!2399 test(#I4SWEE): add Circle unit test

* test: 增加代码覆盖率
* refactor: 更改参数验证逻辑到 OnParameterSet 中
* Revert "refactor: 合并 CircleBase 基类"
* refactor: 合并 CircleBase 基类
* test: 添加 circle 组件单元测试
This commit is contained in:
Argo 2022-02-08 16:09:18 +00:00
parent 3e8d3966f1
commit 69a36adb5a
2 changed files with 83 additions and 2 deletions

View File

@ -94,9 +94,9 @@ public abstract class CircleBase : BootstrapComponentBase
/// <summary>
/// OnInitialized 方法
/// </summary>
protected override void OnInitialized()
protected override void OnParametersSet()
{
base.OnInitialized();
base.OnParametersSet();
// 检查 StrokeWidth 参数
if (Width / 2 < StrokeWidth) StrokeWidth = 2;

View File

@ -0,0 +1,81 @@
// 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/
using BootstrapBlazor.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTest.Components;
public class CircleTest : TestBase
{
[Fact]
public void Value_Ok()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.Value, 100));
Assert.Contains("100%", cut.Markup);
}
[Fact]
public void Width_Ok()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.Width, 100));
Assert.Contains("width: 100px", cut.Markup);
}
[Fact]
public void StrokeWidth_Ok()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.StrokeWidth, 5));
Assert.Contains("stroke-width=\"5\"", cut.Markup);
// 增加代码覆盖率
//Width / 2 < StrokeWidth
cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.Width, 6);
pb.Add(a => a.StrokeWidth, 6);
});
Assert.Equal(2, cut.Instance.StrokeWidth);
}
[Fact]
public void Color_Ok()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.Color, Color.Success));
var element = cut.Find(".circle-success");
Assert.NotNull(element);
}
[Fact]
public void ShowProgress_Ok()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.ShowProgress, false));
var element = cut.Find(".d-none");
Assert.NotNull(element);
}
[Fact]
public void Value_ChildContent()
{
var cut = Context.RenderComponent<Circle>(builder => builder.Add(a => a.ChildContent, s =>
{
s.OpenElement(1, "div");
s.AddContent(2, "I am cricle");
s.CloseElement();
}));
Assert.Contains("I am cricle", cut.Markup);
}
}