From 8738a20682b308e2fa3df9cb3122cc4472886b2a Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 16:41:53 +0800 Subject: [PATCH 1/8] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Filters/LookupFilter.razor.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs b/src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs index 952a22ba3..387dfc25f 100644 --- a/src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs +++ b/src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs @@ -16,15 +16,12 @@ public partial class LookupFilter private List Items { get; } = new List(); - /// - /// 内部使用 - /// - [NotNull] - private Type? EnumType { get; set; } - /// /// 获得/设置 相关枚举类型 /// +#if NET6_0_OR_GREATER + [EditorRequired] +#endif [Parameter] [NotNull] @@ -33,6 +30,9 @@ public partial class LookupFilter /// /// 获得/设置 相关枚举类型 /// +#if NET6_0_OR_GREATER + [EditorRequired] +#endif [Parameter] [NotNull] public Type? Type { get; set; } @@ -48,11 +48,15 @@ public partial class LookupFilter { base.OnInitialized(); + if (Lookup == null) throw new InvalidOperationException("the Parameter Lookup must be set."); + + if (Type == null) throw new InvalidOperationException("the Parameter Type must be set."); + if (TableFilter != null) { TableFilter.ShowMoreButton = false; } - Items.Add(new SelectedItem("", Localizer["EnumFilter.AllText"]?.Value ?? "All")); + Items.Add(new SelectedItem("", Localizer["EnumFilter.AllText"].Value)); Items.AddRange(Lookup); } -- Gitee From 9188f25e19a84108e85da901be61e09fe5e77272 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 16:42:32 +0800 Subject: [PATCH 2/8] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20LookupFilter?= =?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/TableLookupFilterTest.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/UnitTest/Components/TableLookupFilterTest.cs diff --git a/test/UnitTest/Components/TableLookupFilterTest.cs b/test/UnitTest/Components/TableLookupFilterTest.cs new file mode 100644 index 000000000..c6f883299 --- /dev/null +++ b/test/UnitTest/Components/TableLookupFilterTest.cs @@ -0,0 +1,12 @@ +// 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/ + +using BootstrapBlazor.Shared; +using UnitTest.Extensions; + +namespace UnitTest.Components; + +public class TableLookupFilterTest : BootstrapBlazorTestBase +{ +} -- Gitee From 2cab6abdb55019141f1ab51352a0e52046f04c8a Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 16:42:44 +0800 Subject: [PATCH 3/8] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=A8=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/TableLookupFilterTest.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/UnitTest/Components/TableLookupFilterTest.cs b/test/UnitTest/Components/TableLookupFilterTest.cs index c6f883299..5f6cc41af 100644 --- a/test/UnitTest/Components/TableLookupFilterTest.cs +++ b/test/UnitTest/Components/TableLookupFilterTest.cs @@ -9,4 +9,89 @@ namespace UnitTest.Components; public class TableLookupFilterTest : BootstrapBlazorTestBase { + [Fact] + public void Reset_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Type, typeof(string)); + pb.Add(a => a.Lookup, new List() + { + new SelectedItem("true", "True"), + new SelectedItem("false", "False") + }); + }); + + var filter = cut.Instance; + cut.InvokeAsync(() => filter.Reset()); + } + + [Fact] + public void GetFilterConditions_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Type, typeof(string)); + pb.Add(a => a.Lookup, new List() + { + new SelectedItem("true", "True"), + new SelectedItem("false", "False") + }); + }); + + var filter = cut.Instance; + IEnumerable? condtions = null; + cut.InvokeAsync(() => condtions = filter.GetFilterConditions()); + Assert.Empty(condtions); + + // Set Value + var items = cut.FindAll(".dropdown-item"); + cut.InvokeAsync(() => items[1].Click()); + cut.InvokeAsync(() => condtions = filter.GetFilterConditions()); + Assert.Single(condtions); + } + + [Fact] + public void InvalidOperationException_Exception() + { + Assert.ThrowsAny(() => Context.RenderComponent()); + Assert.ThrowsAny(() => Context.RenderComponent(pb => + { + pb.Add(a => a.Lookup, new List()); + })); + } + + [Fact] + public void IsHeaderRow_OnFilterValueChanged() + { + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.Items, new List() { new Foo() }); + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.ShowFilterHeader, true); + pb.Add(a => a.TableColumns, new RenderFragment(foo => builder => + { + var index = 0; + builder.OpenComponent>(index++); + builder.AddAttribute(index++, nameof(TableColumn.Field), foo.Complete); + builder.AddAttribute(index++, nameof(TableColumn.FieldExpression), foo.GenerateValueExpression(nameof(foo.Complete), typeof(bool))); + builder.AddAttribute(index++, nameof(TableColumn.Filterable), true); + builder.AddAttribute(index++, nameof(TableColumn.Lookup), new List() + { + new SelectedItem("true", "True"), + new SelectedItem("false", "False") + }); + builder.CloseComponent(); + })); + }); + }); + + var items = cut.FindAll(".dropdown-item"); + IEnumerable? condtions = null; + cut.InvokeAsync(() => items[1].Click()); + cut.InvokeAsync(() => condtions = cut.FindComponent().Instance.GetFilterConditions()); + Assert.Single(condtions); + } } -- Gitee From b28e3620032bcc6a5a73f67078d31d93ec624c65 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 16:56:31 +0800 Subject: [PATCH 4/8] =?UTF-8?q?refactor:=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Filters/FilterLogicItem.razor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Components/Filters/FilterLogicItem.razor.cs b/src/BootstrapBlazor/Components/Filters/FilterLogicItem.razor.cs index 99a09b57e..7b6c9fb51 100644 --- a/src/BootstrapBlazor/Components/Filters/FilterLogicItem.razor.cs +++ b/src/BootstrapBlazor/Components/Filters/FilterLogicItem.razor.cs @@ -53,9 +53,9 @@ public partial class FilterLogicItem base.OnInitialized(); Items = new List() - { - new SelectedItem("And",Localizer["And"]?.Value ?? "And"), - new SelectedItem("Or",Localizer["Or"]?.Value ?? "Or") - }; + { + new SelectedItem("And",Localizer["And"].Value), + new SelectedItem("Or",Localizer["Or"].Value) + }; } } -- Gitee From 0c99933a4f4d6430ce2b3bcf6eb9c1a6367a7bcd Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 16:56:46 +0800 Subject: [PATCH 5/8] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20FilterKeyValue?= =?UTF-8?q?Action=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/TableFilterTest.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/UnitTest/Components/TableFilterTest.cs b/test/UnitTest/Components/TableFilterTest.cs index 06575d93a..8795c355b 100644 --- a/test/UnitTest/Components/TableFilterTest.cs +++ b/test/UnitTest/Components/TableFilterTest.cs @@ -116,6 +116,18 @@ public class TableFilterTest : BootstrapBlazorTestBase }); } + [Fact] + public void FilterKeyValueAction_Ok() + { + var fkv = new FilterKeyValueAction() + { + FieldKey = "Key", + FilterLogic = FilterLogic.Or + }; + Assert.Equal("Key", fkv.FieldKey); + Assert.Equal(FilterLogic.Or, fkv.FilterLogic); + } + private static RenderFragment CreateTableColumns() => foo => builder => { var index = 0; -- Gitee From df05a0adc615723c3226f208550221e7b3a300be Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 17:13:38 +0800 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Filters/SearchFilterAction.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Filters/SearchFilterAction.cs b/src/BootstrapBlazor/Components/Filters/SearchFilterAction.cs index de7769672..86e767f65 100644 --- a/src/BootstrapBlazor/Components/Filters/SearchFilterAction.cs +++ b/src/BootstrapBlazor/Components/Filters/SearchFilterAction.cs @@ -42,12 +42,12 @@ public class SearchFilterAction : IFilterAction /// /// public virtual IEnumerable GetFilterConditions() => new List() + { + new() { - new() - { - FieldKey = Name, - FieldValue = Value, - FilterAction = Action, - } - }; + FieldKey = Name, + FieldValue = Value, + FilterAction = Action, + } + }; } -- Gitee From 1c80c386ed371fd6522d7f59eb6be34e9edb75e3 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Feb 2022 17:14:03 +0800 Subject: [PATCH 7/8] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20SearchFilterAc?= =?UTF-8?q?tion=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/TableFilterTest.cs | 12 ------------ test/UnitTest/Components/TableStringFilterTest.cs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/UnitTest/Components/TableFilterTest.cs b/test/UnitTest/Components/TableFilterTest.cs index 8795c355b..06575d93a 100644 --- a/test/UnitTest/Components/TableFilterTest.cs +++ b/test/UnitTest/Components/TableFilterTest.cs @@ -116,18 +116,6 @@ public class TableFilterTest : BootstrapBlazorTestBase }); } - [Fact] - public void FilterKeyValueAction_Ok() - { - var fkv = new FilterKeyValueAction() - { - FieldKey = "Key", - FilterLogic = FilterLogic.Or - }; - Assert.Equal("Key", fkv.FieldKey); - Assert.Equal(FilterLogic.Or, fkv.FilterLogic); - } - private static RenderFragment CreateTableColumns() => foo => builder => { var index = 0; diff --git a/test/UnitTest/Components/TableStringFilterTest.cs b/test/UnitTest/Components/TableStringFilterTest.cs index 5b1a04175..0187b94a1 100644 --- a/test/UnitTest/Components/TableStringFilterTest.cs +++ b/test/UnitTest/Components/TableStringFilterTest.cs @@ -34,6 +34,8 @@ public class TableStringFilterTest : BootstrapBlazorTestBase conditions = cut.Instance.GetFilterConditions(); Assert.Equal(2, conditions.Count()); + + // 测试 FilterLogicItem LogicChanged 代码覆盖率 } [Fact] @@ -66,4 +68,17 @@ public class TableStringFilterTest : BootstrapBlazorTestBase cut.InvokeAsync(() => condtions = cut.FindComponent().Instance.GetFilterConditions()); Assert.Single(condtions); } + + [Fact] + public void SearchFilterAction_Ok() + { + var searchFilterAction = new SearchFilterAction("Test-Search", "1", FilterAction.NotEqual); + + var condtion = searchFilterAction.GetFilterConditions(); + Assert.Single(condtion); + Assert.Equal("Test-Search", condtion.First().FieldKey); + Assert.Equal("1", condtion.First().FieldValue); + Assert.Equal(FilterAction.NotEqual, condtion.First().FilterAction); + Assert.Equal(FilterLogic.And, condtion.First().FilterLogic); + } } -- Gitee From 81d93fdf9a3c4068cf0c5bcddb5443c53283ec44 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Fri, 18 Feb 2022 11:21:39 +0800 Subject: [PATCH 8/8] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20FilterLogicIte?= =?UTF-8?q?m=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/TableStringFilterTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/UnitTest/Components/TableStringFilterTest.cs b/test/UnitTest/Components/TableStringFilterTest.cs index 0187b94a1..edd7c5009 100644 --- a/test/UnitTest/Components/TableStringFilterTest.cs +++ b/test/UnitTest/Components/TableStringFilterTest.cs @@ -36,6 +36,10 @@ public class TableStringFilterTest : BootstrapBlazorTestBase Assert.Equal(2, conditions.Count()); // 测试 FilterLogicItem LogicChanged 代码覆盖率 + var logicItem = cut.FindComponent(); + var item = logicItem.FindAll(".dropdown-item")[0]; + cut.InvokeAsync(() => item.Click()); + Assert.Equal(FilterLogic.And, logicItem.Instance.Logic); } [Fact] -- Gitee