Skip to content

Commit a3aac59

Browse files
ArgoZhangdensen2014lambert leeh2ls
authored
test: add unit test for table improve code coverage (#355)
Co-authored-by: alex chow <zhouchuanglin@gmail.com> Co-authored-by: lambert lee <1708416@qq.com> Co-authored-by: lambert lee <lish@live.cn>
1 parent d3d72a6 commit a3aac59

6 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/BootstrapBlazor.Shared/Locales/en.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,7 +5001,6 @@
50015001
"TableBaseTips1": "<code>Auto</code>: Use <code> cardview </code> mode when the screen is smaller than 768px, otherwise use <code> Table </code> mode",
50025002
"TableBaseTips2": "<code>Table</code>: Table rendering mode, using <code> table </code> elements for data rendering, suitable for viewing data in a wide screen",
50035003
"TableBaseTips3": "<code>CardView</code>:Card rendering mode, using <code> div </code> elements for data rendering, which is suitable for viewing data on a narrow screen",
5004-
"TableBaseExplain3": "<code>Table</code> component has a <code> usecomponentwidth </code> attribute. Its default value is <code> false </code>, which means that the <code> window </code> width is used for judgment. When the setting value is <code> true </code>, it means that the component's own width is used for judgment",
50055004
"TableBaseNormalTitle": "Basic table",
50065005
"TableBaseNormalIntro": "Basic table presentation usage",
50075006
"TableBaseNormalDescription": "Update data source when clicking button <code> items </code> component <code> Table </code> display data is automatically updated",
@@ -5079,7 +5078,6 @@
50795078
"ShowEmptyAttr": "Show no data prompts",
50805079
"ShowToastAfterSaveOrDeleteModelAttr": "Do you show a toast prompt box after a save/delete failure",
50815080
"TreeIconAttr": "Small arrow for tree data rows",
5082-
"UseComponentWidthAttr": "Component rendering mode uses component width to determine",
50835081
"ScrollingDialogContentAttr": "Edit whether the pop-up box appears inside the scroll bar",
50845082
"FixedExtendButtonsColumnAttr": "Whether to fix the extended button column",
50855083
"OnQueryAsyncAttr": "Asynchronous query callback method",

src/BootstrapBlazor.Shared/Locales/zh.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,7 +5035,6 @@
50355035
"TableBaseTips1": "<code>Auto</code>: 当屏幕小于 768px 时使用 <code>CardView</code> 模式,否则使用 <code>Table</code> 模式",
50365036
"TableBaseTips2": "<code>Table</code>: 表格渲染模式,使用 <code>table</code> 元素进行数据渲染,适合宽屏幕下查看数据",
50375037
"TableBaseTips3": "<code>CardView</code>:卡片式渲染模式,使用 <code>div</code> 元素进行数据渲染,适合窄屏幕下查看数据",
5038-
"TableBaseExplain3": "<code>Table</code> 组件有一个 <code>UseComponentWidth</code> 属性,其默认值为 <code>false</code>,表示使用 <code>window</code> 宽度来进行判断,当设置值为 <code>true</code> 时,表示使用组件自身宽度进行判断",
50395038
"TableBaseNormalTitle": "基础表格",
50405039
"TableBaseNormalIntro": "基础的表格展示用法。",
50415040
"TableBaseNormalDescription": "点击按钮时更新数据源 <code>Items</code> 组件 <code>Table</code> 显示数据自动更新",
@@ -5113,7 +5112,6 @@
51135112
"ShowEmptyAttr": "是否显示无数据提示",
51145113
"ShowToastAfterSaveOrDeleteModelAttr": "保存/删除失败后是否显示 Toast 提示框",
51155114
"TreeIconAttr": "树形数据行小箭头",
5116-
"UseComponentWidthAttr": "组件渲染模式是否使用组件宽度来判断",
51175115
"ScrollingDialogContentAttr": "编辑弹窗框是否为内部出现滚动条",
51185116
"FixedExtendButtonsColumnAttr": "是否固定扩展按钮列",
51195117
"OnQueryAsyncAttr": "异步查询回调方法",

src/BootstrapBlazor.Shared/Samples/Table/Tables.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
<li>@((MarkupString)TablesLocalizer["TableBaseTips3"].Value)</li>
1616
</ul>
1717

18-
<p>@((MarkupString)TablesLocalizer["TableBaseExplain3"].Value)</p>
19-
2018
<DemoBlock Title="@TablesLocalizer["TableBaseNormalTitle"]" Introduction="@TablesLocalizer["TableBaseNormalIntro"]" Name="TableBaseNormal" Demo="typeof(Demos.Table.Base.TableBaseNormal)">
2119
<div>@((MarkupString)TablesLocalizer["TableBaseNormalDescription"].Value)</div>
2220
</DemoBlock>

src/BootstrapBlazor.Shared/Samples/Table/Tables.razor.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,14 +841,6 @@ public partial class Tables
841841
DefaultValue = "fa-caret-right"
842842
},
843843
new()
844-
{
845-
Name = "UseComponentWidth",
846-
Description = TablesLocalizer["UseComponentWidthAttr"],
847-
Type = "boolean",
848-
ValueList = "true|false",
849-
DefaultValue = "false"
850-
},
851-
new()
852844
{
853845
Name = "ScrollingDialogContent",
854846
Description = TablesLocalizer["ScrollingDialogContentAttr"],

src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ public partial class Table<TItem>
5151
/// </summary>
5252
protected BreakPoint ScreenSize { get; set; }
5353

54-
/// <summary>
55-
/// 获得/设置 组件渲染模式是否使用组件宽度来判断 默认为 false
56-
/// </summary>
57-
[Parameter]
58-
public bool UseComponentWidth { get; set; }
59-
6054
/// <summary>
6155
/// 获得/设置 组件编辑模式 默认为弹窗编辑行数据 PopupEditForm
6256
/// </summary>

test/UnitTest/Components/TableTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,30 @@ public void IsHideFooterWhenNoData_Ok()
15631563
cut.DoesNotContain("table-footer-test");
15641564
}
15651565

1566+
[Fact]
1567+
public void OnBeforeRenderRow_Ok()
1568+
{
1569+
var row = 0;
1570+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
1571+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
1572+
{
1573+
pb.AddChildContent<Table<Foo>>(pb =>
1574+
{
1575+
pb.Add(a => a.RenderMode, TableRenderMode.Table);
1576+
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 2));
1577+
pb.Add(a => a.TableColumns, foo => builder =>
1578+
{
1579+
builder.OpenComponent<TableColumn<Foo, string>>(0);
1580+
builder.AddAttribute(1, "Field", "Name");
1581+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
1582+
builder.CloseComponent();
1583+
});
1584+
pb.Add(a => a.OnBeforeRenderRow, foo => row++);
1585+
});
1586+
});
1587+
Assert.Equal(2, row);
1588+
}
1589+
15661590
[Fact]
15671591
public void FooterTemplate_Ok()
15681592
{
@@ -3971,7 +3995,6 @@ public void SetRowClassFormatter_Ok()
39713995
pb.Add(a => a.Items, items);
39723996
pb.Add(a => a.IsKeyboard, true);
39733997
pb.Add(a => a.ShowLoading, false);
3974-
pb.Add(a => a.UseComponentWidth, true);
39753998
pb.Add(a => a.RenderModeResponsiveWidth, BreakPoint.Medium);
39763999
pb.Add(a => a.SetRowClassFormatter, foo => "test_row_class");
39774000
pb.Add(a => a.TableColumns, foo => builder =>

0 commit comments

Comments
 (0)