Skip to content

Commit

Permalink
test: 更新单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgoZhang committed Nov 7, 2024
1 parent aec7b42 commit 1e4b497
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 78 deletions.
18 changes: 9 additions & 9 deletions test/UnitTest/Components/CheckboxListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void CheckboxItemClass_Ok()
}

[Fact]
public void StringValue_Ok()
public async Task StringValue_Ok()
{
var cut = Context.RenderComponent<CheckboxList<string>>(builder =>
{
Expand Down Expand Up @@ -236,13 +236,13 @@ public void StringValue_Ok()
});
});
// 字符串值选中事件
var item = cut.Find(".form-check-input");
item.Click();
var item = cut.FindComponent<Checkbox<bool>>();
await cut.InvokeAsync(item.Instance.TriggerClick);
Assert.True(selected);
}

[Fact]
public void OnSelectedChanged_Ok()
public async Task OnSelectedChanged_Ok()
{
var selected = false;
var foo = Foo.Generate(Localizer);
Expand All @@ -257,8 +257,8 @@ public void OnSelectedChanged_Ok()
});
});

var item = cut.Find(".form-check-input");
item.Click();
var item = cut.FindComponent<Checkbox<bool>>();
await cut.InvokeAsync(item.Instance.TriggerClick);
Assert.True(selected);
}

Expand All @@ -274,7 +274,7 @@ public void EnumValue_Ok()
}

[Fact]
public void IntValue_Ok()
public async Task IntValue_Ok()
{
var ret = new List<int>();
var selectedIntValues = new List<int> { 1, 2 };
Expand All @@ -292,8 +292,8 @@ public void IntValue_Ok()
return Task.CompletedTask;
});
});
var item = cut.Find(".form-check-input");
item.Click();
var item = cut.FindComponent<Checkbox<bool>>();
await cut.InvokeAsync(item.Instance.TriggerClick);

// 选中 2
Assert.Equal(2, ret.First());
Expand Down
5 changes: 3 additions & 2 deletions test/UnitTest/Components/ConsoleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void LightTitle_OK()
}

[Fact]
public void ClickAutoScroll_OK()
public async Task ClickAutoScroll_OK()
{
var cut = Context.RenderComponent<Console>(builder =>
{
Expand All @@ -206,7 +206,8 @@ public void ClickAutoScroll_OK()
builder.Add(a => a.ShowAutoScroll, true);
});

cut.Find(".card-footer input").Click();
var item = cut.FindComponent<Checkbox<bool>>();
await cut.InvokeAsync(item.Instance.TriggerClick);
var res = cut.Instance.IsAutoScroll;
Assert.False(res);
}
Expand Down
10 changes: 5 additions & 5 deletions test/UnitTest/Components/TableDialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public async Task EditAsync_Ok()

var table = cut.FindComponent<Table<Foo>>();
// 选一个
var input = cut.Find("tbody tr input");
await cut.InvokeAsync(() => input.Click());
var checkbox = cut.FindComponents<Checkbox<Foo>>()[1];
await cut.InvokeAsync(checkbox.Instance.TriggerClick);
await cut.InvokeAsync(() => table.Instance.EditAsync());

cut.Contains("test-save");
Expand Down Expand Up @@ -128,7 +128,7 @@ public async Task EditAsync_Ok()
await cut.InvokeAsync(() => table.Instance.AddAsync());

// 编辑弹窗逻辑
input = cut.Find(".modal-body form input.form-control");
var input = cut.Find(".modal-body form input.form-control");
await cut.InvokeAsync(() => input.Change("Test_Name"));

form = cut.Find(".modal-body form");
Expand Down Expand Up @@ -362,8 +362,8 @@ public async Task Required_Ok()
var modal = cut.FindComponent<Modal>();

// 选一个
var input = cut.Find("tbody tr input");
await cut.InvokeAsync(() => input.Click());
var item = cut.FindComponent<Checkbox<Foo>>();
await cut.InvokeAsync(item.Instance.TriggerClick);
await cut.InvokeAsync(() => table.Instance.AddAsync());

var form = cut.Find(".modal-body form");
Expand Down
10 changes: 5 additions & 5 deletions test/UnitTest/Components/TableDrawerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public async Task EditAsync_Ok()

var table = cut.FindComponent<Table<Foo>>();
// 选一个
var input = cut.Find("tbody tr input");
await cut.InvokeAsync(() => input.Click());
var checkbox = cut.FindComponents<Checkbox<Foo>>()[1];
await cut.InvokeAsync(checkbox.Instance.TriggerClick);
await cut.InvokeAsync(() => table.Instance.EditAsync());

// 编辑弹窗逻辑
Expand Down Expand Up @@ -102,8 +102,8 @@ public async Task EditAsync_Ok()
{
pb.Add(a => a.OnSaveAsync, (foo, itemType) => Task.FromResult(false));
});
input = cut.Find("tbody tr input");
await cut.InvokeAsync(() => input.Click());
checkbox = cut.FindComponents<Checkbox<Foo>>()[1];
await cut.InvokeAsync(checkbox.Instance.TriggerClick);
await cut.InvokeAsync(() => table.Instance.EditAsync());
form = cut.Find("form");
await cut.InvokeAsync(() => form.Submit());
Expand All @@ -119,7 +119,7 @@ public async Task EditAsync_Ok()
await cut.InvokeAsync(() => table.Instance.AddAsync());

// 编辑弹窗逻辑
input = cut.Find("form input.form-control");
var input = cut.Find("form input.form-control");
await cut.InvokeAsync(() => input.Change("Test_Name"));

form = cut.Find("form");
Expand Down
Loading

0 comments on commit 1e4b497

Please sign in to comment.