Skip to content

Commit 22c413e

Browse files
committed
test: 更新单元测试
1 parent 128cfcd commit 22c413e

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

src/BootstrapBlazor/Components/Upload/CardUpload.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@
7575
@RenderAdd
7676
}
7777
</div>
78-
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
79-
8078
@if (ShowPreviewList)
8179
{
8280
<ImagePreviewer Id="@PreviewerId" PreviewList="PreviewList" />
8381
}
82+
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
8483
</div>
8584

8685
@code {

src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,16 @@ public partial class CardUpload<TValue>
106106
/// 获得/设置 是否显示删除按钮 默认 true 显示
107107
/// </summary>
108108
[Parameter]
109+
[Obsolete("已弃用,请使用 ShowDeleteButton 参数。Deprecated, please use the ShowDeleteButton parameter")]
110+
[ExcludeFromCodeCoverage]
109111
public bool ShowDeletedButton { get; set; } = true;
110112

113+
/// <summary>
114+
/// 获得/设置 是否显示删除按钮 默认 true 显示
115+
/// </summary>
116+
[Parameter]
117+
public bool ShowDeleteButton { get; set; } = true;
118+
111119
/// <summary>
112120
/// 获得/设置 继续上传按钮是否在列表前 默认 false
113121
/// </summary>

test/UnitTest/Components/UploadCardTest.cs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using Microsoft.AspNetCore.Components.Forms;
7-
using System.ComponentModel.DataAnnotations;
87

98
namespace UnitTest.Components;
109

@@ -17,6 +16,8 @@ public async Task CardUpload_Ok()
1716
var deleted = false;
1817
var cut = Context.RenderComponent<CardUpload<string>>(pb =>
1918
{
19+
pb.Add(a => a.ShowZoomButton, true);
20+
pb.Add(a => a.ShowDeleteButton, true);
2021
pb.Add(a => a.OnDelete, file =>
2122
{
2223
deleted = true;
@@ -35,6 +36,8 @@ public async Task CardUpload_Ok()
3536
]);
3637
});
3738
cut.Contains("bb-previewer collapse active");
39+
cut.Contains("aria-label=\"zoom\"");
40+
cut.Contains("aria-label=\"delete\"");
3841

3942
cut.SetParametersAndRender(pb =>
4043
{
@@ -119,7 +122,11 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
119122
{
120123
pb.Add(a => a.IsUploadButtonAtFirst, true);
121124
pb.Add(a => a.IsMultiple, true);
125+
pb.Add(a => a.ShowZoomButton, false);
126+
pb.Add(a => a.ShowDeleteButton, false);
122127
});
128+
cut.DoesNotContain("aria-label=\"zoom\"");
129+
cut.DoesNotContain("aria-label=\"delete\"");
123130
}
124131

125132
[Fact]
@@ -170,32 +177,6 @@ await cut.InvokeAsync(() =>
170177
Assert.True(cancel);
171178
}
172179

173-
//[Fact]
174-
//public async Task CardUpload_Max_Ok()
175-
//{
176-
// var cut = Context.RenderComponent<CardUpload<string>>(pb =>
177-
// {
178-
// pb.Add(a => a.ShowProgress, true);
179-
// pb.Add(a => a.Max, 1);
180-
// });
181-
// var input = cut.FindComponent<InputFile>();
182-
// await cut.InvokeAsync(async () =>
183-
// {
184-
// await input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
185-
// {
186-
// new()
187-
// }));
188-
// });
189-
//}
190-
191-
private class Person
192-
{
193-
[Required]
194-
[FileValidation(Extensions = [".png", ".jpg", ".jpeg"])]
195-
196-
public IBrowserFile? Picture { get; set; }
197-
}
198-
199180
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text") : IBrowserFile
200181
{
201182
public string Name { get; } = name;

0 commit comments

Comments
 (0)