Skip to content

Commit bd806a1

Browse files
committed
test: 更新单元测试
1 parent 1703c2f commit bd806a1

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

src/BootstrapBlazor/Components/Upload/AvatarUpload.razor

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@
1616
{
1717
<div @key="item" class="@GetItemClassString(item)" id="@item.ValidateId" style="@ItemStyleString">
1818
<Avatar Url="@item.PrevUrl" />
19-
@if (!IsDisabled)
20-
{
21-
<div class="upload-item-actions">
22-
<span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))">
23-
<i class="@DeleteIcon"></i>
19+
<div class="upload-item-actions">
20+
<span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))">
21+
<i class="@DeleteIcon"></i>
22+
</span>
23+
@if (GetShowProgress(item))
24+
{
25+
<span class="upload-item-spin">
26+
<i class="@LoadingIcon"></i>
2427
</span>
25-
@if (GetShowProgress(item))
26-
{
27-
<span class="upload-item-spin">
28-
<i class="@LoadingIcon"></i>
29-
</span>
30-
}
31-
</div>
32-
}
28+
}
29+
</div>
3330
@if (!IsCircle)
3431
{
3532
<span class="upload-item-label">

test/UnitTest/Components/UploadAvatarTest.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ await input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<
163163
}
164164

165165
[Fact]
166-
public void AvatarUpload_ShowProgress_Ok()
166+
public async Task DropUpload_ShowProgress_Ok()
167167
{
168168
var cut = Context.RenderComponent<AvatarUpload<string>>(pb =>
169169
{
@@ -172,10 +172,16 @@ public void AvatarUpload_ShowProgress_Ok()
172172
{
173173
await Task.Delay(100);
174174
await file.SaveToFileAsync("1.txt");
175-
SetUploaded(file, false);
176175
});
177176
});
178177
var input = cut.FindComponent<InputFile>();
178+
await cut.InvokeAsync(() =>
179+
{
180+
_ = input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
181+
{
182+
new()
183+
}));
184+
});
179185
}
180186

181187
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text") : IBrowserFile

test/UnitTest/Components/UploadButtonTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ public void ButtonUpload_OnGetFileFormat_Ok()
386386
new() { FileName = "1.test" },
387387
new() { FileName = "1" }
388388
]);
389-
390389
});
391390
cut.Contains("fa-file-excel");
392391
cut.Contains("fa-file-word");

test/UnitTest/Components/UploadDropTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ await cut.InvokeAsync(async () =>
136136
});
137137
}
138138

139+
140+
[Fact]
141+
public void OnGetFileFormat_Ok()
142+
{
143+
var cut = Context.RenderComponent<DropUpload>(pb =>
144+
{
145+
pb.Add(a => a.LoadingIcon, "fa-loading");
146+
pb.Add(a => a.DeleteIcon, "fa-delte");
147+
pb.Add(a => a.CancelIcon, "fa-cancel");
148+
pb.Add(a => a.DownloadIcon, "fa-download");
149+
pb.Add(a => a.InvalidStatusIcon, "fa-invalid");
150+
pb.Add(a => a.ValidStatusIcon, "fa-valid");
151+
pb.Add(a => a.ShowUploadFileList, true);
152+
pb.Add(a => a.OnGetFileFormat, extensions =>
153+
{
154+
return "fa-format-test";
155+
});
156+
pb.Add(a => a.DefaultFileList,
157+
[
158+
new() { FileName = "1.csv" }
159+
]);
160+
});
161+
cut.Contains("fa-format-test");
162+
}
163+
139164
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text") : IBrowserFile
140165
{
141166
public string Name { get; } = name;

0 commit comments

Comments
 (0)