mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-01 19:50:31 +08:00
!2668 test(#I534SP): improve code coverage
* test: 增加 Options 单元测试 * test: 修复失败的单元测试 * test: 增加 AutoGenerate 单元测试 * test: 更新异步单元测试 * fix: 修复失败的单元测试
This commit is contained in:
parent
1892432980
commit
6353e6a663
@ -51,7 +51,6 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示标签 Tooltip 多用于标签文字过长导致裁减时使用 默认 false
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool ShowLabelTooltip { get; set; }
|
||||
|
||||
bool? IEditorItem.ShowLabelTooltip
|
||||
|
@ -36,6 +36,7 @@ public abstract class BootstrapComponentBase : ComponentBase, IHandleEvent
|
||||
/// </summary>
|
||||
protected bool IsNotRender { get; set; }
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
private async Task CallStateHasChangedOnAsyncCompletion(Task task)
|
||||
{
|
||||
try
|
||||
|
134
test/UnitTest/Attributes/AutoGenerateClassTest.cs
Normal file
134
test/UnitTest/Attributes/AutoGenerateClassTest.cs
Normal file
@ -0,0 +1,134 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
namespace UnitTest.Attributes;
|
||||
|
||||
public class AutoGenerateClassTest
|
||||
{
|
||||
[Fact]
|
||||
public void AutoGenerateClass_Ok()
|
||||
{
|
||||
var attr = new AutoGenerateClassAttribute()
|
||||
{
|
||||
Editable = true,
|
||||
Readonly = true,
|
||||
Sortable = true,
|
||||
Filterable = true,
|
||||
Searchable = true,
|
||||
TextWrap = true,
|
||||
TextEllipsis = true,
|
||||
ShowTips = true,
|
||||
Align = Alignment.Center
|
||||
};
|
||||
Assert.True(attr.Editable);
|
||||
Assert.True(attr.Readonly);
|
||||
Assert.True(attr.Sortable);
|
||||
Assert.True(attr.Filterable);
|
||||
Assert.True(attr.Searchable);
|
||||
Assert.True(attr.TextWrap);
|
||||
Assert.True(attr.TextEllipsis);
|
||||
Assert.True(attr.ShowTips);
|
||||
Assert.Equal(Alignment.Center, attr.Align);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AutoGenerateColumn_Ok()
|
||||
{
|
||||
var attr = new AutoGenerateColumnAttribute()
|
||||
{
|
||||
Order = 1,
|
||||
Ignore = true,
|
||||
DefaultSort = true,
|
||||
SkipValidate = true,
|
||||
IsReadonlyWhenAdd = true,
|
||||
IsReadonlyWhenEdit = true,
|
||||
ShowLabelTooltip = true,
|
||||
DefaultSortOrder = SortOrder.Asc,
|
||||
Width = 10,
|
||||
Fixed = true,
|
||||
Visible = true,
|
||||
CssClass = "test_class",
|
||||
ShownWithBreakPoint = BreakPoint.Large,
|
||||
FormatString = "yyyy-MM-dd",
|
||||
PlaceHolder = "test_holder",
|
||||
Formatter = null,
|
||||
ComponentType = typeof(Select<string>),
|
||||
Step = 1,
|
||||
Rows = 1,
|
||||
LookupStringComparison = StringComparison.Ordinal,
|
||||
};
|
||||
Assert.Equal(1, attr.Order);
|
||||
Assert.True(attr.Ignore);
|
||||
Assert.True(attr.DefaultSort);
|
||||
Assert.True(attr.SkipValidate);
|
||||
Assert.True(attr.IsReadonlyWhenAdd);
|
||||
Assert.True(attr.IsReadonlyWhenEdit);
|
||||
Assert.True(attr.ShowLabelTooltip);
|
||||
Assert.Equal(SortOrder.Asc, attr.DefaultSortOrder);
|
||||
Assert.Equal(10, attr.Width);
|
||||
Assert.True(attr.Fixed);
|
||||
Assert.True(attr.Visible);
|
||||
Assert.Equal("test_class", attr.CssClass);
|
||||
Assert.Equal(BreakPoint.Large, attr.ShownWithBreakPoint);
|
||||
Assert.Equal("yyyy-MM-dd", attr.FormatString);
|
||||
Assert.Equal("test_holder", attr.PlaceHolder);
|
||||
Assert.Null(attr.Formatter);
|
||||
Assert.Equal(typeof(Select<string>), attr.ComponentType);
|
||||
Assert.Equal(1, attr.Step);
|
||||
Assert.Equal(1, attr.Rows);
|
||||
Assert.Equal(StringComparison.Ordinal, attr.LookupStringComparison);
|
||||
|
||||
var attrInterface = (ITableColumn)attr;
|
||||
attrInterface.ShowLabelTooltip = true;
|
||||
Assert.True(attrInterface.ShowLabelTooltip);
|
||||
attrInterface.ShowLabelTooltip = null;
|
||||
Assert.False(attrInterface.ShowLabelTooltip);
|
||||
|
||||
attrInterface.HeaderTemplate = null;
|
||||
Assert.Null(attrInterface.HeaderTemplate);
|
||||
|
||||
attrInterface.Template = null;
|
||||
Assert.Null(attrInterface.Template);
|
||||
|
||||
attrInterface.SearchTemplate = null;
|
||||
Assert.Null(attrInterface.SearchTemplate);
|
||||
|
||||
attrInterface.FilterTemplate = null;
|
||||
Assert.Null(attrInterface.FilterTemplate);
|
||||
|
||||
attrInterface.Filter = null;
|
||||
Assert.Null(attrInterface.Filter);
|
||||
|
||||
attrInterface.OnCellRender = null;
|
||||
Assert.Null(attrInterface.OnCellRender);
|
||||
|
||||
attrInterface.Width = null;
|
||||
Assert.Equal(0, attr.Width);
|
||||
|
||||
attrInterface.Width = -10;
|
||||
Assert.Equal(0, attr.Width);
|
||||
|
||||
attr.Width = -10;
|
||||
Assert.Null(attrInterface.Width);
|
||||
|
||||
attr.Width = 10;
|
||||
Assert.Equal(10, attrInterface.Width);
|
||||
|
||||
var attrEditor = (IEditorItem)attr;
|
||||
attrEditor.Items = null;
|
||||
Assert.Null(attrEditor.Items);
|
||||
|
||||
attrEditor.EditTemplate = null;
|
||||
Assert.Null(attrEditor.EditTemplate);
|
||||
|
||||
attrEditor.ComponentParameters = null;
|
||||
Assert.Null(attrEditor.ComponentParameters);
|
||||
|
||||
attrEditor.Lookup = null;
|
||||
Assert.Null(attrEditor.Lookup);
|
||||
|
||||
attrEditor.ValidateRules = null;
|
||||
Assert.Null(attrEditor.ValidateRules);
|
||||
}
|
||||
}
|
@ -119,29 +119,29 @@ public class TimerTest : BootstrapBlazorTestBase
|
||||
});
|
||||
});
|
||||
var downs = cut.FindAll(".time-spinner-arrow.fa-angle-down");
|
||||
downs[0].Click();
|
||||
cut.Find(".time-panel-btn.confirm").Click();
|
||||
await cut.InvokeAsync(() => downs[0].Click());
|
||||
await cut.InvokeAsync(() => cut.Find(".time-panel-btn.confirm").Click());
|
||||
await Task.Delay(1000);
|
||||
var buttons = cut.FindAll(".timer-buttons button");
|
||||
// pause
|
||||
Assert.True(buttons[1].ClassList.Contains("btn-warning"));
|
||||
buttons[1].Click();
|
||||
await cut.InvokeAsync(() => buttons[1].Click());
|
||||
await Task.Delay(500);
|
||||
|
||||
// resume
|
||||
buttons = cut.FindAll(".timer-buttons button");
|
||||
Assert.True(buttons[1].ClassList.Contains("btn-success"));
|
||||
buttons[1].Click();
|
||||
await cut.InvokeAsync(() => buttons[1].Click());
|
||||
|
||||
// cancel
|
||||
buttons = cut.FindAll(".timer-buttons button");
|
||||
buttons[0].Click();
|
||||
await cut.InvokeAsync(() => buttons[0].Click());
|
||||
Assert.True(cancelled);
|
||||
|
||||
// 代码覆盖率 Cancel 后再 Star
|
||||
downs = cut.FindAll(".time-spinner-arrow.fa-angle-down");
|
||||
downs[0].Click();
|
||||
cut.Find(".time-panel-btn.confirm").Click();
|
||||
await cut.InvokeAsync(() => downs[0].Click());
|
||||
await cut.InvokeAsync(() => cut.Find(".time-panel-btn.confirm").Click());
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
|
@ -529,7 +529,7 @@ public class UploadTest : BootstrapBlazorTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CardUpload_Ok()
|
||||
public async Task CardUpload_Ok()
|
||||
{
|
||||
var zoom = false;
|
||||
var deleted = false;
|
||||
@ -555,7 +555,7 @@ public class UploadTest : BootstrapBlazorTestBase
|
||||
cut.Contains("bb-viewer-wrapper active");
|
||||
|
||||
// OnZoom
|
||||
cut.InvokeAsync(() => cut.Find(".btn-outline-secondary").Click());
|
||||
await cut.InvokeAsync(() => cut.Find(".btn-outline-secondary").Click());
|
||||
Assert.False(zoom);
|
||||
|
||||
cut.SetParametersAndRender(pb =>
|
||||
@ -566,11 +566,11 @@ public class UploadTest : BootstrapBlazorTestBase
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
});
|
||||
cut.InvokeAsync(() => cut.Find(".btn-outline-secondary").Click());
|
||||
await cut.InvokeAsync(() => cut.Find(".btn-outline-secondary").Click());
|
||||
Assert.True(zoom);
|
||||
|
||||
// OnDelete
|
||||
cut.InvokeAsync(() => cut.Find(".btn-outline-danger").Click());
|
||||
await cut.InvokeAsync(() => cut.Find(".btn-outline-danger").Click());
|
||||
Assert.True(deleted);
|
||||
|
||||
// ShowProgress
|
||||
@ -583,11 +583,11 @@ public class UploadTest : BootstrapBlazorTestBase
|
||||
});
|
||||
});
|
||||
var input = cut.FindComponent<InputFile>();
|
||||
cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
|
||||
await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
|
||||
{
|
||||
new MockBrowserFile("test.txt", "Image-Png")
|
||||
})));
|
||||
cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
|
||||
await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
|
||||
{
|
||||
new MockBrowserFile("test.png")
|
||||
})));
|
||||
|
@ -242,14 +242,14 @@ public class ValidateTest : BootstrapBlazorTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetValue_Ok()
|
||||
public async Task SetValue_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<BootstrapInput<string>>(builder =>
|
||||
{
|
||||
builder.Add(a => a.Value, "test");
|
||||
});
|
||||
Assert.Equal("test", cut.Instance.Value);
|
||||
cut.InvokeAsync(() => cut.Instance.SetValue("test2"));
|
||||
await cut.InvokeAsync(() => cut.Instance.SetValue("test2"));
|
||||
Assert.Equal("test2", cut.Instance.Value);
|
||||
}
|
||||
|
||||
|
22
test/UnitTest/Options/BootstrapBlazorOptionsTest.cs
Normal file
22
test/UnitTest/Options/BootstrapBlazorOptionsTest.cs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
namespace UnitTest.Options;
|
||||
|
||||
public class BootstrapBlazorOptionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void Options_Ok()
|
||||
{
|
||||
var options = new BootstrapBlazorOptions();
|
||||
Assert.NotNull(options.GetSupportedCultures());
|
||||
}
|
||||
[Fact]
|
||||
public void Options_Single_Ok()
|
||||
{
|
||||
var options = new BootstrapBlazorOptions();
|
||||
options.SupportedCultures = new List<string> { "zh-CN" };
|
||||
Assert.Single(options.GetSupportedCultures());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user