1- namespace TDesign . Test . Components . Basic ;
1+ using ComponentBuilder . FluentRenderTree ;
22
3- public class ButtonTest : TestBase
3+ namespace TDesign . Test . Components . Basic ;
4+ public class ButtonTest : TestBase < TButton >
45{
56 [ Fact ( DisplayName = "按钮 - 渲染 button 元素标记" ) ]
67 public void Test_Render_Button_Tag ( )
78 {
8- TestContext . RenderComponent < TButton > ( ) . Should ( ) . HaveTag ( "button" ) ;
9+ RenderComponent ( ) . Should ( ) . HaveTag ( "button" ) ;
910 }
1011
1112 [ Fact ( DisplayName = "按钮 - Theme 参数 " ) ]
1213 public void Test_Theme_Parameter ( )
1314 {
14- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Theme , Theme . Primary ) ) . Should ( ) . HaveClass ( "t-button--theme-primary" ) ;
15+ RenderComponent ( m => m . Add ( p => p . Theme , Theme . Primary ) ) . Should ( ) . HaveClass ( "t-button--theme-primary" ) ;
1516
16- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Theme , Theme . Success ) ) . Should ( ) . HaveClass ( "t-button--theme-success" ) ;
17+ RenderComponent ( m => m . Add ( p => p . Theme , Theme . Success ) ) . Should ( ) . HaveClass ( "t-button--theme-success" ) ;
1718
18- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Theme , Theme . Danger ) ) . Should ( ) . HaveClass ( "t-button--theme-danger" ) ;
19+ RenderComponent ( m => m . Add ( p => p . Theme , Theme . Danger ) ) . Should ( ) . HaveClass ( "t-button--theme-danger" ) ;
1920
20- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Theme , Theme . Warning ) ) . Should ( ) . HaveClass ( "t-button--theme-warning" ) ;
21+ RenderComponent ( m => m . Add ( p => p . Theme , Theme . Warning ) ) . Should ( ) . HaveClass ( "t-button--theme-warning" ) ;
2122 }
2223
2324 [ Fact ( DisplayName = "按钮 - HtmlType 参数渲染 HTML 的 type 属性" ) ]
2425 public void Test_HtmlType_Parameter ( )
2526 {
26- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Button ) ) . Should ( ) . HaveAttribute ( "type" , "button" ) ;
27+ RenderComponent ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Button ) ) . Should ( ) . HaveAttribute ( "type" , "button" ) ;
2728
28- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Submit ) ) . Should ( ) . HaveAttribute ( "type" , "submit" ) ;
29+ RenderComponent ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Submit ) ) . Should ( ) . HaveAttribute ( "type" , "submit" ) ;
2930
30- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Reset ) ) . Should ( ) . HaveAttribute ( "type" , "reset" ) ;
31+ RenderComponent ( m => m . Add ( p => p . HtmlType , ButtonHtmlType . Reset ) ) . Should ( ) . HaveAttribute ( "type" , "reset" ) ;
3132 }
3233
3334 [ Fact ( DisplayName = "按钮 - Varient 参数" ) ]
3435 public void Test_Type_Parameter ( )
3536 {
36- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Varient , ButtonVarient . Dashed ) ) . Should ( ) . HaveClass ( "t-button--variant-dashed" ) ;
37+ RenderComponent ( m => m . Add ( p => p . Varient , ButtonVarient . Dashed ) ) . Should ( ) . HaveClass ( "t-button--variant-dashed" ) ;
3738
38- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Varient , ButtonVarient . Base ) ) . Should ( ) . HaveClass ( "t-button--variant-base" ) ;
39+ RenderComponent ( m => m . Add ( p => p . Varient , ButtonVarient . Base ) ) . Should ( ) . HaveClass ( "t-button--variant-base" ) ;
3940
40- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Varient , ButtonVarient . Outline ) ) . Should ( ) . HaveClass ( "t-button--variant-outline" ) ;
41+ RenderComponent ( m => m . Add ( p => p . Varient , ButtonVarient . Outline ) ) . Should ( ) . HaveClass ( "t-button--variant-outline" ) ;
4142
42- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Varient , ButtonVarient . Text ) ) . Should ( ) . HaveClass ( "t-button--variant-text" ) ;
43+ RenderComponent ( m => m . Add ( p => p . Varient , ButtonVarient . Text ) ) . Should ( ) . HaveClass ( "t-button--variant-text" ) ;
4344 }
4445
4546 [ Fact ( DisplayName = "按钮 - Ghost 参数" ) ]
4647 public void Test_Ghost_Parameter ( )
4748 {
48- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Ghost , true ) ) . Should ( ) . HaveClass ( "t-button--ghost" ) ;
49+ RenderComponent ( m => m . Add ( p => p . Ghost , true ) ) . Should ( ) . HaveClass ( "t-button--ghost" ) ;
4950 }
5051
5152 [ Fact ( DisplayName = "按钮 - Size 参数" ) ]
5253 public void Test_Size_Parameter ( )
5354 {
54- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Size , Size . Small ) ) . Should ( ) . HaveClass ( "t-size-s" ) ;
55- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Size , Size . Medium ) ) . Should ( ) . HaveClass ( "t-size-m" ) ;
56- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Size , Size . Large ) ) . Should ( ) . HaveClass ( "t-size-l" ) ;
55+ RenderComponent ( m => m . Add ( p => p . Size , Size . Small ) ) . Should ( ) . HaveClass ( "t-size-s" ) ;
56+ RenderComponent ( m => m . Add ( p => p . Size , Size . Medium ) ) . Should ( ) . HaveClass ( "t-size-m" ) ;
57+ RenderComponent ( m => m . Add ( p => p . Size , Size . Large ) ) . Should ( ) . HaveClass ( "t-size-l" ) ;
5758 }
5859
5960 [ Fact ( DisplayName = "按钮 - Block 参数" ) ]
6061 public void Test_Block_Parameter ( )
6162 {
62- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Block , true ) ) . Should ( ) . HaveClass ( "t-size-full-width" ) ;
63+ RenderComponent ( m => m . Add ( p => p . Block , true ) ) . Should ( ) . HaveClass ( "t-size-full-width" ) ;
6364 }
6465
6566 [ Fact ( DisplayName = "按钮 - Shape 参数" ) ]
6667 public void Test_Shape_Parameter ( )
6768 {
68- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Shape , ButtonShape . Rectangle ) ) . Should ( ) . HaveClass ( "t-button--shape-rectangle" ) ;
69- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Shape , ButtonShape . Square ) ) . Should ( ) . HaveClass ( "t-button--shape-square" ) ;
70- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Shape , ButtonShape . Circle ) ) . Should ( ) . HaveClass ( "t-button--shape-circle" ) ;
71- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Shape , ButtonShape . Round ) ) . Should ( ) . HaveClass ( "t-button--shape-round" ) ;
69+ RenderComponent ( m => m . Add ( p => p . Shape , ButtonShape . Rectangle ) ) . Should ( ) . HaveClass ( "t-button--shape-rectangle" ) ;
70+ RenderComponent ( m => m . Add ( p => p . Shape , ButtonShape . Square ) ) . Should ( ) . HaveClass ( "t-button--shape-square" ) ;
71+ RenderComponent ( m => m . Add ( p => p . Shape , ButtonShape . Circle ) ) . Should ( ) . HaveClass ( "t-button--shape-circle" ) ;
72+ RenderComponent ( m => m . Add ( p => p . Shape , ButtonShape . Round ) ) . Should ( ) . HaveClass ( "t-button--shape-round" ) ;
7273 }
7374
7475 [ Fact ( DisplayName = "按钮 - Disabled 参数" ) ]
7576 public void Test_Disabled_Parameter ( )
7677 {
77- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Disabled , true ) ) . Should ( ) . HaveClass ( "t-is-disabled" ) . And . HaveAttribute ( "disabled" , "disabled" ) ;
78+ RenderComponent ( m => m . Add ( p => p . Disabled , true ) ) . Should ( ) . HaveClass ( "t-is-disabled" ) . And . HaveAttribute ( "disabled" , "disabled" ) ;
7879 }
7980
8081
8182 [ Fact ( DisplayName = "按钮 - Loading 参数" ) ]
8283 public void Test_Loading_Parameter ( )
8384 {
84- TestContext . RenderComponent < TButton > ( m => m . Add ( p => p . Loading , true ) ) . Should ( ) . HaveClass ( "t-is-loading" ) ;
85+ RenderComponent ( m => m . Add ( p => p . Loading , true ) ) . Should ( ) . HaveClass ( "t-is-loading" ) ;
86+ }
87+
88+ [ Fact ( DisplayName = "按钮 - 有图标和文字一起适配" ) ]
89+ public void Test_Icon_With_Text ( )
90+ {
91+ var button = RenderComponent ( m => m . Add ( p => p . Icon , IconName . Add ) ) ;
92+ button . FindComponent < TIcon > ( ) . MarkupMatches ( b => b . Component < TIcon > ( ) . Attribute ( m => m . Name , IconName . Add ) . Close ( ) ) ;
93+ }
94+
95+ [ Theory ( DisplayName = "按钮 - 不同的 HTML 标记渲染按钮" ) ]
96+ [ InlineData ( new object [ ] { "div" } ) ]
97+ [ InlineData ( new object [ ] { "a" } ) ]
98+ [ InlineData ( new object [ ] { "span" } ) ]
99+ public void Test_Button_With_TagName ( string tag )
100+ {
101+ RenderComponent ( m => m . Add ( p => p . TagName , tag ) ) . Should ( ) . HaveTag ( tag ) ;
85102 }
86103}
0 commit comments