Skip to content

Commit faf2c5b

Browse files
committed
test: 更新单元测试
1 parent 8580d01 commit faf2c5b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/UnitTest/Components/SelectTableTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ public async Task IsClearable_Ok()
5252
var table = cut.FindComponent<SelectTable<Foo>>();
5353
Assert.DoesNotContain("clear-icon", table.Markup);
5454

55+
var isClear = false;
5556
table.SetParametersAndRender(pb =>
5657
{
5758
pb.Add(a => a.IsClearable, true);
5859
pb.Add(a => a.Value, items[0]);
60+
pb.Add(a => a.OnClearAsync, () =>
61+
{
62+
isClear = true;
63+
return Task.CompletedTask;
64+
});
5965
});
6066
Assert.Contains("clear-icon", table.Markup);
6167
var input = table.Find(".form-select");
@@ -65,6 +71,7 @@ public async Task IsClearable_Ok()
6571
await table.InvokeAsync(() => span.Click());
6672
input = table.Find(".form-select");
6773
Assert.Null(input.GetAttribute("value"));
74+
Assert.True(isClear);
6875
}
6976

7077
[Fact]
@@ -96,9 +103,13 @@ public void Color_Ok()
96103
pb.Add(a => a.Color, Color.Danger);
97104
pb.Add(a => a.GetTextCallback, foo => foo.Name);
98105
pb.Add(a => a.OnQueryAsync, options => OnFilterQueryAsync(options, items));
106+
pb.Add(a => a.IsClearable, true);
99107
});
100108
});
101109
cut.Contains("border-danger");
110+
111+
var span = cut.Find(".clear-icon");
112+
Assert.True(span.ClassList.Contains("text-danger"));
102113
}
103114

104115
[Fact]
@@ -302,6 +313,7 @@ public async Task Validate_Ok()
302313
builder.Add(a => a.Model, model);
303314
builder.AddChildContent<SelectTable<Foo>>(pb =>
304315
{
316+
pb.Add(a => a.IsClearable, true);
305317
pb.Add(a => a.Value, model.Foo);
306318
pb.Add(a => a.ValueExpression, Utility.GenerateValueExpression(model, "Foo", typeof(Foo)));
307319
pb.Add(a => a.OnValueChanged, v =>
@@ -333,6 +345,9 @@ await cut.InvokeAsync(() =>
333345
});
334346
Assert.True(valid);
335347

348+
var span = cut.Find(".clear-icon");
349+
Assert.True(span.ClassList.Contains("text-success"));
350+
336351
model.Foo = null;
337352
var table = cut.FindComponent<SelectTable<Foo>>();
338353
table.SetParametersAndRender();
@@ -342,6 +357,9 @@ await cut.InvokeAsync(() =>
342357
form.Submit();
343358
});
344359
Assert.True(invalid);
360+
361+
span = cut.Find(".clear-icon");
362+
Assert.True(span.ClassList.Contains("text-danger"));
345363
}
346364

347365
[Fact]

0 commit comments

Comments
 (0)