@@ -273,8 +273,8 @@ public async Task ResetVisibleColumns_Ok()
273273 var table = cut . FindComponent < Table < Foo > > ( ) ;
274274 await cut . InvokeAsync ( ( ) => table . Instance . ResetVisibleColumns (
275275 [
276- new TableColumnState ( ) { Name = nameof ( Foo . Name ) , Visible = true , DisplayName = "Name-Display" } ,
277- new TableColumnState ( ) { Name = nameof ( Foo . Address ) , Visible = false }
276+ new TableColumnState ( ) { Name = nameof ( Foo . Name ) , Visible = true , Width = 120 } ,
277+ new TableColumnState ( ) { Name = nameof ( Foo . Address ) , Visible = false , Width = 100 }
278278 ] ) ) ;
279279
280280 Assert . Single ( table . Instance . GetVisibleColumns ( ) ) ;
@@ -284,6 +284,9 @@ await cut.InvokeAsync(() => table.Instance.ResetVisibleColumns(
284284 Assert . Equal ( 2 , labels . Count ) ;
285285 Assert . Equal ( "姓名" , labels [ 0 ] . TextContent ) ;
286286 Assert . Equal ( "地址" , labels [ 1 ] . TextContent ) ;
287+
288+ // 检查宽度设置
289+ Assert . Contains ( "<col style=\" width: 120px;\" />" , table . Markup ) ;
287290 }
288291
289292 [ Fact ]
@@ -902,7 +905,9 @@ public async Task ShowColumnList_Ok()
902905 state . Columns = new List < TableColumnState > ( )
903906 {
904907 new TableColumnState ( ) { Name = nameof ( Foo . Name ) , Visible = false } ,
905- new TableColumnState ( ) { Name = nameof ( Foo . Address ) , Visible = true , Width = 120 }
908+ new TableColumnState ( ) { Name = nameof ( Foo . Address ) , Visible = true , Width = 120 } ,
909+ // 增加一列 Columns 中不存在的列
910+ new TableColumnState ( ) { Name = nameof ( Foo . Count ) , Visible = true , Width = 120 }
906911 } ;
907912
908913 Context . JSInterop . Setup < TableColumnClientStatus > ( "getColumnStates" , "test" ) . SetResult ( state ) ;
@@ -945,6 +950,12 @@ public async Task ShowColumnList_Ok()
945950 cut . Contains ( "Test_Column_List" ) ;
946951 cut . DoesNotContain ( "dropdown-menu-popover" ) ;
947952
953+ // 过滤掉 Count 列只显示 Name 和 Address 列
954+ var labels = cut . FindAll ( ".form-check-label" ) ;
955+ Assert . Equal ( 2 , labels . Count ) ;
956+ Assert . Equal ( "姓名" , labels [ 0 ] . TextContent ) ;
957+ Assert . Equal ( "地址" , labels [ 1 ] . TextContent ) ;
958+
948959 var item = cut . FindComponents < Checkbox < bool > > ( ) [ 0 ] ;
949960 await cut . InvokeAsync ( item . Instance . OnToggleClick ) ;
950961 Assert . True ( show ) ;
@@ -981,7 +992,7 @@ public async Task ShowColumnList_Ok()
981992 cut . Contains ( "style=\" width: 340px;\" " ) ;
982993
983994 // 检查 ShowColumnList 中的 DisplayName 是否正确
984- var labels = table . FindAll ( ".form-check-label" ) ;
995+ labels = table . FindAll ( ".form-check-label" ) ;
985996 Assert . Equal ( 2 , labels . Count ) ;
986997 Assert . Equal ( "姓名" , labels [ 0 ] . TextContent ) ;
987998 Assert . Equal ( "地址" , labels [ 1 ] . TextContent ) ;
@@ -7978,6 +7989,7 @@ await cut.WaitForAssertionAsync(() =>
79787989 } ) ;
79797990
79807991 // 二次渲染触发 OnColumnCreating
7992+ // 虽然更改了 Visible 但是以持久化的为准,更改 visible 变量不影响渲染结果
79817993 visible = true ;
79827994 creating = false ;
79837995 cut . Render ( ) ;
@@ -7986,7 +7998,7 @@ await cut.WaitForAssertionAsync(() =>
79867998 {
79877999 Assert . True ( creating ) ;
79888000 var table = cut . FindComponent < Table < Foo > > ( ) ;
7989- Assert . Equal ( 2 , table . Instance . GetVisibleColumns ( ) . Count ) ;
8001+ Assert . Single ( table . Instance . GetVisibleColumns ( ) ) ;
79908002 } ) ;
79918003 }
79928004
@@ -8961,6 +8973,9 @@ public async Task OnLoadTableColumnClientStatus_Ok()
89618973 state . Columns . Add ( new TableColumnState ( ) { Name = nameof ( Foo . Name ) , Visible = true , Width = 100 , DisplayName = "Name-Display" } ) ;
89628974 state . Columns . Add ( new TableColumnState ( ) { Name = nameof ( Foo . Address ) , Visible = false , Width = 120 , DisplayName = "Address-Display" } ) ;
89638975
8976+ // 增加干扰列
8977+ state . Columns . Add ( new TableColumnState ( ) { Name = "" , Visible = true } ) ;
8978+
89648979 var loaded = false ;
89658980 var localizer = Context . Services . GetRequiredService < IStringLocalizer < Foo > > ( ) ;
89668981 var items = Foo . GenerateFoo ( localizer , 2 ) ;
0 commit comments