mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 21:50:05 +08:00
!2385 test(#I4SLOT): add unit test for Card
* test: 增加 Alignment 单元测试 * test: 增加 ChildContent 单元测试 * test: 增加 Vertical 单元测试 * test: 增加 TextIcon 单元测试 * test: 增加单元测试文件 * chore: 移除 DividerBase 基类 * test: 增加收缩单元测试 * test: 增加 HeaderText 单元测试 * test: 增加 IsShadow 单元测试 * refactor: 移除 ServiceProviderExtensions
This commit is contained in:
parent
c06413f1d4
commit
c0e4c410aa
@ -1,5 +1,5 @@
|
||||
@namespace BootstrapBlazor.Components
|
||||
@inherits DividerBase
|
||||
@inherits BootstrapComponentBase
|
||||
|
||||
<div @attributes="@AdditionalAttributes" class="@ClassString">
|
||||
<div class="divider-wrap">
|
||||
|
@ -7,9 +7,9 @@ using Microsoft.AspNetCore.Components;
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Divider 组件基类
|
||||
/// Divider 组件
|
||||
/// </summary>
|
||||
public abstract class DividerBase : ComponentBase
|
||||
public partial class Divider
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得 class 样式集合
|
||||
@ -29,13 +29,6 @@ public abstract class DividerBase : ComponentBase
|
||||
.AddClass("is-right", Alignment.Right == Alignment)
|
||||
.Build();
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 用户自定义属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Parameter(CaptureUnmatchedValues = true)]
|
||||
public IDictionary<string, object>? AdditionalAttributes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 是否为垂直显示 默认为 false
|
||||
/// </summary>
|
@ -1,21 +0,0 @@
|
||||
// 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 BootstrapBlazor.Components;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ServiceProviderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="provider"></param>
|
||||
[Obsolete("可删除此行代码")]
|
||||
public static void RegisterProvider(this IServiceProvider provider)
|
||||
{
|
||||
//TODO: 请移除此代码
|
||||
}
|
||||
}
|
@ -43,6 +43,31 @@ public class CardTest : TestBase
|
||||
Assert.Contains("text-center", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsShadow_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Card>(builder => builder.Add(a => a.IsShadow, true));
|
||||
Assert.Contains("card-shadow", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HeaderText_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Card>(builder => builder.Add(a => a.HeaderText, "Header"));
|
||||
Assert.Contains("Header", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsCollapsible_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Card>(builder =>
|
||||
{
|
||||
builder.Add(a => a.IsCollapsible, true);
|
||||
builder.Add(a => a.HeaderText, "Header");
|
||||
});
|
||||
Assert.Contains("card-collapse", cut.Markup);
|
||||
}
|
||||
|
||||
|
||||
private static RenderFragment CreateComponent() => builder =>
|
||||
{
|
||||
|
64
test/UnitTest/Components/DividerTest.cs
Normal file
64
test/UnitTest/Components/DividerTest.cs
Normal file
@ -0,0 +1,64 @@
|
||||
// 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 DividerTest : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void TextIcon_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Divider>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Text, "Test");
|
||||
pb.Add(a => a.Icon, "fa fa-fa");
|
||||
});
|
||||
Assert.Contains("Test", cut.Markup);
|
||||
Assert.Contains("fa fa-fa", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsVertical_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Divider>(pb =>
|
||||
{
|
||||
pb.Add(a => a.IsVertical, true);
|
||||
pb.Add(a => a.Text, "Test");
|
||||
});
|
||||
Assert.Contains("divider-vertical", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChildContent_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Divider>(pb =>
|
||||
{
|
||||
pb.Add(a => a.ChildContent, new RenderFragment(builder => builder.AddContent(0, "Test")));
|
||||
});
|
||||
Assert.Contains("Test", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Alignment_Ok()
|
||||
{
|
||||
var cut = Context.RenderComponent<Divider>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Alignment, Alignment.Left);
|
||||
pb.Add(a => a.Text, "Test");
|
||||
});
|
||||
Assert.Contains("is-left", cut.Markup);
|
||||
|
||||
cut.SetParametersAndRender(pb =>
|
||||
{
|
||||
pb.Add(a => a.Alignment, Alignment.Center);
|
||||
});
|
||||
Assert.Contains("is-center", cut.Markup);
|
||||
|
||||
cut.SetParametersAndRender(pb =>
|
||||
{
|
||||
pb.Add(a => a.Alignment, Alignment.Right);
|
||||
});
|
||||
Assert.Contains("is-right", cut.Markup);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user