From 73e82b960971e25c5ad857b4091f723aeccf44ca Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 26 Mar 2022 22:33:22 +0800 Subject: [PATCH 1/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Table=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/TableTest.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/UnitTest/Components/TableTest.cs diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs new file mode 100644 index 000000000..eda83ef7f --- /dev/null +++ b/test/UnitTest/Components/TableTest.cs @@ -0,0 +1,27 @@ +// 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 Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; + +namespace UnitTest.Components; + +public class TableTest : BootstrapBlazorTestBase +{ + [Fact] + public void Table_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + }); + }); + + cut.Contains("table"); + } +} -- Gitee From 4db02da92abf3b327c267c9a42b18deb8c48c94b Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 26 Mar 2022 22:40:22 +0800 Subject: [PATCH 2/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20TableColumns?= =?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/TableTest.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index eda83ef7f..f7a44b069 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -24,4 +24,26 @@ public class TableTest : BootstrapBlazorTestBase cut.Contains("table"); } + + [Fact] + public void TableColumns_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + cut.Contains("table"); + } } -- Gitee From da44b9b925fbc02d68b8f992aaa6d8b11ce210c7 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:54:08 +0800 Subject: [PATCH 3/9] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=20Table=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E9=9A=94=E7=A6=BB=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Core/TableTestBase.cs | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/UnitTest/Core/TableTestBase.cs diff --git a/test/UnitTest/Core/TableTestBase.cs b/test/UnitTest/Core/TableTestBase.cs new file mode 100644 index 000000000..338beca21 --- /dev/null +++ b/test/UnitTest/Core/TableTestBase.cs @@ -0,0 +1,83 @@ +// 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 Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace UnitTest.Core; + +[Collection("TableTestContext")] +public class TableTestBase +{ + protected TestContext Context { get; } + + public TableTestBase() + { + Context = TableTestHost.Instance; + } +} + +[CollectionDefinition("TableTestContext")] +public class TableTestCollection : ICollectionFixture +{ + +} + +public class TableTestHost : IDisposable +{ + [NotNull] + internal static TestContext? Instance { get; private set; } + + public TableTestHost() + { + Instance = new TestContext(); + + // Mock 脚本 + Instance.JSInterop.Mode = JSRuntimeMode.Loose; + + ConfigureServices(Instance.Services); + + ConfigureConfigration(Instance.Services); + + // 渲染 BootstrapBlazorRoot 组件 激活 ICacheManager 接口 + Instance.Services.GetRequiredService(); + } + + protected virtual void ConfigureServices(IServiceCollection services) + { + services.AddBootstrapBlazor(); + services.ConfigureJsonLocalizationOptions(op => op.AdditionalJsonAssemblies = new[] { typeof(Alert).Assembly }); + services.AddSingleton(); + } + + protected virtual void ConfigureConfigration(IServiceCollection services) + { + // 增加单元测试 appsettings.json 配置文件 + services.AddConfiguration(); + } + + public void Dispose() + { + Instance.Dispose(); + GC.SuppressFinalize(this); + } + + class FooLookupService : ILookUpService + { + public IEnumerable? GetItemsByKey(string? key) + { + IEnumerable? ret = null; + + if (key == "FooLookup") + { + ret = new SelectedItem[] + { + new("v1", "LookupService-Test-1"), + new("v2", "LookupService-Test-2") + }; + } + return ret; + } + } +} -- Gitee From 2e681bbb967dddb81bb373e538bda6cbb54c11a6 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:54:20 +0800 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E6=8A=A5?= =?UTF-8?q?=E9=94=99=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/UploadTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/UnitTest/Components/UploadTest.cs b/test/UnitTest/Components/UploadTest.cs index fe5cc695e..20839e650 100644 --- a/test/UnitTest/Components/UploadTest.cs +++ b/test/UnitTest/Components/UploadTest.cs @@ -11,7 +11,7 @@ namespace UnitTest.Components; public class UploadTest : BootstrapBlazorTestBase { [Fact] - public void InputUpload_Ok() + public async Task InputUpload_Ok() { UploadFile? uploadFile = null; var cut = Context.RenderComponent>(pb => @@ -27,7 +27,7 @@ public class UploadTest : BootstrapBlazorTestBase cut.Contains("value=\"test.jpg\""); var input = cut.FindComponent(); - cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List() + await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List() { new MockBrowserFile() }))); @@ -66,7 +66,7 @@ public class UploadTest : BootstrapBlazorTestBase cut.Contains("btn btn-delete"); var button = cut.Find(".input-group button"); - cut.InvokeAsync(() => button.Click()); + await cut.InvokeAsync(() => button.Click()); Assert.True(deleted); // IsDisable -- Gitee From e0584711155cf0b84c3855c03a3d8645c53f7f68 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:54:34 +0800 Subject: [PATCH 5/9] =?UTF-8?q?test:=20=E6=9B=B4=E6=94=B9=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TableTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index f7a44b069..3c7d89ea3 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Localization; namespace UnitTest.Components; -public class TableTest : BootstrapBlazorTestBase +public class TableTest : TableTestBase { [Fact] public void Table_Ok() -- Gitee From 4f42c1c156f838e16b0cffe35dd9f4d19ea1eb3e Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:54:49 +0800 Subject: [PATCH 6/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E9=AA=A8?= =?UTF-8?q?=E6=9E=B6=E5=B1=8F=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/TableTest.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 3c7d89ea3..0a490fbc3 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -46,4 +46,25 @@ public class TableTest : TableTestBase cut.Contains("table"); } + + [Fact] + public void ShowSkeleton_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.ShowSkeleton, true); + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + } } -- Gitee From 0bbad0d5c13c17ad0119ef6aef09049a328407eb Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:55:03 +0800 Subject: [PATCH 7/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=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/TableTest.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 0a490fbc3..834c91b0b 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -67,4 +67,27 @@ public class TableTest : TableTestBase }); }); } + + [Fact] + public void ShowSearch_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.ShowSearch, true); + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + cut.Contains("float-end table-toolbar-button btn-group"); + } + } -- Gitee From ae7c32b01b2ae624ad3a6dfeccde53e40bb28031 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:55:18 +0800 Subject: [PATCH 8/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E9=AB=98?= =?UTF-8?q?=E7=BA=A7=E6=90=9C=E7=B4=A2=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/TableTest.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 834c91b0b..6aab3f578 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -90,4 +90,30 @@ public class TableTest : TableTestBase cut.Contains("float-end table-toolbar-button btn-group"); } + [Fact] + public void ShowAdvancedSearch_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.ShowSearch, true); + pb.Add(a => a.ShowSearchText, false); + pb.Add(a => a.ShowAdvancedSearch, true); + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + // 不显示模糊查询框 + // 显示高级搜索按钮 + cut.Contains("fa fa-search-plus"); + } } -- Gitee From 67d1b147c883d54f52a05c06fd3c103a482f5d87 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 10:55:34 +0800 Subject: [PATCH 9/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E9=A1=B6?= =?UTF-8?q?=E6=A0=8F=E6=90=9C=E7=B4=A2=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/TableTest.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 6aab3f578..9eea56fae 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -116,4 +116,27 @@ public class TableTest : TableTestBase // 显示高级搜索按钮 cut.Contains("fa fa-search-plus"); } + + [Fact] + public void ShowTopSearch_Ok() + { + var localizer = Context.Services.GetRequiredService>(); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.ShowSearch, true); + pb.Add(a => a.SearchMode, SearchMode.Top); + pb.Add(a => a.Items, Foo.GenerateFoo(localizer)); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + cut.Contains("table-search"); + } } -- Gitee