Skip to content

Commit 97eb165

Browse files
authored
test(LayoutSplitebar): add unit test for LayoutSplitebar (#5443)
* refactor: 更改组件名称 * test: 增加单元测试 * refactor: 增加默认值 * doc: 更新文档示例
1 parent 1333636 commit 97eb165

File tree

9 files changed

+57
-14
lines changed

9 files changed

+57
-14
lines changed

src/BootstrapBlazor.Server/Components/Layout/MainLayout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<span class="sidebar-text">Bootstrap Blazor</span>
1111
</div>
1212
<NavMenu />
13-
<LayoutSidebar Min="250" Max="380" ContainerSelector=".section"></LayoutSidebar>
13+
<LayoutSplitebar Min="250" Max="380" ContainerSelector=".section"></LayoutSplitebar>
1414
</aside>
1515

1616
<section class="main">

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
}
9191
@if (ShowSplitBar)
9292
{
93-
<LayoutSidebar></LayoutSidebar>
93+
<LayoutSplitebar></LayoutSplitebar>
9494
}
9595
@if (Menus != null)
9696
{
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@namespace BootstrapBlazor.Components
22
@inherits BootstrapModuleComponentBase
3-
@attribute [BootstrapModuleAutoLoader("Layout/LayoutSidebar.razor.js")]
3+
@attribute [BootstrapModuleAutoLoader("Layout/LayoutSplitebar.razor.js")]
44

5-
<div id="@Id" class="layout-sidebar"
5+
<div id="@Id" class="layout-splitebar"
66
data-bb-min="@_minWidthString" data-bb-max="@_maxWidthString" data-bb-selector="@ContainerSelector">
7-
<div class="layout-sidebar-body"></div>
7+
<div class="layout-splitebar-body"></div>
88
</div>

src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.cs renamed to src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace BootstrapBlazor.Components;
88
/// <summary>
99
/// LayoutSidebar 组件
1010
/// </summary>
11-
public partial class LayoutSidebar
11+
public partial class LayoutSplitebar
1212
{
1313
/// <summary>
1414
/// 获得/设置 容器选择器 默认 null 未设置

src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.js renamed to src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Drag from "../../modules/drag.js"
2-
import Data from "../../modules/data.js"
32

43
export function init(id) {
54
const el = document.getElementById(id);
@@ -9,9 +8,9 @@ export function init(id) {
98

109
const min = parseFloat(el.getAttribute("data-bb-min") ?? "0");
1110
const max = parseFloat(el.getAttribute("data-bb-max") ?? "0");
12-
const selector = el.getAttribute("data-bb-selector");
11+
const selector = el.getAttribute("data-bb-selector") ?? ".layout";
1312
const section = document.querySelector(selector);
14-
const bar = el.querySelector(".layout-sidebar-body");
13+
const bar = el.querySelector(".layout-splitebar-body");
1514
let originX = 0;
1615
let width = 0;
1716
Drag.drag(bar,
@@ -37,7 +36,7 @@ export function init(id) {
3736
export function dispose(id) {
3837
const el = document.getElementById(id);
3938
if (el) {
40-
const bar = el.querySelector(".layout-sidebar-body");
39+
const bar = el.querySelector(".layout-splitebar-body");
4140
if (bar) {
4241
Drag.dispose(bar);
4342
}

src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.scss renamed to src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.layout-sidebar {
1+
.layout-splitebar {
22
width: 1px;
33
position: absolute;
44
top: 0;
@@ -7,7 +7,7 @@
77
background-color: var(--bs-border-color);
88
display: none;
99

10-
.layout-sidebar-body {
10+
.layout-splitebar-body {
1111
position: absolute;
1212
inset: 0px -2px;
1313
cursor: col-resize;
@@ -26,7 +26,7 @@
2626
}
2727

2828
@media(min-width: 768px) {
29-
.layout-sidebar {
29+
.layout-splitebar {
3030
display: block;
3131
}
3232
}

src/BootstrapBlazor/wwwroot/scss/components.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
@import "../../Components/Input/FloatingLabel.razor.scss";
5858
@import "../../Components/IpAddress/IpAddress.razor.scss";
5959
@import "../../Components/Layout/Layout.razor.scss";
60-
@import "../../Components/Layout/LayoutSidebar.razor.scss";
60+
@import "../../Components/Layout/LayoutSplitebar.razor.scss";
6161
@import "../../Components/Light/Light.razor.scss";
6262
@import "../../Components/ListGroup/ListGroup.razor.scss";
6363
@import "../../Components/ListView/ListView.razor.scss";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace UnitTest.Components;
7+
8+
public class LayoutSplitebarTest : BootstrapBlazorTestBase
9+
{
10+
[Fact]
11+
public void LayoutSplitebar_Ok()
12+
{
13+
var cut = Context.RenderComponent<LayoutSplitebar>(pb =>
14+
{
15+
pb.Add(a => a.ContainerSelector, ".layout");
16+
});
17+
cut.Contains("data-bb-selector=\".layout\"");
18+
19+
cut.SetParametersAndRender(pb =>
20+
{
21+
pb.Add(a => a.Min, 100);
22+
pb.Add(a => a.Max, 200);
23+
});
24+
cut.Contains("data-bb-min=\"100\"");
25+
cut.Contains("data-bb-max=\"200\"");
26+
}
27+
}

test/UnitTest/Components/LayoutTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ public void UseTabSet_Layout()
237237
cut.WaitForAssertion(() => cut.Contains("<div class=\"tabs-body-content\">Binder</div>"));
238238
}
239239

240+
[Fact]
241+
public void ShowLayouSidebar_Ok()
242+
{
243+
var cut = Context.RenderComponent<Layout>(pb =>
244+
{
245+
pb.Add(a => a.UseTabSet, true);
246+
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
247+
pb.Add(a => a.IsFullSide, true);
248+
pb.Add(a => a.ShowSplitBar, true);
249+
pb.Add(a => a.Side, new RenderFragment(builder =>
250+
{
251+
builder.AddContent(0, "test");
252+
}));
253+
});
254+
cut.Contains("layout-splitebar");
255+
}
256+
240257
[Fact]
241258
public void UseTabSet_Menus()
242259
{

0 commit comments

Comments
 (0)