Skip to content

Commit 4db6e97

Browse files
committed
test: 更新单元测试
1 parent 448ce78 commit 4db6e97

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/BootstrapBlazor/Components/Upload/UploadBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ protected async Task OnFileChange(InputFileChangeEventArgs args)
190190
await OnAllFileUploaded(items);
191191
}
192192

193+
UpdateValue(items);
194+
}
195+
196+
private void UpdateValue(List<UploadFile> items)
197+
{
193198
if (ValueType.IsAssignableTo(typeof(IEnumerable<UploadFile>)))
194199
{
195200
CurrentValue = (TValue)(object)items;
@@ -248,6 +253,8 @@ protected virtual async Task<bool> OnFileDelete(UploadFile item)
248253
UploadFiles.Remove(item);
249254
DefaultFileList?.Remove(item);
250255
_filesCache = null;
256+
257+
UpdateValue(Files);
251258
}
252259
StateHasChanged();
253260
return ret;

test/UnitTest/Components/UploadCardTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public async Task CardUpload_ValidateForm_Ok()
169169
{
170170
pb.Add(a => a.Accept, "Image");
171171
pb.Add(a => a.Value, foo.Files);
172+
pb.Add(a => a.ValueChanged, EventCallback.Factory.Create<List<UploadFile>?>(this, v => foo.Files = v));
172173
pb.Add(a => a.ValueExpression, Utility.GenerateValueExpression(foo, "Files", typeof(List<UploadFile>)));
173174
pb.Add(a => a.AllowExtensions, [".jpg"]);
174175
pb.Add(a => a.ShowDeleteButton, true);
@@ -214,11 +215,13 @@ await input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<
214215
{
215216
pb.Add(a => a.IsDisabled, false);
216217
});
217-
// 清空所有文件
218+
218219
var items = cut.FindAll(".btn-outline-danger");
219220
Assert.Single(items);
220221
await cut.InvokeAsync(() => items[0].Click());
221-
form.Submit();
222+
223+
form = cut.Find("form");
224+
await cut.InvokeAsync(() => form.Submit());
222225
}
223226

224227
[Fact]

0 commit comments

Comments
 (0)