Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
【新增】Divider 组件的单元测试 (#119)
Browse files Browse the repository at this point in the history
## 合并请求( Pull Request )
>标题格式:【新增|修复|移除|更新】摘要描述

### 关于本次更新的主要内容
> 请详细描述,描述得越详细,评审通过的几率就越高

### 本次合并的类型是什么?
- [ ] 缺陷修复(对缺陷的修复,包括紧急修复和一般修复) 
- [ ] 功能开发(新功能、特性的开发,之前功能的完善等)
- [ ] 代码风格(包括命名规范、格式、优化代码的写法等)
- [ ] 文档更新(仅对当前版本的文档进行增加、完善和更新)
- [ ] 重构(没有新功能,仅对代码的重构、调整)
- [x] 测试(单元测试、集成测试、性能测试、压力测试等)
- [ ] DevOps (CI/CD、git action 等)
- [ ] 其他,请在下面进行描述:
   > 其他描述写在这里
   
### 关联的 ISSUE 编号
ISSUE 编号:

### 合并请求的必要条件
- [ ]必要的单元测试已经完成
- [ ]完成必要的注释,包括参数、方法、属性、类等
- [ ]代码风格必须符合 C# 的代码规范

### 期望参与合并请求评审的成员
使用 `@名字`来提及你期望参与本次评审人成员


### 其他相关信息
<!--如果有,请写明-->

>
**非常感谢您对本项目的贡献,所有的合并请求最终将由作者通过才可以合并成功。并且要求贡献者需要谦虚地对待每一次评审的内容,并且尊重每一位贡献者的回复。良好的规范才能让项目健康的运转,保持利他精神才是我们一直信奉的价值观。**
  • Loading branch information
teacher-zhou authored Oct 3, 2022
2 parents 0089a02 + 2728c95 commit d7b4794
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
如果您在此过程中遇到任何问题,请通过以下渠道寻求帮助。我们也鼓励有经验的用户帮助新手。
* 作者邮箱:[william-zzh@outlook.com]
* QQ 群:1012762441
* 微信群

<img src="./asset/tdesign-blazor.jpg" width="50%" height="50%"/>

## :triangular_flag_on_post: 行为准则
本项目采用了贡献者契约定义的行为准则,以澄清我们社区的预期行为。请仔细阅读[行为准则](./CodeOfConduct.md)。
Expand Down
39 changes: 39 additions & 0 deletions src/TDesignBlazor.Test/Components/DividerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using ComponentBuilder;

namespace TDesignBlazor.Test.Components;
public class DividerTest : TestBase<Divider>
{
[Fact(DisplayName = "Divider - 默认样式的渲染")]
public void Test_Render_With_Default_Class()
{
GetComponent().Should().HaveTag("div").And.HaveClass("t-divider");
}

[Fact(DisplayName = "Divider - Vertical 参数")]
public void Test_Vertical_Parameter()
{
GetComponent(m => m.Add(p => p.Vertical, true)).Should().HaveClass("t-divider--vertical");
}

[Fact(DisplayName = "Divider - Dashed 参数")]
public void Test_Dashed_Parameter()
{
GetComponent(m => m.Add(p => p.Dashed, true)).Should().HaveClass("t-divider--dashed");
}

[Theory(DisplayName = "Divider - Alighment 参数")]
[InlineData(new object[] { HorizontalAlignment.Left })]
[InlineData(new object[] { HorizontalAlignment.Center })]
[InlineData(new object[] { HorizontalAlignment.Right })]
public void Test_Alignment_Parameter(HorizontalAlignment alignment)
{
GetComponent(m => m.Add(p => p.Alignment, alignment)).Should().HaveClass($"t-divider--with-text-{alignment.GetCssClass()}");
}

[Fact(DisplayName = "Divider - ChildContent 赋值后会嵌套一层")]
public void Test_ChildContent_Has_Inner_Span()
{
GetComponent(m => m.AddChildContent("test")).Should().HaveChildMarkup("<span class=\"t-divider__inner-text\">test</span>")
.And.HaveClass("t-divider--with-text");
}
}
11 changes: 9 additions & 2 deletions src/TDesignBlazor.Test/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bunit;

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;

namespace TDesignBlazor.Test;
Expand All @@ -26,3 +25,11 @@ public TestBase()

protected TService? GetService<TService>() => _provider.GetService<TService>();
}

public class TestBase<TComponent> : TestBase where TComponent : IComponent
{
protected IRenderedComponent<TComponent> GetComponent(Action<ComponentParameterCollectionBuilder<TComponent>> parameterBuilder) => TestContext.RenderComponent(parameterBuilder);

protected IRenderedComponent<TComponent> GetComponent(params ComponentParameter[] parameters) => TestContext.RenderComponent<TComponent>(parameters);

}
2 changes: 1 addition & 1 deletion src/TDesignBlazor/Components/Divider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Divider : BlazorComponentBase, IHasChildContent
/// <summary>
/// 是否为虚线。
/// </summary>
[Parameter][CssClass("t-divider-dashed")] public bool Dashed { get; set; }
[Parameter][CssClass("t-divider--dashed")] public bool Dashed { get; set; }

/// <summary>
/// 文字对齐方式。
Expand Down

0 comments on commit d7b4794

Please sign in to comment.