From 8294e015699732022d5b242572a8b29f04b72cc2 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 00:51:44 +0800 Subject: [PATCH 01/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20TabLink=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabLinkTest.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/UnitTest/Components/TabLinkTest.cs diff --git a/test/UnitTest/Components/TabLinkTest.cs b/test/UnitTest/Components/TabLinkTest.cs new file mode 100644 index 000000000..f20af302d --- /dev/null +++ b/test/UnitTest/Components/TabLinkTest.cs @@ -0,0 +1,9 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace UnitTest.Components; + +public class TabLinkTest : BootstrapBlazorTestBase +{ +} -- Gitee From 085571ffa8271ec51f08a4d40d5dd52bb5146117 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 00:52:04 +0800 Subject: [PATCH 02/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Click=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabLinkTest.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/UnitTest/Components/TabLinkTest.cs b/test/UnitTest/Components/TabLinkTest.cs index f20af302d..0552d6d0b 100644 --- a/test/UnitTest/Components/TabLinkTest.cs +++ b/test/UnitTest/Components/TabLinkTest.cs @@ -6,4 +6,23 @@ namespace UnitTest.Components; public class TabLinkTest : BootstrapBlazorTestBase { + [Fact] + public void Click_Ok() + { + var clicked = false; + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Url, "/Cat"); + pb.Add(a => a.Text, "Cat"); + pb.Add(a => a.Icon, "fa fa-fa"); + pb.Add(a => a.Closable, false); + pb.Add(a => a.OnClick, () => + { + clicked = true; + return Task.CompletedTask; + }); + }); + cut.Find("a").Click(); + Assert.True(clicked); + } } -- Gitee From d603be71b37af5088e6b485a11cd6b4e36c06864 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 00:52:33 +0800 Subject: [PATCH 03/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20ChildContent?= =?UTF-8?q?=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabLinkTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/UnitTest/Components/TabLinkTest.cs b/test/UnitTest/Components/TabLinkTest.cs index 0552d6d0b..302ac0bef 100644 --- a/test/UnitTest/Components/TabLinkTest.cs +++ b/test/UnitTest/Components/TabLinkTest.cs @@ -25,4 +25,14 @@ public class TabLinkTest : BootstrapBlazorTestBase cut.Find("a").Click(); Assert.True(clicked); } + + [Fact] + public void ChildContent_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.ChildContent, builder => builder.AddContent(0, "Body")); + }); + Assert.Contains("Body", cut.Markup); + } } -- Gitee From 703142c4f464d49cdbc5c1beca4d4c56a426a266 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 01:02:55 +0800 Subject: [PATCH 04/12] =?UTF-8?q?test:=20TabItem=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=8E=87=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 12 ++++++++++++ test/UnitTest/Misc/NullString.cs | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/UnitTest/Misc/NullString.cs diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index aaad053fd..7da6782ad 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -5,6 +5,7 @@ using Bunit.TestDoubles; using Microsoft.Extensions.DependencyInjection; using System.Reflection; +using UnitTest.Misc; namespace UnitTest.Components; @@ -27,6 +28,17 @@ public class TabTest : BootstrapBlazorTestBase }); }); Assert.Contains("Tab1-Content", cut.Markup); + [Fact] + public void TabItemCreate_Ok() + { + TabItem.Create(new Dictionary() + { + ["Url"] = null + }); + TabItem.Create(new Dictionary() + { + ["Url"] = new NullString() + }); } [Fact] diff --git a/test/UnitTest/Misc/NullString.cs b/test/UnitTest/Misc/NullString.cs new file mode 100644 index 000000000..e78647570 --- /dev/null +++ b/test/UnitTest/Misc/NullString.cs @@ -0,0 +1,10 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace UnitTest.Misc; + +internal class NullString +{ + public override string? ToString() => null; +} -- Gitee From aeed103fb9a7ce15c1097268ab247969b0fab788 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 01:03:07 +0800 Subject: [PATCH 05/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Key=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index 7da6782ad..4b2b3f339 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -28,6 +28,9 @@ public class TabTest : BootstrapBlazorTestBase }); }); Assert.Contains("Tab1-Content", cut.Markup); + Assert.Equal("TabItem-Key", cut.FindComponent().Instance.Key); + } + [Fact] public void TabItemCreate_Ok() { -- Gitee From 55fcb351c9cc2c62c7f48315a98e34efbb156db2 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 02:58:51 +0800 Subject: [PATCH 06/12] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Tab/Tab.razor.cs | 48 ++++++------------- src/BootstrapBlazor/Components/Tab/TabItem.cs | 2 + 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs index 98dc9c060..69b285be4 100644 --- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs +++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs @@ -256,44 +256,24 @@ public partial class Tab } } - private bool CheckUrl(string url) - { - var ret = false; - foreach (var rule in ExcludeUrls ?? Enumerable.Empty()) - { - var checkUrl = rule.TrimStart('/'); - var startIndex = checkUrl.IndexOf("?"); - if (startIndex > 0) - { - checkUrl = checkUrl[..startIndex]; - if (url.StartsWith(checkUrl, StringComparison.OrdinalIgnoreCase)) - { - ret = true; - break; - } - } - else - { - if (url.Equals(checkUrl, StringComparison.OrdinalIgnoreCase)) - { - ret = true; - break; - } - } - } - return ret; - } - private void AddTabByUrl() { var requestUrl = Navigator.ToBaseRelativePath(Navigator.Uri); // 判断是否排除 - Excluded = CheckUrl(requestUrl); - + var urls = ExcludeUrls ?? Enumerable.Empty(); + if (requestUrl == "") + { + Excluded = urls.Any(u => u == "" || u == "/"); + } + else + { + Excluded = urls.Any(u => u != "/" && requestUrl.StartsWith(u.TrimStart('/'), StringComparison.OrdinalIgnoreCase)); + } if (!Excluded) { - var tab = Items.FirstOrDefault(tab => tab.Url?.Equals(requestUrl, StringComparison.OrdinalIgnoreCase) ?? false); + // 地址相同参数不同需要重新渲染 TabItem + var tab = Items.FirstOrDefault(tab => tab.Url.Equals(requestUrl, StringComparison.OrdinalIgnoreCase)); if (tab != null) { ActiveTabItem(tab); @@ -366,7 +346,7 @@ public partial class Tab item = Items.ElementAt(index); if (ClickTabToNavigation) { - Navigator.NavigateTo(item.Url!); + Navigator.NavigateTo(item.Url); } else { @@ -404,7 +384,7 @@ public partial class Tab if (ClickTabToNavigation) { - Navigator.NavigateTo(item.Url!); + Navigator.NavigateTo(item.Url); } else { @@ -596,7 +576,7 @@ public partial class Tab { if (ClickTabToNavigation) { - Navigator.NavigateTo(activeItem.Url!); + Navigator.NavigateTo(activeItem.Url); } else { diff --git a/src/BootstrapBlazor/Components/Tab/TabItem.cs b/src/BootstrapBlazor/Components/Tab/TabItem.cs index 3617c51b5..726ab95be 100644 --- a/src/BootstrapBlazor/Components/Tab/TabItem.cs +++ b/src/BootstrapBlazor/Components/Tab/TabItem.cs @@ -21,6 +21,7 @@ public class TabItem : ComponentBase /// 获得/设置 请求地址 /// [Parameter] + [NotNull] public string? Url { get; set; } /// @@ -72,6 +73,7 @@ public class TabItem : ComponentBase { base.OnInitialized(); + Url ??= ""; TabSet?.AddItem(this); } -- Gitee From 123e81b9bb53cf6e0b5cec01740fe396e2b6a5f2 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 02:59:21 +0800 Subject: [PATCH 07/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index 4b2b3f339..ffd669d6d 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -49,7 +49,6 @@ public class TabTest : BootstrapBlazorTestBase { var cut = Context.RenderComponent(pb => { - pb.Add(a => a.ShowExtendButtons, true); pb.Add(a => a.Placement, Placement.Left); pb.Add(a => a.Height, 100); }); @@ -83,6 +82,8 @@ public class TabTest : BootstrapBlazorTestBase var clicked = false; var cut = Context.RenderComponent(pb => { + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.Placement, Placement.Bottom); pb.Add(a => a.OnClickTab, item => { clicked = true; @@ -114,6 +115,7 @@ public class TabTest : BootstrapBlazorTestBase cut.InvokeAsync(() => tab.ClickPrevTab()); cut.InvokeAsync(() => tab.CloseCurrentTab()); cut.InvokeAsync(() => tab.CloseAllTabs()); + cut.InvokeAsync(() => tab.CloseCurrentTab()); } [Fact] @@ -147,12 +149,61 @@ public class TabTest : BootstrapBlazorTestBase public void AddTabByUrl_Ok() { var navMan = Context.Services.GetRequiredService(); + navMan.NavigateTo("/"); var cut = Context.RenderComponent(pb => { pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); pb.Add(a => a.ClickTabToNavigation, true); }); + + navMan.NavigateTo("/"); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.ExcludeUrls, new String[] { "/" }); + }); + + navMan.NavigateTo("/"); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.ExcludeUrls, new String[] { "" }); + }); + + navMan.NavigateTo("/Cat"); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.ExcludeUrls, new String[] { "/", "Cat" }); + }); + navMan.NavigateTo("/"); + cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary + { + ["Text"] = "Cat", + ["Url"] = "Cat" + })); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.ExcludeUrls, new String[] { "/Test" }); + }); + cut.InvokeAsync(() => cut.Instance.CloseCurrentTab()); + + // AddTab + cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary + { + ["Text"] = "Cat", + ["Url"] = null, + ["IsActive"] = true + })); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.ExcludeUrls, new String[] { "/Test" }); + }); + + // Remove Tab + var item = cut.Instance.GetActiveTab(); + Assert.NotNull(item); + cut.InvokeAsync(() => cut.Instance.RemoveTab(item!)); + item = cut.Instance.GetActiveTab(); + Assert.Null(item); } [Fact] -- Gitee From 2ad219961b2ee029f3f16120f4426c85fe9cc037 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 02:59:51 +0800 Subject: [PATCH 08/12] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 36 ++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index ffd669d6d..9542b9f63 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -207,20 +207,44 @@ public class TabTest : BootstrapBlazorTestBase } [Fact] - public void ExcludeUrls_Ok() + public void DefaultUrl_Ok() { - var navMan = Context.Services.GetRequiredService(); var cut = Context.RenderComponent(pb => { pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); - pb.Add(a => a.ClickTabToNavigation, true); - pb.Add(a => a.ExcludeUrls, new String[] { "/Cat" }); + pb.Add(a => a.DefaultUrl, "/"); + pb.Add(a => a.NullTabText, "NotFound"); }); - navMan.NavigateTo("/Cat"); + var item = cut.Instance.GetActiveTab(); + Assert.Contains("Index", cut.Markup); } [Fact] - public void DefaultUrl_Ok() + public void IsOnlyRenderActiveTab_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); + pb.Add(a => a.IsOnlyRenderActiveTab, true); + pb.AddChildContent(pb => + { + pb.Add(a => a.Text, "Tab1"); + pb.Add(a => a.Url, "/Cat"); + pb.Add(a => a.ChildContent, "Tab1-Content"); + }); + pb.AddChildContent(pb => + { + pb.Add(a => a.Text, "Tab2"); + pb.Add(a => a.Url, "/"); + pb.Add(a => a.Closable, false); + pb.Add(a => a.ChildContent, "Tab2-Content"); + }); + }); + Assert.Equal(1, cut.FindAll(".tabs-body-content").Count); + + // 提高代码覆盖率 + cut.InvokeAsync(() => cut.Instance.CloseOtherTabs()); + } { var cut = Context.RenderComponent(pb => { -- Gitee From 80fb7f86ddd2a8ece26b0be0d9f8de608aed4507 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Feb 2022 03:00:04 +0800 Subject: [PATCH 09/12] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20ActiveTab=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index 9542b9f63..eb78710b4 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -245,10 +245,27 @@ public class TabTest : BootstrapBlazorTestBase // 提高代码覆盖率 cut.InvokeAsync(() => cut.Instance.CloseOtherTabs()); } + + [Fact] + public void ActiveTab_Ok() { var cut = Context.RenderComponent(pb => { + pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); pb.Add(a => a.DefaultUrl, "/"); }); + cut.InvokeAsync(() => cut.Instance.ActiveTab(0)); + var item = cut.Instance.GetActiveTab(); + Assert.NotNull(item); + cut.InvokeAsync(() => + { + if (item != null) + { + cut.Instance.ActiveTab(item); + } + }); + cut.InvokeAsync(() => cut.Instance.RemoveTab(item!)); + item = cut.Instance.GetActiveTab(); + Assert.Null(item); } } -- Gitee From ceb968810bde1c57dd64e06ba07ccd4cc4eaa0c5 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Feb 2022 00:59:37 +0800 Subject: [PATCH 10/12] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20Tab=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E9=AB=98=E4=BB=A3=E7=A0=81=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Tab/Tab.razor.cs | 28 +++---------------- .../Extensions/NavigationManagerExtensions.cs | 5 ++-- .../Options/TabItemTextOptions.cs | 16 +++++------ 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs index 69b285be4..00183e367 100644 --- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs +++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs @@ -170,13 +170,6 @@ public partial class Tab [NotNull] public string? CloseCurrentTabText { get; set; } - /// - /// 获得/设置 空白 Tab 显示文字 - /// - [Parameter] - [NotNull] - public string? NullTabText { get; set; } - /// /// 获得/设置 关闭所有 TabItem 菜单文本 /// @@ -273,7 +266,7 @@ public partial class Tab if (!Excluded) { // 地址相同参数不同需要重新渲染 TabItem - var tab = Items.FirstOrDefault(tab => tab.Url.Equals(requestUrl, StringComparison.OrdinalIgnoreCase)); + var tab = Items.FirstOrDefault(tab => tab.Url.TrimStart('/').Equals(requestUrl, StringComparison.OrdinalIgnoreCase)); if (tab != null) { ActiveTabItem(tab); @@ -503,29 +496,16 @@ public partial class Tab { var text = Options.Text; var icon = Options.Icon ?? string.Empty; - var active = Options.IsActive ?? true; - var closable = Options.Closable ?? true; + var active = Options.IsActive; + var closable = Options.Closable; Options.Reset(); parameters.Add(nameof(TabItem.Url), url); parameters.Add(nameof(TabItem.Icon), icon); parameters.Add(nameof(TabItem.Closable), closable); parameters.Add(nameof(TabItem.IsActive), active); - parameters.Add(nameof(TabItem.Text), GetTabText(text, context.Segments)); - } - } - - private string GetTabText(string? text, string[]? segments) - { - if (NullTabText == null) - { - var t = Localizer[nameof(NullTabText)]; - if (!t.ResourceNotFound) - { - NullTabText = t.Value; - } + parameters.Add(nameof(TabItem.Text), text); } - return text ?? NullTabText ?? segments?.FirstOrDefault() ?? ""; } /// diff --git a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs index 860be3377..3760720bd 100644 --- a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs +++ b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs @@ -21,13 +21,12 @@ public static class NavigationManagerExtensions /// /// /// - public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null) + public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool closable = true) { var option = provider.GetRequiredService(); option.Text = text; option.Icon = icon; - option.IsActive = true; - option.Closable = closable ?? true; + option.Closable = closable; navigation.NavigateTo(url); } } diff --git a/src/BootstrapBlazor/Options/TabItemTextOptions.cs b/src/BootstrapBlazor/Options/TabItemTextOptions.cs index 3edbaec6d..6b2a693eb 100644 --- a/src/BootstrapBlazor/Options/TabItemTextOptions.cs +++ b/src/BootstrapBlazor/Options/TabItemTextOptions.cs @@ -20,29 +20,29 @@ internal class TabItemTextOptions public string? Icon { get; set; } /// - /// 获得/设置 是否激活 默认为 null + /// 获得/设置 是否激活 默认为 true /// /// - public bool? IsActive { get; set; } + public bool IsActive { get; set; } = true; /// - /// 获得/设置 当前 TabItem 是否可关闭 默认为 null + /// 获得/设置 当前 TabItem 是否可关闭 默认为 true /// - public bool? Closable { get; set; } + public bool Closable { get; set; } = true; /// - /// + /// 重置方法 /// public void Reset() { Text = null; Icon = null; - IsActive = null; - Closable = null; + IsActive = true; + Closable = true; } /// - /// + /// 是否可用方法 /// /// public bool Valid() => Text != null; -- Gitee From 684e496a4e6ca59127d7949fac1f130fd6ae3996 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Feb 2022 01:00:11 +0800 Subject: [PATCH 11/12] =?UTF-8?q?test:=20=E6=8F=90=E9=AB=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TabTest.cs | 78 ++++++++++++++++++++++++++--- test/UnitTest/Pages/Cat.cs | 1 + 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index eb78710b4..2d63cf417 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -84,6 +84,7 @@ public class TabTest : BootstrapBlazorTestBase { pb.Add(a => a.ShowExtendButtons, true); pb.Add(a => a.Placement, Placement.Bottom); + pb.Add(a => a.ShowClose, true); pb.Add(a => a.OnClickTab, item => { clicked = true; @@ -108,14 +109,56 @@ public class TabTest : BootstrapBlazorTestBase cut.Find(".tabs-item").Click(); Assert.True(clicked); - var tab = cut.Instance; - cut.InvokeAsync(() => tab.ClickNextTab()); + // Click Prev + var button = cut.Find(".nav-link-bar.left"); + button.Click(); + button.Click(); + button.Click(); Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none").InnerHtml); - cut.InvokeAsync(() => tab.ClickPrevTab()); - cut.InvokeAsync(() => tab.CloseCurrentTab()); - cut.InvokeAsync(() => tab.CloseAllTabs()); - cut.InvokeAsync(() => tab.CloseCurrentTab()); + // Click Next + button = cut.Find(".nav-link-bar.right"); + button.Click(); + button.Click(); + button.Click(); + Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml); + + // Close + button = cut.Find(".tabs-item-close"); + button.Click(); + } + + [Fact] + public void ClickTabToNavigation_True() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.Placement, Placement.Top); + pb.Add(a => a.ClickTabToNavigation, true); + pb.Add(a => a.ShowClose, true); + pb.Add(a => a.DefaultUrl, "/"); + }); + cut.InvokeAsync(() => cut.Instance.AddTab("/", "Index")); + cut.InvokeAsync(() => cut.Instance.AddTab("/Cat", null!)); + + // Click Prev + var button = cut.Find(".nav-link-bar.left"); + button.Click(); + + // Click Next + button = cut.Find(".nav-link-bar.right"); + button.Click(); + + button = cut.Find(".tabs-item-close"); + button.Click(); + + // Close Current + cut.InvokeAsync(() => cut.Instance.CloseAllTabs()); + + button = cut.Find(".dropdown-item"); + button.Click(); } [Fact] @@ -213,7 +256,6 @@ public class TabTest : BootstrapBlazorTestBase { pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); pb.Add(a => a.DefaultUrl, "/"); - pb.Add(a => a.NullTabText, "NotFound"); }); var item = cut.Instance.GetActiveTab(); Assert.Contains("Index", cut.Markup); @@ -268,4 +310,26 @@ public class TabTest : BootstrapBlazorTestBase item = cut.Instance.GetActiveTab(); Assert.Null(item); } + + [Fact] + public void NavigationActiveTab_Ok() + { + var navMan = Context.Services.GetRequiredService(); + navMan.NavigateTo("/"); + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); + pb.Add(a => a.ClickTabToNavigation, true); + pb.AddChildContent(pb => + { + pb.Add(a => a.Text, "Tab1"); + pb.Add(a => a.Url, "/Cat"); + }); + pb.AddChildContent(pb => + { + pb.Add(a => a.Text, "Tab2"); + pb.Add(a => a.Url, "/"); + }); + }); + } } diff --git a/test/UnitTest/Pages/Cat.cs b/test/UnitTest/Pages/Cat.cs index 2fd2d3442..f28487d46 100644 --- a/test/UnitTest/Pages/Cat.cs +++ b/test/UnitTest/Pages/Cat.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components.Rendering; namespace UnitTest.Pages; [Route("/Cat")] +[TabItemOption(Icon = "fa fa-fa", Closable = true, Text = "Cat")] public class Cat : ComponentBase { protected override void BuildRenderTree(RenderTreeBuilder builder) -- Gitee From 714694b5e4339e65d1c0f6a33c824d953ef4e0bf Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 6 Feb 2022 01:00:23 +0800 Subject: [PATCH 12/12] =?UTF-8?q?test:=20=E6=81=A2=E5=A4=8D=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/LayoutTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/UnitTest/Components/LayoutTest.cs b/test/UnitTest/Components/LayoutTest.cs index 28cbd1e9c..ad080c188 100644 --- a/test/UnitTest/Components/LayoutTest.cs +++ b/test/UnitTest/Components/LayoutTest.cs @@ -211,6 +211,10 @@ public class LayoutTest : BootstrapBlazorTestBase }); navMan.NavigateTo("/"); Assert.Equal("http://localhost/Test", navMan.Uri); + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.OnAuthorizing, null); + }); } [Fact] -- Gitee