Skip to content

Commit 9bc11e0

Browse files
committed
test: 增加删除按钮单元测试
1 parent 80e65ea commit 9bc11e0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/UnitTest/Components/UploadCardTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,26 @@ await cut.InvokeAsync(() =>
200200
Assert.True(cancel);
201201
}
202202

203-
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text") : IBrowserFile
203+
[Fact]
204+
public async Task ShowDeleteButton_Ok()
205+
{
206+
var cut = Context.RenderComponent<CardUpload<string>>(pb =>
207+
{
208+
pb.Add(a => a.ShowDeleteButton, true);
209+
pb.Add(a => a.IsDisabled, true);
210+
});
211+
212+
var input = cut.FindComponent<InputFile>();
213+
await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
214+
{
215+
new("test3.png", delay: TimeSpan.FromMilliseconds(300)),
216+
})));
217+
218+
var btn = cut.Find(".btn-outline-danger");
219+
btn.InnerHtml.Contains("disabled=\"disabled\"");
220+
}
221+
222+
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text", TimeSpan? delay = null) : IBrowserFile
204223
{
205224
public string Name { get; } = name;
206225

@@ -212,6 +231,10 @@ private class MockBrowserFile(string name = "UploadTestFile", string contentType
212231

213232
public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default)
214233
{
234+
if (delay != null)
235+
{
236+
Thread.Sleep(delay.Value.Milliseconds);
237+
}
215238
return new MemoryStream([0x01, 0x02]);
216239
}
217240
}

0 commit comments

Comments
 (0)