mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 13:39:39 +08:00
!3524 feat(#I60TG7): update unit test improve code coverage
* chore: bump version 7.0.0-beta04 * Merge branch 'main' into feat/sidebar-template * test: 更新 TableFilter 单元测试 * test: 增加 DialogClose/SaveButton 单元测试 * test: 增加 Layout 单元测试 * test: 增加 Popover 单元测试 * test: 增加 JSModule 单元测试 * test: 增加 TimePickerCell 单元测试 * test: 增加 HeaderToolbarTemplate 单元测试 * test: 增加 Format 单元测试 * fix: 修复丢失 DateFormat 问题 * test: 更新单元测试 * test: 增加 SidebarTemplate 单元测试 * feat: DateTimePicker 增加 SidebarTemplate 参数 * feat: DatePickerBody 增加 SidebarTemplate
This commit is contained in:
parent
d2bc2bb58f
commit
51f83e7f95
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>7.0.1-beta03</Version>
|
||||
<Version>7.0.1-beta04</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -10,7 +10,7 @@
|
||||
<input readonly class="@InputClassName" value="@CurrentValueAsString" placeholder="@PlaceholderString" disabled="@Disabled" data-bs-toggle="@Constants.DropdownToggleString" data-bs-placement="@PlacementString" data-bs-custom-class="@CustomClassString" />
|
||||
<i class="@DateTimePickerIconClassString"></i>
|
||||
<DatePickerBody @bind-Value="ComponentValue" AllowNull="AllowNull" ShowSidebar="ShowSidebar" SidebarTemplate="SidebarTemplate!"
|
||||
DateFormat="DateFormat" ShowFooter="true"
|
||||
DateFormat="@DateFormat" ShowFooter="true"
|
||||
OnConfirm="OnConfirm" OnClear="OnClear" MinValue="MinValue" MaxValue="MaxValue"
|
||||
AutoClose="AutoClose" ViewMode="ViewMode">
|
||||
</DatePickerBody>
|
||||
|
@ -34,7 +34,7 @@ public abstract class FilterBase : ComponentBase, IFilterAction
|
||||
/// <summary>
|
||||
/// 获得 当前过滤条件是否激活
|
||||
/// </summary>
|
||||
protected bool HasFilter => TableFilter!.HasFilter; // IsHeaderRow 为真时使用 TableFilter 不为空
|
||||
protected bool HasFilter => TableFilter?.HasFilter ?? false; // IsHeaderRow 为真时使用 TableFilter 不为空
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 条件数量
|
||||
|
@ -132,7 +132,6 @@ public partial class TableFilter : IFilter
|
||||
{
|
||||
base.OnParametersSet();
|
||||
|
||||
Title ??= Localizer[nameof(Title)];
|
||||
FilterButtonText ??= Localizer[nameof(FilterButtonText)];
|
||||
ClearButtonText ??= Localizer[nameof(ClearButtonText)];
|
||||
}
|
||||
|
@ -239,7 +239,6 @@
|
||||
"SaveButtonText": "Save"
|
||||
},
|
||||
"BootstrapBlazor.Components.TableFilter": {
|
||||
"Title": "Filter",
|
||||
"ClearButtonText": "Clear",
|
||||
"FilterButtonText": "Filter",
|
||||
"BoolFilter.AllText": "All",
|
||||
|
@ -239,7 +239,6 @@
|
||||
"SaveButtonText": "保存"
|
||||
},
|
||||
"BootstrapBlazor.Components.TableFilter": {
|
||||
"Title": "过滤",
|
||||
"ClearButtonText": "重置",
|
||||
"FilterButtonText": "确认",
|
||||
"BoolFilter.AllText": "全部",
|
||||
|
@ -339,4 +339,28 @@ public class ButtonTest : BootstrapBlazorTestBase
|
||||
pb.Add(a => a.IsAutoFocus, true);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DialogCloseButton_Ok()
|
||||
{
|
||||
var clicked = false;
|
||||
var cut = Context.RenderComponent<DialogCloseButton>(pb =>
|
||||
{
|
||||
pb.AddCascadingValue<Func<Task>>(() =>
|
||||
{
|
||||
clicked = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
cut.Contains("button type=\"button\"");
|
||||
cut.InvokeAsync(async () => await cut.Instance.OnClickWithoutRender());
|
||||
Assert.True(clicked);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DialogSaveButton_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<DialogSaveButton>();
|
||||
cut.Contains("button type=\"submit\"");
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +148,18 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
||||
cut.Contains($"value=\"{DateTime.Today:yyyy/MM/dd}\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Format_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<DateTimePicker<DateTime>>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Format, "yyyy-MM-dd HH:mm:ss");
|
||||
});
|
||||
|
||||
var body = cut.FindComponent<DatePickerBody>();
|
||||
Assert.Equal("yyyy-MM-dd", body.Instance.DateFormat);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DatePickerViewModel_Ok()
|
||||
{
|
||||
@ -429,6 +441,18 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
||||
cut1.InvokeAsync(() => buttons[1].Click());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HeightCallback_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<TimePickerBody>();
|
||||
var cell = cut.FindComponent<TimePickerCell>();
|
||||
cut.InvokeAsync(() => cell.Instance.OnHeightCallback(16));
|
||||
cut.SetParametersAndRender(pb =>
|
||||
{
|
||||
pb.Add(a => a.Value, TimeSpan.FromSeconds(1));
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_Ok()
|
||||
{
|
||||
@ -716,8 +740,9 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
||||
pb.Add(a => a.AutoClose, false);
|
||||
});
|
||||
cut.InvokeAsync(() => cell.Click());
|
||||
Assert.True(confirm);
|
||||
Assert.False(confirm);
|
||||
|
||||
// 不显示 Footer AutoClose 参数不起作用自动关闭
|
||||
confirm = false;
|
||||
cut.SetParametersAndRender(pb =>
|
||||
{
|
||||
@ -725,7 +750,7 @@ public class DateTimePickerTest : BootstrapBlazorTestBase
|
||||
pb.Add(a => a.AutoClose, false);
|
||||
});
|
||||
cut.InvokeAsync(() => cell.Click());
|
||||
Assert.False(confirm);
|
||||
Assert.True(confirm);
|
||||
}
|
||||
|
||||
[JSModuleNotInherited]
|
||||
|
@ -48,6 +48,14 @@ public class DialogTest : DialogTestBase
|
||||
cut.InvokeAsync(() => modal.Instance.Close());
|
||||
Assert.True(closed);
|
||||
|
||||
// 测试 HeaderToolbarTemplate
|
||||
cut.InvokeAsync(() => dialog.Show(new DialogOption()
|
||||
{
|
||||
HeaderToolbarTemplate = builder => builder.AddContent(0, "Test-HeaderToolbarTemplate"),
|
||||
}));
|
||||
Assert.Contains("Test-HeaderToolbarTemplate", cut.Markup);
|
||||
cut.InvokeAsync(() => modal.Instance.Close());
|
||||
|
||||
// 测试 Component 赋值逻辑
|
||||
cut.InvokeAsync(() => dialog.Show(new DialogOption()
|
||||
{
|
||||
|
@ -267,3 +267,21 @@ public class LayoutTest : BootstrapBlazorTestBase
|
||||
|
||||
private static RenderFragment CreateSide(string? content = "Side") => builder => builder.AddContent(0, content);
|
||||
}
|
||||
|
||||
public class LayoutAuthorizationTest : AuthorizateViewTestBase
|
||||
{
|
||||
[Fact]
|
||||
public void Authorized_Ok()
|
||||
{
|
||||
AuthorizationContext.SetAuthorized("Admin");
|
||||
|
||||
var navMan = Context.Services.GetRequiredService<FakeNavigationManager>();
|
||||
navMan.NavigateTo("Dog");
|
||||
|
||||
var cut = Context.RenderComponent<Layout>(pb =>
|
||||
{
|
||||
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
|
||||
});
|
||||
cut.Contains("<section class=\"layout\"><header class=\"layout-header\"></header><main class=\"layout-main\"></main></section>");
|
||||
}
|
||||
}
|
||||
|
32
test/UnitTest/Components/PopoverTest.cs
Normal file
32
test/UnitTest/Components/PopoverTest.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.Components;
|
||||
|
||||
public class PopoverTest : BootstrapBlazorTestBase
|
||||
{
|
||||
[Fact]
|
||||
public void Content_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Popover>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Title, "test_popover");
|
||||
pb.Add(a => a.Content, "test_content");
|
||||
});
|
||||
Assert.Contains("data-bs-original-title=\"test_popover\"", cut.Markup);
|
||||
Assert.Contains("data-bs-toggle=\"popover\"", cut.Markup);
|
||||
Assert.Contains("data-bs-placement=\"top\" data-bs-custom-class=\"shadow\" data-bs-trigger=\"focus hover\"", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShowShadow_OK()
|
||||
{
|
||||
var cut = Context.RenderComponent<Popover>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Content, "test_content");
|
||||
pb.Add(a => a.ShowShadow, false);
|
||||
});
|
||||
Assert.DoesNotContain("data-bs-custom-class=\"shadow\"", cut.Markup);
|
||||
}
|
||||
}
|
@ -41,11 +41,10 @@ public class TableFilterTest : BootstrapBlazorTestBase
|
||||
|
||||
// Reset/Confirm buttons
|
||||
// ClickReset
|
||||
var buttons = filterInstance.FindAll(".is-close");
|
||||
var buttons = filterInstance.FindAll(".filter-dismiss");
|
||||
cut.InvokeAsync(() => buttons[0].Click());
|
||||
|
||||
// ClickConfirm
|
||||
buttons = filterInstance.FindAll(".is-close");
|
||||
cut.InvokeAsync(() => buttons[1].Click());
|
||||
|
||||
// OnFilterAsync
|
||||
|
@ -14,7 +14,7 @@ internal static class IServiceCollectionExtensions
|
||||
builder.AddJsonFile("appsettings.json");
|
||||
if (cultureName != null)
|
||||
{
|
||||
builder.AddInMemoryCollection(new Dictionary<string, string>()
|
||||
builder.AddInMemoryCollection(new Dictionary<string, string?>()
|
||||
{
|
||||
["BootstrapBlazorOptions:DefaultCultureInfo"] = cultureName
|
||||
});
|
||||
|
@ -26,9 +26,11 @@ public class JSModuleTest
|
||||
var module = new JSModule(js);
|
||||
await module.InvokeVoidAsync("Test.init", "bb_id");
|
||||
await module.InvokeVoidAsync("Test.init", TimeSpan.Zero, "bb_id");
|
||||
await module.InvokeVoidAsync("Test.init", Timeout.InfiniteTimeSpan, "bb_id");
|
||||
await module.InvokeVoidAsync("Test.init", CancellationToken.None, "bb_id");
|
||||
await module.InvokeAsync<object>("Test.init", "bb_id");
|
||||
await module.InvokeAsync<object>("Test.init", TimeSpan.Zero, "bb_id");
|
||||
await module.InvokeAsync<object>("Test.init", Timeout.InfiniteTimeSpan, "bb_id");
|
||||
await module.InvokeAsync<object>("Test.init", CancellationToken.None, "bb_id");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user