Skip to content

Commit d54014e

Browse files
authored
test(Upload): add unit test for upload reset (#6667)
* refactor: 更改写法消除警告信息 * feat: 增加 Reset 方法 * doc: 代码格式化 * revert: 撤销新方法 * test: 增加单元测试
1 parent dd729e2 commit d54014e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/BootstrapBlazor/Components/Upload/ButtonUpload.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
88
}
99
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id">
10-
<Button class="@BrowserButtonClassString" IsDisabled="@CheckStatus()" Size="Size" Icon="@BrowserButtonIcon" Text="@BrowserButtonText" Color="@BrowserButtonColor">
10+
<Button class="@BrowserButtonClassString" IsDisabled="@CheckStatus()" Size="Size" Icon="@BrowserButtonIcon"
11+
Text="@BrowserButtonText" Color="@BrowserButtonColor">
1112
@ChildContent
1213
</Button>
1314
@if (ShowUploadFileList)

src/BootstrapBlazor/Components/Upload/UploadBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected async Task OnFileChange(InputFileChangeEventArgs args)
149149
fileCount = MaxFileCount.Value;
150150

151151
// 计算剩余可上传数量
152-
fileCount = fileCount - Files.Count;
152+
fileCount -= Files.Count;
153153
if (fileCount <= 0)
154154
{
155155
// 如果剩余可上传数量小于等于 0 则不允许继续上传

test/UnitTest/Components/UploadButtonTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void ButtonUpload_IsDisabled_Ok()
8686
}
8787

8888
[Fact]
89-
public void InputUpload_IsMultiple()
89+
public async Task InputUpload_IsMultiple()
9090
{
9191
var cut = Context.RenderComponent<ButtonUpload<string>>(pb =>
9292
{
@@ -108,6 +108,13 @@ public void InputUpload_IsMultiple()
108108
var button = cut.Find(".btn-browser");
109109
Assert.True(button.IsDisabled());
110110

111+
// 调用 Reset 方法
112+
await cut.InvokeAsync(() => cut.Instance.Reset());
113+
114+
// 重置后上传按钮应该被启用
115+
button = cut.Find(".btn-browser");
116+
Assert.False(button.IsDisabled());
117+
111118
// 开启多选功能
112119
cut.SetParametersAndRender(pb =>
113120
{

0 commit comments

Comments
 (0)