From 6646e6cb67d79e658b4ee04192dc6c8e0c539a28 Mon Sep 17 00:00:00 2001 From: capdiem Date: Thu, 21 Nov 2024 17:21:39 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20update=20unit=20tests=20(#2?= =?UTF-8?q?255)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 + src/Masa.Blazor/Components/App/MApp.razor.cs | 2 - .../Components/Button/MButton.razor.cs | 2 - .../Components/List/MList.razor.cs | 1 + src/Masa.Blazor/Core/MasaComponentBase.cs | 7 +- src/Masa.Blazor/Services/Application.cs | 5 +- test/Masa.Blazor.Test/Alert/MAlertTests.cs | 118 ++-- test/Masa.Blazor.Test/App/MAppTests.cs | 41 +- test/Masa.Blazor.Test/App/MMainTests.cs | 43 +- test/Masa.Blazor.Test/AppBar/MAppBarTests.cs | 390 +++---------- .../Aspect ratios/MResponsiveTests.cs | 12 +- .../Autocomplete/MAutocompleteTests.cs | 31 - .../Autocompletes/MAutocompleteTests.cs | 548 ++---------------- test/Masa.Blazor.Test/Avatar/MAvatarTest.cs | 14 +- test/Masa.Blazor.Test/Badge/MBadgeTests.cs | 45 -- test/Masa.Blazor.Test/Banner/MBannerTests.cs | 75 --- .../Button/MButtonGroupTests.cs | 120 ---- test/Masa.Blazor.Test/Button/MButtonTests.cs | 206 ++----- test/Masa.Blazor.Test/Card/MCardTests.cs | 134 +---- .../Checkbox/MCheckboxTests.cs | 16 - test/Masa.Blazor.Test/Chip/MChipTests.cs | 45 -- test/Masa.Blazor.Test/Dialog/MDialogTests.cs | 30 - .../Masa.Blazor.Test/Divider/MDividerTests.cs | 19 +- .../Masa.Blazor.Test/ECharts/MEChartsTests.cs | 2 +- test/Masa.Blazor.Test/Footer/MFooterTests.cs | 12 +- test/Masa.Blazor.Test/Image/MImageTests.cs | 12 +- test/Masa.Blazor.Test/Input/MInputTests.cs | 76 +-- .../List/MListItemAvatarTests.cs | 14 +- test/Masa.Blazor.Test/List/MListTests.cs | 14 +- test/Masa.Blazor.Test/Masa.Blazor.Test.csproj | 8 +- .../MNavigationDrawerTests.cs | 22 +- .../Masa.Blazor.Test/Overlay/MOverlayTests.cs | 45 +- test/Masa.Blazor.Test/Picker/MPickerTests.cs | 2 +- .../ProgressLinear/MProgressLinearTests.cs | 9 +- test/Masa.Blazor.Test/Radio/MRadioTests.cs | 30 - .../RangeSlider/MRangeSliderTests.cs | 2 +- test/Masa.Blazor.Test/Sheet/MSheetTests.cs | 12 +- .../Snackbar/MSnackbarTests.cs | 12 +- .../Masa.Blazor.Test/Stepper/MStepperTests.cs | 12 +- .../SystemBar/MSystemBarTests.cs | 2 +- test/Masa.Blazor.Test/TestBase.cs | 38 +- .../Masa.Blazor.Test/Toolbar/MToolbarTests.cs | 14 +- .../Treeview/MTreeviewTests.cs | 54 +- .../Windows/MWindowItemTests.cs | 18 +- 44 files changed, 477 insertions(+), 1839 deletions(-) delete mode 100644 test/Masa.Blazor.Test/Autocomplete/MAutocompleteTests.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f4a0b494fc..14de3f7426 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,3 +33,5 @@ jobs: run: dotnet workload list - name: build run: dotnet build Masa.Blazor.sln + - name: test + run: dotnet test test/Masa.Blazor.Test/Masa.Blazor.Test.csproj diff --git a/src/Masa.Blazor/Components/App/MApp.razor.cs b/src/Masa.Blazor/Components/App/MApp.razor.cs index b04bd40477..7154da454c 100644 --- a/src/Masa.Blazor/Components/App/MApp.razor.cs +++ b/src/Masa.Blazor/Components/App/MApp.razor.cs @@ -1,5 +1,3 @@ -using Masa.Blazor.Popup; - namespace Masa.Blazor; /// diff --git a/src/Masa.Blazor/Components/Button/MButton.razor.cs b/src/Masa.Blazor/Components/Button/MButton.razor.cs index 76010715db..72458cbd55 100644 --- a/src/Masa.Blazor/Components/Button/MButton.razor.cs +++ b/src/Masa.Blazor/Components/Button/MButton.razor.cs @@ -38,8 +38,6 @@ public MButton() : base(GroupType.ButtonGroup, "button") [Parameter] public bool Rounded { get; set; } - [Parameter] public bool Shaped { get; set; } - [Parameter] public bool Small { get; set; } [Parameter] public bool Text { get; set; } diff --git a/src/Masa.Blazor/Components/List/MList.razor.cs b/src/Masa.Blazor/Components/List/MList.razor.cs index 6397015ead..cbcb79bfe4 100644 --- a/src/Masa.Blazor/Components/List/MList.razor.cs +++ b/src/Masa.Blazor/Components/List/MList.razor.cs @@ -190,6 +190,7 @@ protected override void OnParametersSet() protected override IEnumerable BuildComponentClass() { yield return _sheetModifierBuilder + .Add(Outlined) .Add(Shaped) .AddTheme(IsDark, IndependentTheme) .AddElevation(Elevation) diff --git a/src/Masa.Blazor/Core/MasaComponentBase.cs b/src/Masa.Blazor/Core/MasaComponentBase.cs index 3d5d8f33cd..ee88d43433 100644 --- a/src/Masa.Blazor/Core/MasaComponentBase.cs +++ b/src/Masa.Blazor/Core/MasaComponentBase.cs @@ -97,9 +97,12 @@ public ForwardRef RefBack { continue; } - + stringBuilder.Append(item); - stringBuilder.Append("; "); + if (!item.EndsWith(';')) + { + stringBuilder.Append(';'); + } } if (!NoStyle) diff --git a/src/Masa.Blazor/Services/Application.cs b/src/Masa.Blazor/Services/Application.cs index 165fb6b7cd..173ed0bd8e 100644 --- a/src/Masa.Blazor/Services/Application.cs +++ b/src/Masa.Blazor/Services/Application.cs @@ -1,4 +1,7 @@ -using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.ComponentModel; + +[assembly:InternalsVisibleTo("Masa.Blazor.Test")] namespace Masa.Blazor { diff --git a/test/Masa.Blazor.Test/Alert/MAlertTests.cs b/test/Masa.Blazor.Test/Alert/MAlertTests.cs index 1eda782a7e..a0a23078e9 100644 --- a/test/Masa.Blazor.Test/Alert/MAlertTests.cs +++ b/test/Masa.Blazor.Test/Alert/MAlertTests.cs @@ -4,33 +4,28 @@ namespace Masa.Blazor.Test.Alert { [TestClass] - public class MAlertTests : TestBase + public class MAlertTests : TestBase { [TestMethod] - public void RenderAlertWithColoredBorder() + public void Border() { - //Act - var cut = RenderComponent(props => + var cut = Render(props => { - props.Add(alert => alert.ColoredBorder, true); + props.Add(alert => alert.Border, Borders.Left); }); - var classes = cut.Instance.GetClass(); - var hasColoredBorderClass = classes.Contains("m-alert"); - // Assert - Assert.IsTrue(hasColoredBorderClass); + cut.Find(".m-alert__border"); } [TestMethod] public void RenderAlertWithDense() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Dense, true); }); - var classes = cut.Instance.GetClass(); - var hasDenseClass = classes.Contains("m-alert--dense"); + var hasDenseClass = cut.ClassList.Contains("m-alert--dense"); // Assert Assert.IsTrue(hasDenseClass); @@ -40,12 +35,11 @@ public void RenderAlertWithDense() public void RenderAlertWithDark() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Dark, true); }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("theme--dark"); + var hasDarkClass = cut.ClassList.Contains("theme--dark"); // Assert Assert.IsTrue(hasDarkClass); @@ -55,27 +49,23 @@ public void RenderAlertWithDark() public void RenderAlertWithDismissible() { //Act - var cut = RenderComponent(props => + var cut = Render(props => { props.Add(alert => alert.Dismissible, true); }); - var classes = cut.Instance.GetClass(); - var hasDismissibleClass = classes.Contains("m-alert"); - // Assert - Assert.IsTrue(hasDismissibleClass); + cut.Find(".m-alert__dismissible"); } [TestMethod] public void RenderAlertWithElevation() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Elevation, 2); }); - var classes = cut.Instance.GetClass(); - var hasElevationClass = classes.Contains("elevation-2"); + var hasElevationClass = cut.ClassList.Contains("elevation-2"); // Assert Assert.IsTrue(hasElevationClass); @@ -85,27 +75,25 @@ public void RenderAlertWithElevation() public void RenderWithHeight() { // Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(p => p.Height, 100); }); - var inputSlotDiv = cut.Find(".m-alert"); - var style = inputSlotDiv.GetAttribute("style"); + var style = cut.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] public void RenderAlertWithIcon() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Icon, true); }); - var classes = cut.Instance.GetClass(); - var hasIconClass = classes.Contains("m-alert"); + var hasIconClass = cut.ClassList.Contains("m-alert"); // Assert Assert.IsTrue(hasIconClass); @@ -115,12 +103,11 @@ public void RenderAlertWithIcon() public void RenderAlertWithWithLight() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Light, true); }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("theme--light"); + var hasLightClass = cut.ClassList.Contains("theme--light"); // Assert Assert.IsTrue(hasLightClass); @@ -130,72 +117,67 @@ public void RenderAlertWithWithLight() public void RenderWithMaxHeight() { // Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(p => p.MaxHeight, 100); }); - var inputSlotDiv = cut.Find(".m-alert"); - var style = inputSlotDiv.GetAttribute("style"); + var style = cut.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] public void RenderWithMaxWidth() { // Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(p => p.MaxWidth, 100); }); - var inputSlotDiv = cut.Find(".m-alert"); - var style = inputSlotDiv.GetAttribute("style"); + var style = cut.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] public void RenderWithMinWidth() { // Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(p => p.MinWidth, 100); }); - var inputSlotDiv = cut.Find(".m-alert"); - var style = inputSlotDiv.GetAttribute("style"); + var style = cut.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] public void RenderWithMinHeight() { // Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(p => p.MinHeight, 100); }); - var inputSlotDiv = cut.Find(".m-alert"); - var style = inputSlotDiv.GetAttribute("style"); + var style = cut.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] public void RenderAlertWithOutlined() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Outlined, true); }); - var classes = cut.Instance.GetClass(); - var hasOutlinedClass = classes.Contains("m-alert--outlined"); + var hasOutlinedClass = cut.ClassList.Contains("m-alert--outlined"); // Assert Assert.IsTrue(hasOutlinedClass); @@ -205,12 +187,11 @@ public void RenderAlertWithOutlined() public void RenderAlertWithProminent() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Prominent, true); }); - var classes = cut.Instance.GetClass(); - var hasProminentClass = classes.Contains("m-alert--prominent"); + var hasProminentClass = cut.ClassList.Contains("m-alert--prominent"); // Assert Assert.IsTrue(hasProminentClass); @@ -220,12 +201,11 @@ public void RenderAlertWithProminent() public void RenderAlertWithRounded() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Rounded, true); }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("rounded"); + var hasRoundedClass = cut.ClassList.Contains("rounded"); // Assert Assert.IsTrue(hasRoundedClass); @@ -235,12 +215,11 @@ public void RenderAlertWithRounded() public void RenderAlertWithShaped() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Shaped, true); }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-sheet--shaped"); + var hasShapedClass = cut.ClassList.Contains("m-sheet--shaped"); // Assert Assert.IsTrue(hasShapedClass); @@ -250,12 +229,11 @@ public void RenderAlertWithShaped() public void RenderAlertWithText() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Text, true); }); - var classes = cut.Instance.GetClass(); - var hasTextClass = classes.Contains("m-alert--text"); + var hasTextClass = cut.ClassList.Contains("m-alert--text"); // Assert Assert.IsTrue(hasTextClass); @@ -265,12 +243,11 @@ public void RenderAlertWithText() public void RenderAlertWithTile() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Tile, true); }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("rounded"); + var hasRoundedClass = cut.ClassList.Contains("rounded-0"); // Assert Assert.IsTrue(hasRoundedClass); @@ -280,12 +257,11 @@ public void RenderAlertWithTile() public void RenderAlertWithValue() { //Act - var cut = RenderComponent(props => + var cut = RenderAndGetRootElement(props => { props.Add(alert => alert.Value, true); }); - var classes = cut.Instance.GetClass(); - var hasValueClass = classes.Contains("m-alert"); + var hasValueClass = cut.ClassList.Contains("m-alert"); // Assert Assert.IsTrue(hasValueClass); @@ -295,7 +271,7 @@ public void RenderAlertWithValue() public void RenderWithChildContent() { // Arrange & Act - var cut = RenderComponent(props => + var cut = Render(props => { props.Add(alert => alert.ChildContent, "Hello world"); }); diff --git a/test/Masa.Blazor.Test/App/MAppTests.cs b/test/Masa.Blazor.Test/App/MAppTests.cs index 63ca4f5868..665ae87095 100644 --- a/test/Masa.Blazor.Test/App/MAppTests.cs +++ b/test/Masa.Blazor.Test/App/MAppTests.cs @@ -1,4 +1,5 @@ -using Bunit; +using System.Linq; +using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.App @@ -7,19 +8,41 @@ namespace Masa.Blazor.Test.App public class MAppTests : TestBase { [TestMethod] - public void RenderWithChildContentt() + public void Structure() + { + var cut = RenderComponent(); + var app = cut.Find(".m-application.m-application--is-ltr.theme--light"); + Assert.IsTrue(app.FirstElementChild.ClassList.Contains("m-application__wrap")); + } + + [TestMethod] + public void ChildContent() { - // Arrange & Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent(props => { props.Add(app => app.ChildContent, "Hello world"); }); - var contentDiv = cut.Find(".m-application--wrap"); - // Assert - contentDiv.Children.MarkupMatches("Hello world"); + var wrap = cut.Find(".m-application__wrap"); + wrap.Children.MarkupMatches("Hello world"); } - } -} + [TestMethod] + public void ToggleTheme() + { + var masaBlazor = Services.GetService(); + masaBlazor.ToggleTheme(); + var cut = RenderComponent(); + cut.Find(".m-application.theme--dark"); + } + + [TestMethod] + public void Rtl() + { + var masaBlazor = Services.GetService(); + masaBlazor.RTL = true; + var cut = RenderComponent(); + cut.Find(".m-application.m-application--is-rtl"); + } + } +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/App/MMainTests.cs b/test/Masa.Blazor.Test/App/MMainTests.cs index c0f9199e79..6756b4cb0d 100644 --- a/test/Masa.Blazor.Test/App/MMainTests.cs +++ b/test/Masa.Blazor.Test/App/MMainTests.cs @@ -1,20 +1,45 @@ -using Bunit; +using AngleSharp.Css.Dom; +using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.Main { [TestClass] - public class MMainTests : TestBase + public class MMainTests : TestBase { [TestMethod] - public void RenderMain() + public void Structure() { - //Act - var cut = RenderComponent(); - var main = cut.Find("main"); + var cut = Render(); + var root = cut.Find(".m-main"); + Assert.IsTrue(root.FirstElementChild.ClassList.Contains("m-main__wrap")); + } + + [TestMethod] + public void ChildContent() + { + var cut = Render(props => { props.Add(u => u.ChildContent, "Hello world"); }); + + var wrap = cut.Find(".m-main__wrap"); + wrap.Children.MarkupMatches("Hello world"); + } + + [TestMethod] + public void Application() + { + // assume application position was set by JSInterop + var masaBlazor = Services.GetService(); + masaBlazor.Application.Bar = 64; + masaBlazor.Application.Footer = 128; + masaBlazor.Application.Right = 256; + masaBlazor.Application.Left = 256; - // Assert - Assert.IsNotNull(main); + var cut = Render(); + var styles = cut.Find(".m-main").GetStyle(); + Assert.AreEqual("64px", styles["padding-top"]); + Assert.AreEqual("256px", styles["padding-left"]); + Assert.AreEqual("256px", styles["padding-right"]); + Assert.AreEqual("128px", styles["padding-bottom"]); } } -} +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/AppBar/MAppBarTests.cs b/test/Masa.Blazor.Test/AppBar/MAppBarTests.cs index b62f8a9d12..f940adf3b1 100644 --- a/test/Masa.Blazor.Test/AppBar/MAppBarTests.cs +++ b/test/Masa.Blazor.Test/AppBar/MAppBarTests.cs @@ -1,22 +1,22 @@ -using Bunit; +using AngleSharp.Css.Dom; +using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.AppBar { [TestClass] - public class MAppBarTests : TestBase + public class MAppBarTests : TestBase { + public MAppBarTests() : base("header") + { + } + [TestMethod] public void RenderAppBarWithAbsolute() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Absolute, true); - }); - var classes = cut.Instance.GetClass(); - var hasAbsoluteClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Absolute, true); }); + var hasAbsoluteClass = cut.ClassList.Contains("m-toolbar--absolute"); // Assert Assert.IsTrue(hasAbsoluteClass); @@ -26,13 +26,8 @@ public void RenderAppBarWithAbsolute() public void RenderAppBarWithApp() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.App, true); - }); - var classes = cut.Instance.GetClass(); - var hasAppClass = classes.Contains("m-app-bar--fixed"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.App, true); }); + var hasAppClass = cut.ClassList.Contains("m-app-bar--app"); // Assert Assert.IsTrue(hasAppClass); @@ -42,13 +37,9 @@ public void RenderAppBarWithApp() public void RenderAppBarWithBottom() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Bottom, true); - }); - var classes = cut.Instance.GetClass(); - var hasBottomClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Bottom, true); }); + + var hasBottomClass = cut.ClassList.Contains("m-toolbar--bottom"); // Assert Assert.IsTrue(hasBottomClass); @@ -58,109 +49,54 @@ public void RenderAppBarWithBottom() public void RenderAppBarWithClippedRight() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ClippedRight, true); - }); - var classes = cut.Instance.GetClass(); - var hasClippedRightClass = classes.Contains("m-app-bar--clipped"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.ClippedRight, true); }); + var hasClippedClass = cut.ClassList.Contains("m-app-bar--clipped"); + var hasClippedRightClass = cut.ClassList.Contains("m-app-bar--clipped-right"); // Assert - Assert.IsTrue(hasClippedRightClass); + Assert.IsTrue(hasClippedClass && hasClippedRightClass); } [TestMethod] public void RenderAppBarWithClippedLeft() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ClippedLeft, true); - }); - var classes = cut.Instance.GetClass(); - var hasClippedLeftClass = classes.Contains("m-app-bar--clipped"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.ClippedLeft, true); }); + var hasClippedClass = cut.ClassList.Contains("m-app-bar--clipped"); + var hasClippedLeftClass = cut.ClassList.Contains("m-app-bar--clipped-left"); // Assert - Assert.IsTrue(hasClippedLeftClass); + Assert.IsTrue(hasClippedClass && hasClippedLeftClass); } [TestMethod] public void RenderAppBarWithCollapse() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Collapse, true); - }); - var classes = cut.Instance.GetClass(); - var hasClippedLeftClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Collapse, true); }); + var hasClippedLeftClass = cut.ClassList.Contains("m-toolbar--collapse"); // Assert Assert.IsTrue(hasClippedLeftClass); } - [TestMethod] - public void RenderAppBarWithCollapseOnScroll() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.CollapseOnScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasScrollClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasScrollClass); - } - [TestMethod] public void RenderAppBarWithDense() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Dense, true); - }); - var classes = cut.Instance.GetClass(); - var hasDenseClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Dense, true); }); + var hasDenseClass = cut.ClassList.Contains("m-toolbar--dense"); // Assert Assert.IsTrue(hasDenseClass); } - [TestMethod] - public void RenderAppBarWithDark() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Dark, true); - }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("theme--dark"); - - // Assert - Assert.IsTrue(hasDarkClass); - } - [TestMethod] public void RenderButtonWithScroll() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ElevateOnScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasScrollClass = classes.Contains("m-app-bar--elevate-on-scroll"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.ElevateOnScroll, true); }); + var hasScrollClass = cut.ClassList.Contains("m-app-bar--elevate-on-scroll"); // Assert Assert.IsTrue(hasScrollClass); @@ -170,13 +106,8 @@ public void RenderButtonWithScroll() public void RenderAppBarWithElevation() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Elevation, 2); - }); - var classes = cut.Instance.GetClass(); - var hasElevationClass = classes.Contains("elevation-2"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Elevation, 2); }); + var hasElevationClass = cut.ClassList.Contains("elevation-2"); // Assert Assert.IsTrue(hasElevationClass); @@ -186,13 +117,8 @@ public void RenderAppBarWithElevation() public void RenderButtonWithExtended() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Extended, true); - }); - var classes = cut.Instance.GetClass(); - var hasScrollClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Extended, true); }); + var hasScrollClass = cut.ClassList.Contains("m-toolbar--extended"); // Assert Assert.IsTrue(hasScrollClass); @@ -202,29 +128,23 @@ public void RenderButtonWithExtended() public void RenderAppBarWithExtensionHeight() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => + var cut = Render(props => { - props.Add(appbar => appbar.ExtensionHeight, 48); + props.Add(appbar => appbar.Extended, true); + props.Add(appbar => appbar.ExtensionHeight, 52); }); - var classes = cut.Instance.GetClass(); - var hasElevationClass = classes.Contains("m-app-bar"); // Assert - Assert.IsTrue(hasElevationClass); + var extension = cut.Find(".m-toolbar__extension"); + Assert.AreEqual("52px", extension.GetStyle()["height"]); } [TestMethod] public void RenderAppBarWithFadeImgOnScroll() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.FadeImgOnScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasFadeImgOnScrollClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.FadeImgOnScroll, true); }); + var hasFadeImgOnScrollClass = cut.ClassList.Contains("m-app-bar--fade-img-on-scroll"); // Assert Assert.IsTrue(hasFadeImgOnScrollClass); @@ -234,13 +154,8 @@ public void RenderAppBarWithFadeImgOnScroll() public void RenderAppBarWithFixed() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Fixed, true); - }); - var classes = cut.Instance.GetClass(); - var hasFixedClass = classes.Contains("m-app-bar--fixed"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Fixed, true); }); + var hasFixedClass = cut.ClassList.Contains("m-app-bar--fixed"); // Assert Assert.IsTrue(hasFixedClass); @@ -250,13 +165,8 @@ public void RenderAppBarWithFixed() public void RenderAppBarWithFlat() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Flat, true); - }); - var classes = cut.Instance.GetClass(); - var hasFlatClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Flat, true); }); + var hasFlatClass = cut.ClassList.Contains("m-toolbar--flat"); // Assert Assert.IsTrue(hasFlatClass); @@ -266,13 +176,8 @@ public void RenderAppBarWithFlat() public void RenderAppBarWithFloating() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Floating, true); - }); - var classes = cut.Instance.GetClass(); - var hasFloatingClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Floating, true); }); + var hasFloatingClass = cut.ClassList.Contains("m-toolbar--floating"); // Assert Assert.IsTrue(hasFloatingClass); @@ -282,141 +187,80 @@ public void RenderAppBarWithFloating() public void RenderWithHeight() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.Height, 100); - }); + var cut = Render(props => { props.Add(p => p.Height, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] public void RenderWithWidth() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.Width, 100); - }); + var cut = Render(props => { props.Add(p => p.Width, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); + Assert.AreEqual("height: 64px;", style); } [TestMethod] public void RenderWithMinHeight() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.MinHeight, 100); - }); + var cut = Render(props => { props.Add(p => p.MinHeight, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); + Assert.AreEqual("height: 64px;", style); } [TestMethod] public void RenderWithMinWidth() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.MinWidth, 100); - }); + var cut = Render(props => { props.Add(p => p.MinWidth, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); + Assert.AreEqual("height: 64px;", style); } [TestMethod] public void RenderWithMaxHeight() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.MaxHeight, 100); - }); + var cut = Render(props => { props.Add(p => p.MaxHeight, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); + Assert.AreEqual("height: 64px;", style); } [TestMethod] public void RenderWithMaxWidth() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.MaxWidth, 100); - }); + var cut = Render(props => { props.Add(p => p.MaxWidth, 100); }); var inputSlotDiv = cut.Find(".m-toolbar__content"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); - } - - [TestMethod] - public void RenderAppBarWithHideOnScroll() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.HideOnScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasHideOnScrollClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasHideOnScrollClass); - } - - [TestMethod] - public void RenderAppBarWithInvertedScroll() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.InvertedScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasInvertedScrollClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasInvertedScrollClass); + Assert.AreEqual("height: 64px;", style); } [TestMethod] public void RenderAppBarWithLight() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Light, true); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("theme--light"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Light, true); }); + var hasLightClass = cut.ClassList.Contains("theme--light"); // Assert Assert.IsTrue(hasLightClass); @@ -426,13 +270,8 @@ public void RenderAppBarWithLight() public void RenderAppBarWithOutlined() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Outlined, true); - }); - var classes = cut.Instance.GetClass(); - var hasOutlinedClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Outlined, true); }); + var hasOutlinedClass = cut.ClassList.Contains("m-sheet--outlined"); // Assert Assert.IsTrue(hasOutlinedClass); @@ -442,93 +281,31 @@ public void RenderAppBarWithOutlined() public void RenderAppBarWithProminent() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Prominent, true); - }); - var classes = cut.Instance.GetClass(); - var hasProminentClass = classes.Contains("m-app-bar"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Prominent, true); }); + var hasProminentClass = cut.ClassList.Contains("m-toolbar--prominent"); // Assert Assert.IsTrue(hasProminentClass); } - [TestMethod] - public void RenderAppBarWithRounded() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Rounded, true); - }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasRoundedClass); - } - - [TestMethod] - public void RenderAppBarWithScrollOffScreen() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ScrollOffScreen, true); - }); - var classes = cut.Instance.GetClass(); - var hasScrollOffScreenClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasScrollOffScreenClass); - } - [TestMethod] public void RenderWithScrollThreshold() { // Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(p => p.ScrollThreshold, 0); - }); + var cut = Render(props => { props.Add(p => p.ScrollThreshold, 0); }); var inputSlotDiv = cut.Find(".m-app-bar"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px;margin-top:0px;transform:translateY(0px);left:0px;right:0px", style); - } - - [TestMethod] - public void RenderAppBarWithShaped() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Shaped, true); - }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasShapedClass); + Assert.AreEqual("height: 64px;transform: translateY(0px);margin-top: 0px;left: 0px;right: 0px;", style); } [TestMethod] public void RenderButtonWithShrinkOnScroll() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ShrinkOnScroll, true); - }); - var classes = cut.Instance.GetClass(); - var hasScrollClass = classes.Contains("m-app-bar--shrink-on-scroll"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.ShrinkOnScroll, true); }); + var hasScrollClass = cut.ClassList.Contains("m-app-bar--shrink-on-scroll"); // Assert Assert.IsTrue(hasScrollClass); @@ -538,47 +315,22 @@ public void RenderButtonWithShrinkOnScroll() public void RenderAppBarWithTile() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Tile, true); - }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("rounded"); + var cut = RenderAndGetRootElement(props => { props.Add(appbar => appbar.Tile, true); }); + var hasRoundedClass = cut.ClassList.Contains("rounded-0"); // Assert Assert.IsTrue(hasRoundedClass); } - [TestMethod] - public void RenderAppBarWithValue() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.Value, true); - }); - var classes = cut.Instance.GetClass(); - var hasValueClass = classes.Contains("m-app-bar"); - - // Assert - Assert.IsTrue(hasValueClass); - } - [TestMethod] public void RenderWithChildContent() { // Arrange & Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(appbar => appbar.ChildContent, "Hello world"); - }); + var cut = Render(props => { props.Add(appbar => appbar.ChildContent, "Hello world"); }); var contentDiv = cut.Find(".m-toolbar__content"); // Assert contentDiv.Children.MarkupMatches("Hello world"); } } -} +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/Aspect ratios/MResponsiveTests.cs b/test/Masa.Blazor.Test/Aspect ratios/MResponsiveTests.cs index 71c7c6f019..de1b274e21 100644 --- a/test/Masa.Blazor.Test/Aspect ratios/MResponsiveTests.cs +++ b/test/Masa.Blazor.Test/Aspect ratios/MResponsiveTests.cs @@ -32,7 +32,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -47,7 +47,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] @@ -62,7 +62,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -77,7 +77,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -92,7 +92,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -107,7 +107,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } } } diff --git a/test/Masa.Blazor.Test/Autocomplete/MAutocompleteTests.cs b/test/Masa.Blazor.Test/Autocomplete/MAutocompleteTests.cs deleted file mode 100644 index 1b9bf63191..0000000000 --- a/test/Masa.Blazor.Test/Autocomplete/MAutocompleteTests.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Bunit; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Masa.Blazor.Test.Autocomplete -{ - [TestClass] - public class MAutocompleteTests:TestBase - { - //[TestMethod] - //public void RenderAppBarWithClippedRight() - //{ - // //Act - // var cut = RenderComponent>(props => - // { - // props.Add(appbar => appbar.Interval, 500); - // props.Add(select => select.ItemText, item => item); - // props.Add(select => select.ItemValue, item => item); - // }); - // var classes = cut.Instance.CssProvider.GetClass(); - // var hasClippedRightClass = classes.Contains("m-input"); - - // // Assert - // Assert.IsTrue(hasClippedRightClass); - //} - } -} diff --git a/test/Masa.Blazor.Test/Autocompletes/MAutocompleteTests.cs b/test/Masa.Blazor.Test/Autocompletes/MAutocompleteTests.cs index 352b145015..4d9c27ce07 100644 --- a/test/Masa.Blazor.Test/Autocompletes/MAutocompleteTests.cs +++ b/test/Masa.Blazor.Test/Autocompletes/MAutocompleteTests.cs @@ -1,4 +1,7 @@ -using Bunit; +using System; +using System.Collections.Generic; +using AngleSharp.Dom; +using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.Autocompletes @@ -6,37 +9,42 @@ namespace Masa.Blazor.Test.Autocompletes [TestClass] public class MAutocompleteTests : TestBase { - [TestMethod] - public void RenderAutocompleteWithAutofocus() + private record Model(string Name, string Value); + + private IRenderedComponent> Render( + Action>> parameterBuilder = null) { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Autofocus, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasAutofocusClass = classes.Contains("m-autocomplete"); + return RenderComponent>(props => + { + props.Add(a => a.Value, "Value1"); + props.Add(a => a.Items, new List() + { + new Model("Name1", "Value1"), + new Model("Name2", "Value2"), + new Model("Name3", "Value3"), + }); + props.Add(a => a.ItemText, item => item.Name); + props.Add(a => a.ItemValue, item => item.Value); + parameterBuilder?.Invoke(props); + }); + } - // Assert - Assert.IsTrue(hasAutofocusClass); + private IElement RenderAndGetRootElement( + Action>> parameterBuilder = null, + string tag = "div") + { + return Render(parameterBuilder).Find(tag); } [TestMethod] public void RenderAutocompleteWithChips() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => + var cut = RenderAndGetRootElement(props => { props.Add(autocomplete => autocomplete.Chips, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); }); - var classes = cut.Instance.GetClass(); - var hasChipsClass = classes.Contains("m-autocomplete"); + var hasChipsClass = cut.ClassList.Contains("m-select--chips"); // Assert Assert.IsTrue(hasChipsClass); @@ -46,522 +54,54 @@ public void RenderAutocompleteWithChips() public void RenderAutocompleteWithClearable() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => + var cut = Render(props => { props.Add(autocomplete => autocomplete.Clearable, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasClearableClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasClearableClass); - } - - [TestMethod] - public void RenderAutocompleteWithCounter() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Counter, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); }); - var classes = cut.Instance.GetClass(); - var hasCounterClass = classes.Contains("m-autocomplete"); - // Assert - Assert.IsTrue(hasCounterClass); - } + cut.Render(); - [TestMethod] - public void RenderAutocompleteWithDark() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Dark, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasDarkClass); + cut.Find(".m-input__icon--clear"); } [TestMethod] public void RenderAutocompleteWithDeletableChips() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.DeletableChips, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasDeletableChipsClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasDeletableChipsClass); - } - - [TestMethod] - public void RenderAutocompleteWithDense() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Dense, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasDenseClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasDenseClass); - } - - [TestMethod] - public void RenderAutocompleteWithDisabled() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Disabled, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasDisabledClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasDisabledClass); - } - - [TestMethod] - public void RenderAutocompleteWithError() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Error, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasErrorClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasErrorClass); - } - - [TestMethod] - public void RenderAutocompleteWithFilled() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Filled, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasFilledClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasFilledClass); - } - - [TestMethod] - public void RenderAutocompleteWithFlat() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Flat, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasFlatClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasFlatClass); - } - - [TestMethod] - public void RenderAutocompleteWithFullWidth() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => + var cut = Render(props => { - props.Add(autocomplete => autocomplete.FullWidth, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); + props.Add(a => a.Chips, true); + props.Add(a => a.DeletableChips, true); }); - var classes = cut.Instance.GetClass(); - var hasFullWidthClass = classes.Contains("m-autocomplete"); - // Assert - Assert.IsTrue(hasFullWidthClass); - } - - [TestMethod] - public void RenderWithHeight() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Height, 100); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasHeightClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasHeightClass); - } - - [TestMethod] - public void RenderAutocompleteWithHideDetails() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.HideDetails, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasHideDetailsClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasHideDetailsClass); - } - - [TestMethod] - public void RenderAutocompleteWithLight() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Light, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasLightClass); - } - - [TestMethod] - public void RenderAutocompleteWithLoaderHeight() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.LoaderHeight, 2); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasLoaderHeightClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasLoaderHeightClass); - } - - [TestMethod] - public void RenderAutocompleteWithLoading() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Loading, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasLoadingClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasLoadingClass); + cut.Find(".m-chip__close"); } [TestMethod] public void RenderAutocompleteWithMultiple() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => + var cut = RenderAndGetRootElement(props => { props.Add(autocomplete => autocomplete.Multiple, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasMultipleClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasMultipleClass); - } - - [TestMethod] - public void RenderAutocompleteWithOutlined() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Outlined, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); }); - var classes = cut.Instance.GetClass(); - var hasOutlinedClass = classes.Contains("m-autocomplete"); // Assert - Assert.IsTrue(hasOutlinedClass); - } - - [TestMethod] - public void RenderAutocompleteWithPersistentHint() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.PersistentHint, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasPersistentHintClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasPersistentHintClass); - } - - [TestMethod] - public void RenderAutocompleteWithPersistentPlaceholder() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.PersistentPlaceholder, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasPersistentPlaceholderClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasPersistentPlaceholderClass); - } - - [TestMethod] - public void RenderAutocompleteWithReadonly() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Readonly, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasReadonlyClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasReadonlyClass); - } - - [TestMethod] - public void RenderAutocompleteWithReverse() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Reverse, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasReverseClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasReverseClass); - } - - [TestMethod] - public void RenderAutocompleteWithRounded() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Rounded, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasRoundedClass); - } - - [TestMethod] - public void RenderAutocompleteWithShaped() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Shaped, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasShapedClass); - } - - [TestMethod] - public void RenderAutocompleteWithSingleLine() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.SingleLine, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasSingleLineClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasSingleLineClass); + Assert.IsTrue(cut.ClassList.Contains("m-select--is-multi")); } [TestMethod] public void RenderAutocompleteWithSmallChips() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.SmallChips, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasSmallChipsClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasSmallChipsClass); - } - - [TestMethod] - public void RenderAutocompleteWithSolo() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => + var cut = Render(props => { - props.Add(autocomplete => autocomplete.Solo, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); + props.Add(a => a.Chips, true); + props.Add(a => a.SmallChips, true); }); - var classes = cut.Instance.GetClass(); - var hasSoloClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasSoloClass); - } - - [TestMethod] - public void RenderAutocompleteWithSoloInverted() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.SoloInverted, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasSoloInvertedClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasSoloInvertedClass); - } - - [TestMethod] - public void RenderAutocompleteWithSuccess() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.Success, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasSuccessClass = classes.Contains("m-autocomplete"); - - // Assert - Assert.IsTrue(hasSuccessClass); - } - - [TestMethod] - public void RenderAutocompleteWithValidateOnBlur() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent>(props => - { - props.Add(autocomplete => autocomplete.ValidateOnBlur, true); - props.Add(autocomplete => autocomplete.ItemText, item => item); - props.Add(autocomplete => autocomplete.ItemValue, item => item); - }); - var classes = cut.Instance.GetClass(); - var hasValidateOnBlurClass = classes.Contains("m-autocomplete"); - + // Assert - Assert.IsTrue(hasValidateOnBlurClass); + cut.Find(".m-chip.m-size--small"); } } -} +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/Avatar/MAvatarTest.cs b/test/Masa.Blazor.Test/Avatar/MAvatarTest.cs index 5b7ca83a18..5ad40b477d 100644 --- a/test/Masa.Blazor.Test/Avatar/MAvatarTest.cs +++ b/test/Masa.Blazor.Test/Avatar/MAvatarTest.cs @@ -62,7 +62,7 @@ public void RenderWithSize() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px", style); + Assert.AreEqual("height: 48px !important;min-width: 48px !important;width: 48px !important;", style); } [TestMethod] @@ -92,7 +92,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;height: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;height: 48px !important;", style); } [TestMethod] @@ -107,7 +107,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;width: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;width: 48px !important;", style); } [TestMethod] @@ -122,7 +122,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-height: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-height: 48px !important;", style); } [TestMethod] @@ -137,7 +137,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-width: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-width: 48px !important;", style); } [TestMethod] @@ -152,7 +152,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-height: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-height: 48px !important;", style); } [TestMethod] @@ -167,7 +167,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-width: 48px", style); + Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-width: 48px !important;", style); } } } diff --git a/test/Masa.Blazor.Test/Badge/MBadgeTests.cs b/test/Masa.Blazor.Test/Badge/MBadgeTests.cs index ce06a48617..7b4c2cbc7e 100644 --- a/test/Masa.Blazor.Test/Badge/MBadgeTests.cs +++ b/test/Masa.Blazor.Test/Badge/MBadgeTests.cs @@ -81,21 +81,6 @@ public void RenderBadgeWithDark() Assert.IsTrue(hasdarkClass); } - [TestMethod] - public void RenderBadgeWithContent() - { - //Act - var cut = RenderComponent(props => - { - props.Add(badge => badge.Content, 6); - }); - var classes = cut.Instance.GetClass(); - var hasContentClass = classes.Contains("m-badge"); - - // Assert - Assert.IsTrue(hasContentClass); - } - [TestMethod] public void RenderBadgeWithInLine() { @@ -171,36 +156,6 @@ public void RenderBadgeWithTile() Assert.IsTrue(hasTileClass); } - [TestMethod] - public void RenderBadgeWithOffsetX() - { - //Act - var cut = RenderComponent(props => - { - props.Add(badge => badge.OffsetX, 10); - }); - var classes = cut.Instance.GetClass(); - var hasOffsetXClass = classes.Contains("m-badge"); - - // Assert - Assert.IsTrue(hasOffsetXClass); - } - - [TestMethod] - public void RenderBadgeWithOffsetY() - { - //Act - var cut = RenderComponent(props => - { - props.Add(badge => badge.OffsetY, 10); - }); - var classes = cut.Instance.GetClass(); - var hasOffsetYClass = classes.Contains("m-badge"); - - // Assert - Assert.IsTrue(hasOffsetYClass); - } - [TestMethod] public void RenderWithBadgeContent() { diff --git a/test/Masa.Blazor.Test/Banner/MBannerTests.cs b/test/Masa.Blazor.Test/Banner/MBannerTests.cs index 1a4f069d0e..32176d77dc 100644 --- a/test/Masa.Blazor.Test/Banner/MBannerTests.cs +++ b/test/Masa.Blazor.Test/Banner/MBannerTests.cs @@ -21,21 +21,6 @@ public void RenderButtonWithSingleLine() Assert.IsTrue(hasSingleLineClass); } - [TestMethod] - public void RenderButtonNoWithSingleLine() - { - //Act - var cut = RenderComponent(props => - { - props.Add(banner => banner.SingleLine, false); - }); - var classes = cut.Instance.GetClass(); - var hasSingleLineClass = classes.Contains("m-banner"); - - // Assert - Assert.IsTrue(hasSingleLineClass); - } - [TestMethod] public void RenderButtonWithApp() { @@ -51,21 +36,6 @@ public void RenderButtonWithApp() Assert.IsTrue(hasAppClass); } - [TestMethod] - public void RenderButtonNoWithApp() - { - //Act - var cut = RenderComponent(props => - { - props.Add(banner => banner.App, false); - }); - var classes = cut.Instance.GetClass(); - var hasAppClass = classes.Contains("m-banner"); - - // Assert - Assert.IsTrue(hasAppClass); - } - [TestMethod] public void RenderButtonWithSticky() { @@ -81,21 +51,6 @@ public void RenderButtonWithSticky() Assert.IsTrue(hasStickyClass); } - [TestMethod] - public void RenderButtonNoWithSticky() - { - //Act - var cut = RenderComponent(props => - { - props.Add(banner => banner.Sticky, false); - }); - var classes = cut.Instance.GetClass(); - var hasStickyClass = classes.Contains("m-banner"); - - // Assert - Assert.IsTrue(hasStickyClass); - } - [TestMethod] public void RenderButtonWithDark() { @@ -111,21 +66,6 @@ public void RenderButtonWithDark() Assert.IsTrue(hasdarkClass); } - [TestMethod] - public void RenderButtonNoWithDark() - { - //Act - var cut = RenderComponent(props => - { - props.Add(banner => banner.Dark, false); - }); - var classes = cut.Instance.GetClass(); - var hasdarkClass = classes.Contains("m-banner"); - - // Assert - Assert.IsTrue(hasdarkClass); - } - [TestMethod] public void RenderButtonWithLight() { @@ -141,21 +81,6 @@ public void RenderButtonWithLight() Assert.IsTrue(hasLightClass); } - [TestMethod] - public void RenderButtonNoWithLight() - { - //Act - var cut = RenderComponent(props => - { - props.Add(banner => banner.Light, false); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("m-banner"); - - // Assert - Assert.IsTrue(hasLightClass); - } - [TestMethod] public void RenderButtonWithValue() { diff --git a/test/Masa.Blazor.Test/Button/MButtonGroupTests.cs b/test/Masa.Blazor.Test/Button/MButtonGroupTests.cs index 9b01f9dddb..248b643340 100644 --- a/test/Masa.Blazor.Test/Button/MButtonGroupTests.cs +++ b/test/Masa.Blazor.Test/Button/MButtonGroupTests.cs @@ -6,21 +6,6 @@ namespace Masa.Blazor.Test.Button [TestClass] public class MButtonGroupTests : TestBase { - [TestMethod] - public void RenderButtonGroupWithBorderless() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Borderless, true); - }); - var classes = cut.Instance.GetClass(); - var hasBorderlessClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasBorderlessClass); - } - [TestMethod] public void RenderButtonGroupWithDark() { @@ -36,36 +21,6 @@ public void RenderButtonGroupWithDark() Assert.IsTrue(hasDarkClass); } - [TestMethod] - public void RenderButtonGroupWithDense() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Dense, true); - }); - var classes = cut.Instance.GetClass(); - var hasDenseClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasDenseClass); - } - - [TestMethod] - public void RenderButtonGroupWithGroup() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Group, true); - }); - var classes = cut.Instance.GetClass(); - var hasGroupClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasGroupClass); - } - [TestMethod] public void RenderButtonGroupWithLight() { @@ -81,81 +36,6 @@ public void RenderButtonGroupWithLight() Assert.IsTrue(hasLightClass); } - [TestMethod] - public void RenderButtonGroupWithMandatory() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Mandatory, true); - }); - var classes = cut.Instance.GetClass(); - var hasMandatoryClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasMandatoryClass); - } - - [TestMethod] - public void RenderButtonGroupWithMultiple() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Multiple, true); - }); - var classes = cut.Instance.GetClass(); - var hasMultipleClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasMultipleClass); - } - - [TestMethod] - public void RenderButtonGroupWithRounded() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Rounded, true); - }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasRoundedClass); - } - - [TestMethod] - public void RenderButtonGroupWithShaped() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Shaped, true); - }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasShapedClass); - } - - [TestMethod] - public void RenderButtonGroupWithTile() - { - //Act - var cut = RenderComponent(props => - { - props.Add(buttongroup => buttongroup.Tile, true); - }); - var classes = cut.Instance.GetClass(); - var hasTileClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasTileClass); - } - [TestMethod] public void RenderWithChildContent() { diff --git a/test/Masa.Blazor.Test/Button/MButtonTests.cs b/test/Masa.Blazor.Test/Button/MButtonTests.cs index 350af0e985..e7419ad7f6 100644 --- a/test/Masa.Blazor.Test/Button/MButtonTests.cs +++ b/test/Masa.Blazor.Test/Button/MButtonTests.cs @@ -10,10 +10,7 @@ public class MButtonTests : TestBase public void RenderButtonWithAbsolute() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Absolute, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Absolute, true); }); var classes = cut.Instance.GetClass(); var hasAbsoluteClass = classes.Contains("m-btn--absolute"); @@ -25,10 +22,7 @@ public void RenderButtonWithAbsolute() public void RenderButtonWithBlock() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Block, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Block, true); }); var classes = cut.Instance.GetClass(); var hasBlockClass = classes.Contains("m-btn--block"); @@ -40,10 +34,7 @@ public void RenderButtonWithBlock() public void RenderButtonWithBottom() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Bottom, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Bottom, true); }); var classes = cut.Instance.GetClass(); var hasBottomClass = classes.Contains("m-btn--bottom"); @@ -55,10 +46,7 @@ public void RenderButtonWithBottom() public void RenderButtonWithDark() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Dark, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Dark, true); }); var classes = cut.Instance.GetClass(); var hasDarkClass = classes.Contains("theme--dark"); @@ -70,10 +58,7 @@ public void RenderButtonWithDark() public void RenderButtonWithDepressed() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Depressed, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Depressed, true); }); var classes = cut.Instance.GetClass(); var noElevatedClass = !classes.Contains("m-bin--is-elevated"); @@ -85,10 +70,7 @@ public void RenderButtonWithDepressed() public void RenderButtonWithDisabled() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Disabled, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Disabled, true); }); var classes = cut.Instance.GetClass(); var hasDisabledClass = classes.Contains("m-btn--disabled"); @@ -100,10 +82,7 @@ public void RenderButtonWithDisabled() public void RenderButtonWithElevation() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Elevation, 24); - }); + var cut = RenderComponent(props => { props.Add(button => button.Elevation, 24); }); var classes = cut.Instance.GetClass(); var hasElevationClass = classes.Contains("m-btn--is-elevated"); @@ -115,10 +94,7 @@ public void RenderButtonWithElevation() public void RenderButtonWithFab() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Fab, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Fab, true); }); var classes = cut.Instance.GetClass(); var hasFabClass = classes.Contains("m-btn--fab"); @@ -130,10 +106,7 @@ public void RenderButtonWithFab() public void RenderButtonWithFixed() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Fixed, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Fixed, true); }); var classes = cut.Instance.GetClass(); var hasFixedClass = classes.Contains("m-btn--fixed"); @@ -145,25 +118,19 @@ public void RenderButtonWithFixed() public void RenderWithHeight() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.Height, 100); - }); + var cut = RenderComponent(props => { props.Add(p => p.Height, 100); }); var inputSlotDiv = cut.Find(".m-btn"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] public void RenderButtonWithIcon() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Icon, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Icon, true); }); var classes = cut.Instance.GetClass(); var hasIconClass = classes.Contains("m-btn--icon"); @@ -175,10 +142,7 @@ public void RenderButtonWithIcon() public void RenderButtonWithLarge() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Large, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Large, true); }); var classes = cut.Instance.GetClass(); var hasLargeClass = classes.Contains("m-size--large"); @@ -190,10 +154,7 @@ public void RenderButtonWithLarge() public void RenderButtonWithLeft() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Left, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Left, true); }); var classes = cut.Instance.GetClass(); var hasLeftClass = classes.Contains("m-btn--left"); @@ -205,10 +166,7 @@ public void RenderButtonWithLeft() public void RenderButtonWithLight() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Light, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Light, true); }); var classes = cut.Instance.GetClass(); var hasLightClass = classes.Contains("theme--light"); @@ -220,10 +178,7 @@ public void RenderButtonWithLight() public void RenderButtonWithLoading() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Loading, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Loading, true); }); var classes = cut.Instance.GetClass(); var hasLoadingClass = classes.Contains("m-btn--loading"); @@ -235,70 +190,55 @@ public void RenderButtonWithLoading() public void RenderWithMaxHeight() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.MaxHeight, 100); - }); + var cut = RenderComponent(props => { props.Add(p => p.MaxHeight, 100); }); var inputSlotDiv = cut.Find(".m-btn"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] public void RenderWithMaxWidth() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.MaxWidth, 100); - }); + var cut = RenderComponent(props => { props.Add(p => p.MaxWidth, 100); }); var inputSlotDiv = cut.Find(".m-btn"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] public void RenderWithMinHeight() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.MinHeight, 100); - }); + var cut = RenderComponent(props => { props.Add(p => p.MinHeight, 100); }); var inputSlotDiv = cut.Find(".m-btn"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] public void RenderWithMinWidth() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.MinWidth, 100); - }); + var cut = RenderComponent(props => { props.Add(p => p.MinWidth, 100); }); var inputSlotDiv = cut.Find(".m-btn"); var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] public void RenderButtonWithOutlined() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Outlined, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Outlined, true); }); var classes = cut.Instance.GetClass(); var hasoutlinedClass = classes.Contains("m-btn--outlined"); @@ -310,10 +250,7 @@ public void RenderButtonWithOutlined() public void RenderButtonWithPlain() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Plain, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Plain, true); }); var classes = cut.Instance.GetClass(); var hasPlainClass = classes.Contains("m-btn--plain"); @@ -325,10 +262,7 @@ public void RenderButtonWithPlain() public void RenderButtonWithRight() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Right, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Right, true); }); var classes = cut.Instance.GetClass(); var hasRightClass = classes.Contains("m-btn--right"); @@ -339,27 +273,24 @@ public void RenderButtonWithRight() [TestMethod] public void RenderButtonWithRipple() { - //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Ripple, true); + // ripple = true + var cut = RenderComponent(props => { props.Add(button => button.Ripple, true); }); + var root = cut.Find("button"); + var attr = root.GetAttribute("ripple"); + Assert.IsNotNull(attr); - }); - var classes = cut.Instance.GetClass(); - var hasRippleClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasRippleClass); + // ripple = false + var cut2 = RenderComponent(props => { props.Add(button => button.Ripple, false); }); + var root2 = cut2.Find("button"); + var attr2 = root2.GetAttribute("ripple"); + Assert.IsNull(attr2); } [TestMethod] public void RenderButtonWithRounded() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Rounded, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Rounded, true); }); var classes = cut.Instance.GetClass(); var hasRoundedClass = classes.Contains("m-btn--rounded"); @@ -367,30 +298,11 @@ public void RenderButtonWithRounded() Assert.IsTrue(hasRoundedClass); } - [TestMethod] - public void RenderButtonWithShaped() - { - //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Shaped, true); - - }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-btn"); - - // Assert - Assert.IsTrue(hasShapedClass); - } - [TestMethod] public void RenderButtonWithSmall() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Small, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Small, true); }); var classes = cut.Instance.GetClass(); var hasSmallClass = classes.Contains("m-size--small"); @@ -402,10 +314,7 @@ public void RenderButtonWithSmall() public void RenderButtonWithText() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Text, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Text, true); }); var classes = cut.Instance.GetClass(); var hasTextClass = classes.Contains("m-btn--text"); @@ -417,10 +326,7 @@ public void RenderButtonWithText() public void RenderButtonWithTile() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Tile, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Tile, true); }); var classes = cut.Instance.GetClass(); var hasTileClass = classes.Contains("m-btn--tile"); @@ -432,10 +338,7 @@ public void RenderButtonWithTile() public void RenderButtonWithTop() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.Top, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.Top, true); }); var classes = cut.Instance.GetClass(); var hasTopClass = classes.Contains("m-btn--top"); @@ -447,10 +350,7 @@ public void RenderButtonWithTop() public void RenderButtonWithXLarge() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.XLarge, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.XLarge, true); }); var classes = cut.Instance.GetClass(); var hasXLargeClass = classes.Contains("m-size--x-large"); @@ -462,10 +362,7 @@ public void RenderButtonWithXLarge() public void RenderButtonWithXSmall() { //Act - var cut = RenderComponent(props => - { - props.Add(button => button.XSmall, true); - }); + var cut = RenderComponent(props => { props.Add(button => button.XSmall, true); }); var classes = cut.Instance.GetClass(); var hasXSmallClass = classes.Contains("m-size--x-small"); @@ -478,17 +375,10 @@ public void RenderButtonAndOnClick() { // Arrange var times = 0; - var cut = RenderComponent(props => - { - props.Add(button => button.OnClick, args => - { - times++; - }); - }); + var cut = RenderComponent(props => { props.Add(button => button.OnClick, args => { times++; }); }); // Act - var buttonElement = cut.Find("button"); - buttonElement.Click(); + cut.Instance.OnClick.InvokeAsync(); // Assert Assert.AreEqual(1, times); @@ -522,7 +412,5 @@ public void RenderWithChildContent() // Assert contentDiv.Children.MarkupMatches("Hello world"); } - } -} - +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/Card/MCardTests.cs b/test/Masa.Blazor.Test/Card/MCardTests.cs index ec73004410..a19c25746b 100644 --- a/test/Masa.Blazor.Test/Card/MCardTests.cs +++ b/test/Masa.Blazor.Test/Card/MCardTests.cs @@ -45,7 +45,7 @@ public void RenderCardWithElevation() props.Add(alert => alert.Elevation, 24); }); var classes = cut.Instance.GetClass(); - var hasElevationClass = classes.Contains("m-card"); + var hasElevationClass = classes.Contains("elevation-24"); // Assert Assert.IsTrue(hasElevationClass); @@ -78,7 +78,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -93,22 +93,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); - } - - [TestMethod] - public void RenderCardWithHover() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Hover, true); - }); - var classes = cut.Instance.GetClass(); - var hasHoverClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasHoverClass); + Assert.AreEqual("width: 100px;", style); } [TestMethod] @@ -126,36 +111,6 @@ public void RenderCardWithLight() Assert.IsTrue(hasLightClass); } - [TestMethod] - public void RenderCardWithLoaderHeight() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.LoaderHeight, 4); - }); - var classes = cut.Instance.GetClass(); - var hasLoaderHeightClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasLoaderHeightClass); - } - - [TestMethod] - public void RenderCardWithLoading() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Loading, true); - }); - var classes = cut.Instance.GetClass(); - var hasLoadingClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasLoadingClass); - } - [TestMethod] public void RenderWithMaxHeight() { @@ -168,7 +123,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -183,7 +138,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -198,7 +153,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -213,7 +168,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -231,81 +186,6 @@ public void RenderCardWithOutlined() Assert.IsTrue(hasOutlinedClass); } - [TestMethod] - public void RenderCardWithRaised() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Raised, true); - }); - var classes = cut.Instance.GetClass(); - var hasRaisedClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasRaisedClass); - } - - [TestMethod] - public void RenderCardWithRipple() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Ripple, true); - }); - var classes = cut.Instance.GetClass(); - var hasRippleClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasRippleClass); - } - - [TestMethod] - public void RenderCardWithRounded() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Rounded, true); - }); - var classes = cut.Instance.GetClass(); - var hasRoundedClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasRoundedClass); - } - - [TestMethod] - public void RenderCardWithShaped() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Shaped, true); - }); - var classes = cut.Instance.GetClass(); - var hasShapedClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasShapedClass); - } - - [TestMethod] - public void RenderCardWithTile() - { - //Act - var cut = RenderComponent(props => - { - props.Add(card => card.Tile, true); - }); - var classes = cut.Instance.GetClass(); - var hasTileClass = classes.Contains("m-card"); - - // Assert - Assert.IsTrue(hasTileClass); - } - [TestMethod] public void RenderCardAndOnClick() { diff --git a/test/Masa.Blazor.Test/Checkbox/MCheckboxTests.cs b/test/Masa.Blazor.Test/Checkbox/MCheckboxTests.cs index 999b293a55..fc2ec8bb31 100644 --- a/test/Masa.Blazor.Test/Checkbox/MCheckboxTests.cs +++ b/test/Masa.Blazor.Test/Checkbox/MCheckboxTests.cs @@ -10,7 +10,6 @@ public class MCheckboxTests : TestBase public void RenderCheckboxWithDark() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Dark, true); @@ -26,7 +25,6 @@ public void RenderCheckboxWithDark() public void RenderCheckboxWithDense() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Dense, true); @@ -42,7 +40,6 @@ public void RenderCheckboxWithDense() public void RenderCheckboxWithDisabled() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(breadcrumbs => breadcrumbs.Disabled, true); @@ -58,7 +55,6 @@ public void RenderCheckboxWithDisabled() public void RenderCheckboxWithError() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Error, true); @@ -74,7 +70,6 @@ public void RenderCheckboxWithError() public void RenderCheckboxWithErrorCount() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(alert => alert.ErrorCount, 1); @@ -90,7 +85,6 @@ public void RenderCheckboxWithErrorCount() public void RenderCheckboxWithHideDetails() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.HideDetails, true); @@ -106,7 +100,6 @@ public void RenderCheckboxWithHideDetails() public void RenderCheckboxWithIndeterminate() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Indeterminate, true); @@ -122,7 +115,6 @@ public void RenderCheckboxWithIndeterminate() public void RenderCheckboxWithPersistentHint() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.PersistentHint, true); @@ -138,7 +130,6 @@ public void RenderCheckboxWithPersistentHint() public void RenderCheckboxWithReadonly() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Readonly, true); @@ -154,7 +145,6 @@ public void RenderCheckboxWithReadonly() public void RenderCheckboxWithRipple() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Ripple, true); @@ -170,7 +160,6 @@ public void RenderCheckboxWithRipple() public void RenderCheckboxWithSuccess() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Success, true); @@ -186,7 +175,6 @@ public void RenderCheckboxWithSuccess() public void RenderCheckboxWithValidateOnBlur() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.ValidateOnBlur, true); @@ -202,7 +190,6 @@ public void RenderCheckboxWithValidateOnBlur() public void RenderCheckboxWithValue() { //Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.Value, true); @@ -218,7 +205,6 @@ public void RenderCheckboxWithValue() public void RenderWithLabelContent() { // Arrange & Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(props => { props.Add(checkbox => checkbox.LabelContent, "Hello world"); @@ -233,12 +219,10 @@ public void RenderWithLabelContent() public void RenderNormal() { // Arrange & Act - JSInterop.Mode = JSRuntimeMode.Loose; var cut = RenderComponent>(); var inputDiv = cut.Find("div"); // Assert - Assert.AreEqual(6, inputDiv.ClassList.Length); Assert.IsTrue(inputDiv.ClassList.Contains("m-input")); Assert.IsTrue(inputDiv.ClassList.Contains("theme--light")); } diff --git a/test/Masa.Blazor.Test/Chip/MChipTests.cs b/test/Masa.Blazor.Test/Chip/MChipTests.cs index 03c4a90386..7c25b34a77 100644 --- a/test/Masa.Blazor.Test/Chip/MChipTests.cs +++ b/test/Masa.Blazor.Test/Chip/MChipTests.cs @@ -6,21 +6,6 @@ namespace Masa.Blazor.Test.Chip [TestClass] public class MChipTests : TestBase { - [TestMethod] - public void RenderChipWithActive() - { - //Act - var cut = RenderComponent(props => - { - props.Add(chip => chip.Active, true); - }); - var classes = cut.Instance.GetClass(); - var hasActiveClass = classes.Contains("m-chip"); - - // Assert - Assert.IsTrue(hasActiveClass); - } - [TestMethod] public void RenderChipWithClose() { @@ -81,21 +66,6 @@ public void RenderChipWithDisabled() Assert.IsTrue(hasDisabledClass); } - [TestMethod] - public void RenderChipWithFilter() - { - //Act - var cut = RenderComponent(props => - { - props.Add(chip => chip.Filter, true); - }); - var classes = cut.Instance.GetClass(); - var hasFilterClass = classes.Contains("m-chip"); - - // Assert - Assert.IsTrue(hasFilterClass); - } - [TestMethod] public void RenderChipWithLabel() { @@ -171,21 +141,6 @@ public void RenderChipWithPill() Assert.IsTrue(hasPillClass); } - [TestMethod] - public void RenderChipWithRipple() - { - //Act - var cut = RenderComponent(props => - { - props.Add(chip => chip.Ripple, true); - }); - var classes = cut.Instance.GetClass(); - var hasRippleClass = classes.Contains("m-chip"); - - // Assert - Assert.IsTrue(hasRippleClass); - } - [TestMethod] public void RenderChipWithSmall() { diff --git a/test/Masa.Blazor.Test/Dialog/MDialogTests.cs b/test/Masa.Blazor.Test/Dialog/MDialogTests.cs index 80ebe54149..d21879d9ec 100644 --- a/test/Masa.Blazor.Test/Dialog/MDialogTests.cs +++ b/test/Masa.Blazor.Test/Dialog/MDialogTests.cs @@ -80,36 +80,6 @@ public void RenderDialogWithLight() Assert.IsTrue(hasLightClass); } - [TestMethod] - public void RenderDialogWithMaxWidth() - { - //Act - var cut = RenderComponent(props => - { - props.Add(alert => alert.MaxWidth, 1); - }); - var classes = cut.Instance.GetClass(); - var hasMaxWidthClass = classes.Contains("m-dialog__container"); - - // Assert - Assert.IsTrue(hasMaxWidthClass); - } - - [TestMethod] - public void RenderDialogWithWidth() - { - //Act - var cut = RenderComponent(props => - { - props.Add(alert => alert.Width, 64); - }); - var classes = cut.Instance.GetClass(); - var hasWidthClass = classes.Contains("m-dialog__container"); - - // Assert - Assert.IsTrue(hasWidthClass); - } - [TestMethod] public void RenderDialogWithOpenDelay() { diff --git a/test/Masa.Blazor.Test/Divider/MDividerTests.cs b/test/Masa.Blazor.Test/Divider/MDividerTests.cs index 036e59cf3c..0874f93707 100644 --- a/test/Masa.Blazor.Test/Divider/MDividerTests.cs +++ b/test/Masa.Blazor.Test/Divider/MDividerTests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Bunit; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.Divider { @@ -13,8 +14,8 @@ public void RenderDividerWithDark() { props.Add(divider => divider.Dark, true); }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("theme--dark"); + var divider = cut.Find(".m-divider__wrapper").FirstElementChild; + var hasDarkClass = divider.ClassList.Contains("theme--dark"); // Assert Assert.IsTrue(hasDarkClass); @@ -28,8 +29,8 @@ public void RenderDividerWithLight() { props.Add(divider => divider.Light, true); }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("theme--light"); + var divider = cut.Find(".m-divider__wrapper").FirstElementChild; + var hasLightClass = divider.ClassList.Contains("theme--light"); // Assert Assert.IsTrue(hasLightClass); @@ -43,8 +44,8 @@ public void RenderDividerWithInset() { props.Add(divider => divider.Inset, true); }); - var classes = cut.Instance.GetClass(); - var hasInsetClass = classes.Contains("m-divider--inset"); + var divider = cut.Find(".m-divider__wrapper").FirstElementChild; + var hasInsetClass = divider.ClassList.Contains("m-divider--inset"); // Assert Assert.IsTrue(hasInsetClass); @@ -58,8 +59,8 @@ public void RenderDividerWithVertical() { props.Add(divider => divider.Vertical, true); }); - var classes = cut.Instance.GetClass(); - var hasVerticalClass = classes.Contains("m-divider--vertical"); + var divider = cut.Find(".m-divider__wrapper").FirstElementChild; + var hasVerticalClass = divider.ClassList.Contains("m-divider--vertical"); // Assert Assert.IsTrue(hasVerticalClass); diff --git a/test/Masa.Blazor.Test/ECharts/MEChartsTests.cs b/test/Masa.Blazor.Test/ECharts/MEChartsTests.cs index 72752b234d..06d6d451c8 100644 --- a/test/Masa.Blazor.Test/ECharts/MEChartsTests.cs +++ b/test/Masa.Blazor.Test/ECharts/MEChartsTests.cs @@ -18,7 +18,7 @@ public class MEChartsTests : TestBase // var style = inputSlotDiv.GetAttribute("style"); // // Assert - // Assert.AreEqual("height: 400px", style); + // Assert.AreEqual("height: 400px;", style); //} } } diff --git a/test/Masa.Blazor.Test/Footer/MFooterTests.cs b/test/Masa.Blazor.Test/Footer/MFooterTests.cs index 2388c6780c..9469ecbcc4 100644 --- a/test/Masa.Blazor.Test/Footer/MFooterTests.cs +++ b/test/Masa.Blazor.Test/Footer/MFooterTests.cs @@ -99,7 +99,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -147,7 +147,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: auto;max-height: 100px", style); + Assert.AreEqual("height: auto;max-height: 100px;", style); } [TestMethod] @@ -163,7 +163,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: auto;max-width: 100px", style); + Assert.AreEqual("height: auto;max-width: 100px;", style); } [TestMethod] @@ -179,7 +179,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: auto;min-height: 100px", style); + Assert.AreEqual("height: auto;min-height: 100px;", style); } [TestMethod] @@ -195,7 +195,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: auto;min-width: 100px", style); + Assert.AreEqual("height: auto;min-width: 100px;", style); } [TestMethod] @@ -211,7 +211,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: auto;width: 100px", style); + Assert.AreEqual("height: auto;width: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Image/MImageTests.cs b/test/Masa.Blazor.Test/Image/MImageTests.cs index 45edc3d57d..6bc5bbcae2 100644 --- a/test/Masa.Blazor.Test/Image/MImageTests.cs +++ b/test/Masa.Blazor.Test/Image/MImageTests.cs @@ -48,7 +48,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -78,7 +78,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -93,7 +93,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -108,7 +108,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -123,7 +123,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -138,7 +138,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Input/MInputTests.cs b/test/Masa.Blazor.Test/Input/MInputTests.cs index 7d6b45efc9..8baab3e22a 100644 --- a/test/Masa.Blazor.Test/Input/MInputTests.cs +++ b/test/Masa.Blazor.Test/Input/MInputTests.cs @@ -4,26 +4,23 @@ namespace Masa.Blazor.Test.Input { [TestClass] - public class MInputTests : TestBase + public class MInputTests : TestBase> { [TestMethod] public void RenderNormal() { // Arrange & Act - var cut = RenderComponent>(); - var inputDiv = cut.Find("div"); + var root = RenderAndGetRootElement(); // Assert - Assert.AreEqual(2, inputDiv.ClassList.Length); - Assert.IsTrue(inputDiv.ClassList.Contains("m-input")); - Assert.IsTrue(inputDiv.ClassList.Contains("theme--light")); + Assert.IsTrue(root.ClassList.Contains("m-input")); } [TestMethod] public void RenderWithHeight() { // Act - var cut = RenderComponent>(props => + var cut = Render(props => { props.Add(p => p.Height, 100); }); @@ -31,19 +28,18 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] public void RenderInputWithWithDark() { //Act - var cut = RenderComponent>(props => + var root = RenderAndGetRootElement(props => { props.Add(input => input.Dark, true); }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("theme--dark"); + var hasDarkClass = root.ClassList.Contains("theme--dark"); // Assert Assert.IsTrue(hasDarkClass); @@ -53,12 +49,11 @@ public void RenderInputWithWithDark() public void RenderInputNoWithWithDark() { //Act - var cut = RenderComponent>(props => + var cut = RenderAndGetRootElement(props => { props.Add(input => input.Dark, false); }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("m-input"); + var hasDarkClass = cut.ClassList.Contains("theme--light"); // Assert Assert.IsTrue(hasDarkClass); @@ -68,12 +63,11 @@ public void RenderInputNoWithWithDark() public void RenderInputWithWithLight() { //Act - var cut = RenderComponent>(props => + var cut = RenderAndGetRootElement(props => { props.Add(input => input.Light, true); }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("theme--light"); + var hasLightClass = cut.ClassList.Contains("theme--light"); // Assert Assert.IsTrue(hasLightClass); @@ -117,62 +111,20 @@ public void RenderIsDarkComputedColorShouldBeWhite() // Assert Assert.IsTrue(cut.Instance.IsDark); - Assert.AreEqual("white", cut.Instance.ComputedColor); - } - - [TestMethod] - public void RenderIsDarkShouldBeFalse() - { - // Act - var cut = RenderComponent>(); - - // Assert - Assert.IsFalse(cut.Instance.IsDark); - } - - [TestMethod] - public void RenderDarkIsDarkShouldBeTrue() - { - // Act - var cut = RenderComponent>(props => - { - props.Add(input => input.Light, false); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("m-input"); - - // Assert - Assert.IsTrue(hasLightClass); + Assert.AreEqual("primary", cut.Instance.ComputedColor); } [TestMethod] public void RenderInputWithWithDense() { //Act - var cut = RenderComponent>(props => + var cut = RenderAndGetRootElement(props => { props.Add(input => input.Dense, true); }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("m-input--dense"); - - // Assert - Assert.IsTrue(hasLightClass); - } - - [TestMethod] - public void RenderInputNoWithWithDense() - { - //Act - var cut = RenderComponent>(props => - { - props.Add(input => input.Dense, false); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("m-input"); // Assert - Assert.IsTrue(hasLightClass); + Assert.IsTrue(cut.ClassList.Contains("m-input--dense")); } } } diff --git a/test/Masa.Blazor.Test/List/MListItemAvatarTests.cs b/test/Masa.Blazor.Test/List/MListItemAvatarTests.cs index b8c554c6e7..0b4b5e69b4 100644 --- a/test/Masa.Blazor.Test/List/MListItemAvatarTests.cs +++ b/test/Masa.Blazor.Test/List/MListItemAvatarTests.cs @@ -18,7 +18,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;height: 100px", style); + Assert.AreEqual("height: 100px !important;", style); } [TestMethod] @@ -63,7 +63,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-height: 100px", style); + Assert.AreEqual("max-height: 100px !important;", style); } [TestMethod] @@ -78,7 +78,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;max-width: 100px", style); + Assert.AreEqual("max-width: 100px !important;", style); } [TestMethod] @@ -93,7 +93,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-height: 100px", style); + Assert.AreEqual("min-height: 100px !important;", style); } [TestMethod] @@ -108,7 +108,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;min-width: 100px", style); + Assert.AreEqual("min-width: 100px !important;", style); } [TestMethod] @@ -153,7 +153,7 @@ public void RenderWithSize() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px;min-width: 100px;width: 100px", style); + Assert.AreEqual("height: 100px !important;min-width: 100px !important;width: 100px !important;", style); } [TestMethod] @@ -183,7 +183,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 48px;min-width: 48px;width: 48px;width: 100px", style); + Assert.AreEqual("width: 100px !important;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/List/MListTests.cs b/test/Masa.Blazor.Test/List/MListTests.cs index 46ce66a608..8a5884bb3e 100644 --- a/test/Masa.Blazor.Test/List/MListTests.cs +++ b/test/Masa.Blazor.Test/List/MListTests.cs @@ -108,7 +108,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -123,7 +123,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] @@ -153,7 +153,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -168,7 +168,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -183,7 +183,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -198,7 +198,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -234,7 +234,7 @@ public void RenderListWithOutlined() [TestMethod] public void RenderListWithRounded() { - //Act + //Act var cut = RenderComponent(props => { props.Add(list => list.Rounded, true); diff --git a/test/Masa.Blazor.Test/Masa.Blazor.Test.csproj b/test/Masa.Blazor.Test/Masa.Blazor.Test.csproj index 3afce8fe63..4227dd98ed 100644 --- a/test/Masa.Blazor.Test/Masa.Blazor.Test.csproj +++ b/test/Masa.Blazor.Test/Masa.Blazor.Test.csproj @@ -1,12 +1,12 @@ - net6.0 + net6.0;net7.0;net8.0;net9.0 false - + @@ -18,8 +18,4 @@ - - - - diff --git a/test/Masa.Blazor.Test/NavigationDrawer/MNavigationDrawerTests.cs b/test/Masa.Blazor.Test/NavigationDrawer/MNavigationDrawerTests.cs index 28fedb3790..26b02675a6 100644 --- a/test/Masa.Blazor.Test/NavigationDrawer/MNavigationDrawerTests.cs +++ b/test/Masa.Blazor.Test/NavigationDrawer/MNavigationDrawerTests.cs @@ -179,7 +179,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px;top:0;transform:translateX(0%);width:256px", style); + Assert.AreEqual("height: 100px;top: 0px;transform: translateX(0%);width: 256px;", style); } [TestMethod] @@ -227,7 +227,7 @@ public void RenderWithMiniVariantWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100%;top:0;transform:translateX(0%);width:256px", style); + Assert.AreEqual("height: 100%;top: 0px;transform: translateX(0%);width: 256px;", style); } [TestMethod] @@ -262,22 +262,6 @@ public void RenderNavigationDrawerWithRight() Assert.IsTrue(hasRightClass); } - [TestMethod] - public void RenderNavigationDrawerWithStateless() - { - //Act - JSInterop.Mode = JSRuntimeMode.Loose; - var cut = RenderComponent(props => - { - props.Add(navigationdrawer => navigationdrawer.Stateless, true); - }); - var classes = cut.Instance.GetClass(); - var hasStatelessClass = classes.Contains("m-navigation-drawer"); - - // Assert - Assert.IsTrue(hasStatelessClass); - } - [TestMethod] public void RenderNavigationDrawerWithTemporary() { @@ -323,7 +307,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100%;top:0;transform:translateX(0%);width:100px", style); + Assert.AreEqual("height: 100%;top: 0px;transform: translateX(0%);width: 100px;", style); } } } diff --git a/test/Masa.Blazor.Test/Overlay/MOverlayTests.cs b/test/Masa.Blazor.Test/Overlay/MOverlayTests.cs index 721549adf5..e4fefa8a2f 100644 --- a/test/Masa.Blazor.Test/Overlay/MOverlayTests.cs +++ b/test/Masa.Blazor.Test/Overlay/MOverlayTests.cs @@ -1,4 +1,5 @@ -using Bunit; +using AngleSharp.Css.Dom; +using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Masa.Blazor.Test.Overlay @@ -10,10 +11,7 @@ public class MOverlayTests : TestBase public void RenderOverlayWithDark() { //Act - var cut = RenderComponent(props => - { - props.Add(overlay => overlay.Dark, true); - }); + var cut = RenderComponent(props => { props.Add(overlay => overlay.Dark, true); }); var classes = cut.Instance.GetClass(); var hasDarkClass = classes.Contains("theme--dark"); @@ -25,10 +23,7 @@ public void RenderOverlayWithDark() public void RenderOverlayWithLight() { //Act - var cut = RenderComponent(props => - { - props.Add(overlay => overlay.Light, true); - }); + var cut = RenderComponent(props => { props.Add(overlay => overlay.Light, true); }); var classes = cut.Instance.GetClass(); var hasLightClass = classes.Contains("m-overlay"); @@ -40,10 +35,7 @@ public void RenderOverlayWithLight() public void RenderOverlayWithValue() { //Act - var cut = RenderComponent(props => - { - props.Add(overlay => overlay.Value, true); - }); + var cut = RenderComponent(props => { props.Add(overlay => overlay.Value, true); }); var classes = cut.Instance.GetClass(); var hasValueClass = classes.Contains("m-overlay--active"); @@ -55,10 +47,7 @@ public void RenderOverlayWithValue() public void RenderOverlayWithAbsolute() { //Act - var cut = RenderComponent(props => - { - props.Add(overlay => overlay.Absolute, true); - }); + var cut = RenderComponent(props => { props.Add(overlay => overlay.Absolute, true); }); var classes = cut.Instance.GetClass(); var hasAbsoluteClass = classes.Contains("m-overlay--absolute"); @@ -72,28 +61,24 @@ public void RenderWithOpacity() // Act var cut = RenderComponent(props => { + props.Add(p => p.Value, true); props.Add(p => p.Opacity, 0.46); }); - var overlayDiv = cut.Find(".m-overlay__scrim"); - var style = overlayDiv.GetAttribute("style"); - - // Assert - Assert.AreEqual("background-color:#212121;border-color:#212121;opacity:0", style); + var root = cut.Find(".m-overlay"); + var opacity = root.GetStyle()["--m-overlay-opacity"]; + Assert.AreEqual(opacity, "0.46"); } [TestMethod] public void RenderWithZIndex() { // Act - var cut = RenderComponent(props => - { - props.Add(p => p.ZIndex, 5); - }); - var overlayDiv = cut.Find(".m-overlay__scrim"); - var style = overlayDiv.GetAttribute("style"); + var cut = RenderComponent(props => { props.Add(p => p.ZIndex, 5); }); + var root = cut.Find(".m-overlay"); + var zIndex = root.GetStyle()["z-index"]; // Assert - Assert.AreEqual("background-color:#212121;border-color:#212121;opacity:0", style); + Assert.AreEqual(zIndex, "5"); } } -} +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/Picker/MPickerTests.cs b/test/Masa.Blazor.Test/Picker/MPickerTests.cs index 852b091a41..b14afe231f 100644 --- a/test/Masa.Blazor.Test/Picker/MPickerTests.cs +++ b/test/Masa.Blazor.Test/Picker/MPickerTests.cs @@ -122,7 +122,7 @@ public void RenderPickerWithElevation() // var style = inputSlotDiv.GetAttribute("style"); // // Assert - // Assert.AreEqual("width: 290px", style); + // Assert.AreEqual("width: 290px;", style); //} } } diff --git a/test/Masa.Blazor.Test/ProgressLinear/MProgressLinearTests.cs b/test/Masa.Blazor.Test/ProgressLinear/MProgressLinearTests.cs index e2ad326990..d7e58e7fc5 100644 --- a/test/Masa.Blazor.Test/ProgressLinear/MProgressLinearTests.cs +++ b/test/Masa.Blazor.Test/ProgressLinear/MProgressLinearTests.cs @@ -4,7 +4,7 @@ namespace Masa.Blazor.Test.ProgressLinear { [TestClass] - public class MProgressLinearTests : TestBase + public class MProgressLinearTests : TestBase { [TestMethod] public void RenderProgressLinearWithAbsolute() @@ -112,15 +112,14 @@ public void RenderProgressLinearWithFixed() public void RenderWithHeight() { // Act - var cut = RenderComponent(props => + var root = RenderAndGetRootElement(props => { props.Add(p => p.Height, 4); }); - var inputSlotDiv = cut.Find(".m-progress-linear"); - var style = inputSlotDiv.GetAttribute("style"); + var style = root.GetAttribute("style"); // Assert - Assert.AreEqual("height:4px", style); + Assert.AreEqual("height: 4px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Radio/MRadioTests.cs b/test/Masa.Blazor.Test/Radio/MRadioTests.cs index eb6f02fdfc..d7dd69ca18 100644 --- a/test/Masa.Blazor.Test/Radio/MRadioTests.cs +++ b/test/Masa.Blazor.Test/Radio/MRadioTests.cs @@ -5,36 +5,6 @@ namespace Masa.Blazor.Test.Radio [TestClass] public class MRadioTests : TestBase { - [TestMethod] - public void RenderRadioWithDark() - { - //Act - var cut = RenderComponent>(props => - { - props.Add(radio => radio.Dark, true); - }); - var classes = cut.Instance.GetClass(); - var hasDarkClass = classes.Contains("theme--dark"); - - // Assert - Assert.IsTrue(hasDarkClass); - } - - [TestMethod] - public void RenderRadioWithLight() - { - //Act - var cut = RenderComponent>(props => - { - props.Add(radio => radio.Light, true); - }); - var classes = cut.Instance.GetClass(); - var hasLightClass = classes.Contains("theme--light"); - - // Assert - Assert.IsTrue(hasLightClass); - } - [TestMethod] public void RenderRadioWithIsDisabled() { diff --git a/test/Masa.Blazor.Test/RangeSlider/MRangeSliderTests.cs b/test/Masa.Blazor.Test/RangeSlider/MRangeSliderTests.cs index e2b9dbca1b..6d64f84152 100644 --- a/test/Masa.Blazor.Test/RangeSlider/MRangeSliderTests.cs +++ b/test/Masa.Blazor.Test/RangeSlider/MRangeSliderTests.cs @@ -102,7 +102,7 @@ public class MRangeSliderTests : TestBase // var style = inputSlotDiv.GetAttribute("style"); // // Assert - // Assert.AreEqual("height: 100px", style); + // Assert.AreEqual("height: 100px;", style); //} //[TestMethod] diff --git a/test/Masa.Blazor.Test/Sheet/MSheetTests.cs b/test/Masa.Blazor.Test/Sheet/MSheetTests.cs index 56b926c9c6..5e4f9ee6c4 100644 --- a/test/Masa.Blazor.Test/Sheet/MSheetTests.cs +++ b/test/Masa.Blazor.Test/Sheet/MSheetTests.cs @@ -48,7 +48,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -78,7 +78,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -93,7 +93,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -108,7 +108,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -123,7 +123,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -194,7 +194,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Snackbar/MSnackbarTests.cs b/test/Masa.Blazor.Test/Snackbar/MSnackbarTests.cs index a639eb46ac..7f8fdb8b23 100644 --- a/test/Masa.Blazor.Test/Snackbar/MSnackbarTests.cs +++ b/test/Masa.Blazor.Test/Snackbar/MSnackbarTests.cs @@ -89,7 +89,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -132,7 +132,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -147,7 +147,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -162,7 +162,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -177,7 +177,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -334,7 +334,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Stepper/MStepperTests.cs b/test/Masa.Blazor.Test/Stepper/MStepperTests.cs index 4d964ab5d1..0646f77203 100644 --- a/test/Masa.Blazor.Test/Stepper/MStepperTests.cs +++ b/test/Masa.Blazor.Test/Stepper/MStepperTests.cs @@ -77,7 +77,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] @@ -106,7 +106,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px", style); + Assert.AreEqual("max-height: 100px;", style); } [TestMethod] @@ -121,7 +121,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px", style); + Assert.AreEqual("max-width: 100px;", style); } [TestMethod] @@ -136,7 +136,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px", style); + Assert.AreEqual("min-height: 100px;", style); } [TestMethod] @@ -151,7 +151,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px", style); + Assert.AreEqual("min-width: 100px;", style); } [TestMethod] @@ -250,7 +250,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px", style); + Assert.AreEqual("width: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/SystemBar/MSystemBarTests.cs b/test/Masa.Blazor.Test/SystemBar/MSystemBarTests.cs index 90c0773c1d..036d655f20 100644 --- a/test/Masa.Blazor.Test/SystemBar/MSystemBarTests.cs +++ b/test/Masa.Blazor.Test/SystemBar/MSystemBarTests.cs @@ -83,7 +83,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height:100px", style); + Assert.AreEqual("height: 100px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/TestBase.cs b/test/Masa.Blazor.Test/TestBase.cs index 1911eeb1fd..32a611f40b 100644 --- a/test/Masa.Blazor.Test/TestBase.cs +++ b/test/Masa.Blazor.Test/TestBase.cs @@ -1,4 +1,8 @@ +using System; +using System.Linq; +using AngleSharp.Dom; using Bunit; +using Microsoft.AspNetCore.Components; using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -11,9 +15,41 @@ public void Setup() { TestContext = new Bunit.TestContext(); TestContext.Services.AddMasaBlazor(); + + JSInterop.Mode = JSRuntimeMode.Loose; + JSInterop.SetupModule("./_content/Masa.Blazor/js/components/transition/index.js"); } [TestCleanup] public void TearDown() => TestContext?.Dispose(); } -} + + public abstract class TestBase : TestBase where TComponent : IComponent + { + private readonly string _rootTag; + + public TestBase() + { + _rootTag = "div"; + } + + public TestBase(string rootTag) + { + _rootTag = rootTag; + } + + protected IRenderedComponent Render( + Action> parameterBuilder = null) + { + return parameterBuilder is null + ? TestContext!.RenderComponent() + : TestContext!.RenderComponent(parameterBuilder); + } + + protected IElement RenderAndGetRootElement( + Action> parameterBuilder = null) + { + return Render(parameterBuilder).Find(_rootTag); + } + } +} \ No newline at end of file diff --git a/test/Masa.Blazor.Test/Toolbar/MToolbarTests.cs b/test/Masa.Blazor.Test/Toolbar/MToolbarTests.cs index 93225e6474..4b79d49748 100644 --- a/test/Masa.Blazor.Test/Toolbar/MToolbarTests.cs +++ b/test/Masa.Blazor.Test/Toolbar/MToolbarTests.cs @@ -145,7 +145,7 @@ public void RenderWithHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 100px;height: 100px", style); + Assert.AreEqual("height: 100px;height: 100px;", style); } [TestMethod] @@ -160,7 +160,7 @@ public void RenderWithWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("width: 100px;height: 64px", style); + Assert.AreEqual("width: 100px;height: 64px;", style); } [TestMethod] @@ -175,7 +175,7 @@ public void RenderWithExtensionHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("height: 64px", style); + Assert.AreEqual("height: 64px;", style); } [TestMethod] @@ -204,7 +204,7 @@ public void RenderWithMaxHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-height: 100px;height: 64px", style); + Assert.AreEqual("max-height: 100px;height: 64px;", style); } [TestMethod] @@ -219,7 +219,7 @@ public void RenderWithMaxWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("max-width: 100px;height: 64px", style); + Assert.AreEqual("max-width: 100px;height: 64px;", style); } [TestMethod] @@ -234,7 +234,7 @@ public void RenderWithMinHeight() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-height: 100px;height: 64px", style); + Assert.AreEqual("min-height: 100px;height: 64px;", style); } [TestMethod] @@ -249,7 +249,7 @@ public void RenderWithMinWidth() var style = inputSlotDiv.GetAttribute("style"); // Assert - Assert.AreEqual("min-width: 100px;height: 64px", style); + Assert.AreEqual("min-width: 100px;height: 64px;", style); } [TestMethod] diff --git a/test/Masa.Blazor.Test/Treeview/MTreeviewTests.cs b/test/Masa.Blazor.Test/Treeview/MTreeviewTests.cs index 12bfd5476a..897da3e184 100644 --- a/test/Masa.Blazor.Test/Treeview/MTreeviewTests.cs +++ b/test/Masa.Blazor.Test/Treeview/MTreeviewTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using Bunit; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -8,15 +9,26 @@ namespace Masa.Blazor.Test.Treeview [TestClass] public class MTreeviewTests : TestBase { + private record Model(string Name, string Value, List Children); + + private IRenderedComponent> RenderTreeview( + Action>> parameterBuilder = null) + { + return RenderComponent>(props => + { + props.Add(t => t.Items, new List()); + props.Add(t => t.ItemText, u => u.Name); + props.Add(t => t.ItemKey, u => u.Value); + props.Add(t => t.ItemChildren, u => u.Children); + parameterBuilder?.Invoke(props); + }); + } + [TestMethod] public void RenderTreeviewWithHoverable() { //Act - var cut = RenderComponent>(props => - { - props.Add(treeview => treeview.Hoverable, true); - props.Add(treeview => treeview.ItemKey, item => item); - }); + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Hoverable, true); }); var classes = cut.Instance.GetClass(); var hasHoverableClass = classes.Contains("m-treeview--hoverable"); @@ -28,10 +40,9 @@ public void RenderTreeviewWithHoverable() public void RenderTreeviewWithActivatable() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Activatable, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasActivatableClass = classes.Contains("m-treeview"); @@ -44,10 +55,9 @@ public void RenderTreeviewWithActivatable() public void RenderTreeviewWithDark() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Dark, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasDarkClass = classes.Contains("theme--dark"); @@ -60,10 +70,9 @@ public void RenderTreeviewWithDark() public void RenderTreeviewWithDense() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Dense, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasDenseClass = classes.Contains("m-treeview"); @@ -76,10 +85,9 @@ public void RenderTreeviewWithDense() public void RenderTreeviewWithLight() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Light, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasLightClass = classes.Contains("theme--light"); @@ -92,10 +100,9 @@ public void RenderTreeviewWithLight() public void RenderTreeviewWithMultipleActive() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.MultipleActive, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasMultipleActiveClass = classes.Contains("m-treeview"); @@ -108,10 +115,9 @@ public void RenderTreeviewWithMultipleActive() public void RenderTreeviewWithOpenAll() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.OpenAll, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasOpenAllClass = classes.Contains("m-treeview"); @@ -124,10 +130,9 @@ public void RenderTreeviewWithOpenAll() public void RenderTreeviewWithOpenOnClick() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.OpenOnClick, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasOpenOnClickClass = classes.Contains("m-treeview"); @@ -140,10 +145,9 @@ public void RenderTreeviewWithOpenOnClick() public void RenderTreeviewWithRounded() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Rounded, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasRoundedClass = classes.Contains("m-treeview"); @@ -156,10 +160,9 @@ public void RenderTreeviewWithRounded() public void RenderTreeviewWithSelectable() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Selectable, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasSelectableClass = classes.Contains("m-treeview"); @@ -172,10 +175,9 @@ public void RenderTreeviewWithSelectable() public void RenderTreeviewWithShaped() { //Act - var cut = RenderComponent>(props => + var cut = RenderTreeview(props => { props.Add(treeview => treeview.Shaped, true); - props.Add(treeview => treeview.ItemKey, item => item); }); var classes = cut.Instance.GetClass(); var hasShapedClass = classes.Contains("m-treeview"); diff --git a/test/Masa.Blazor.Test/Windows/MWindowItemTests.cs b/test/Masa.Blazor.Test/Windows/MWindowItemTests.cs index 1767777ba3..f3d1801824 100644 --- a/test/Masa.Blazor.Test/Windows/MWindowItemTests.cs +++ b/test/Masa.Blazor.Test/Windows/MWindowItemTests.cs @@ -6,31 +6,17 @@ namespace Masa.Blazor.Test.Windows [TestClass] public class MWindowItemTests : TestBase { - [TestMethod] - public void RenderWindowItemWithDisabled() - { - //Act - var cut = RenderComponent(props => - { - props.Add(windowitem => windowitem.Disabled, true); - }); - var classes = cut.Instance.GetClass(); - var hasDisabledClass = classes.Contains("m-window-item"); - - // Assert - Assert.IsTrue(hasDisabledClass); - } - [TestMethod] public void RenderWithChildContent() { // Arrange & Act var cut = RenderComponent(props => { + props.Add(w => w.Eager, true); props.Add(windowitem => windowitem.ChildContent, "Hello world"); }); var contentDiv = cut.Find(".m-window-item"); - //row fill-height + // Assert contentDiv.Children.MarkupMatches("Hello world"); }