Skip to content

Commit

Permalink
✅ test: update unit tests (#2255)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem authored Nov 21, 2024
1 parent 0fe6b05 commit 6646e6c
Show file tree
Hide file tree
Showing 44 changed files with 477 additions and 1,839 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/Masa.Blazor/Components/App/MApp.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Masa.Blazor.Popup;

namespace Masa.Blazor;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Masa.Blazor/Components/Button/MButton.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions src/Masa.Blazor/Components/List/MList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ protected override void OnParametersSet()
protected override IEnumerable<string> BuildComponentClass()
{
yield return _sheetModifierBuilder
.Add(Outlined)
.Add(Shaped)
.AddTheme(IsDark, IndependentTheme)
.AddElevation(Elevation)
Expand Down
7 changes: 5 additions & 2 deletions src/Masa.Blazor/Core/MasaComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ public ForwardRef RefBack
{
continue;
}

stringBuilder.Append(item);
stringBuilder.Append("; ");
if (!item.EndsWith(';'))
{
stringBuilder.Append(';');
}
}

if (!NoStyle)
Expand Down
5 changes: 4 additions & 1 deletion src/Masa.Blazor/Services/Application.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.ComponentModel;

[assembly:InternalsVisibleTo("Masa.Blazor.Test")]

namespace Masa.Blazor
{
Expand Down
118 changes: 47 additions & 71 deletions test/Masa.Blazor.Test/Alert/MAlertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@
namespace Masa.Blazor.Test.Alert
{
[TestClass]
public class MAlertTests : TestBase
public class MAlertTests : TestBase<MAlert>
{
[TestMethod]
public void RenderAlertWithColoredBorder()
public void Border()
{
//Act
var cut = RenderComponent<MAlert>(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<MAlert>(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);
Expand All @@ -40,12 +35,11 @@ public void RenderAlertWithDense()
public void RenderAlertWithDark()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -55,27 +49,23 @@ public void RenderAlertWithDark()
public void RenderAlertWithDismissible()
{
//Act
var cut = RenderComponent<MAlert>(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<MAlert>(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);
Expand All @@ -85,27 +75,25 @@ public void RenderAlertWithElevation()
public void RenderWithHeight()
{
// Act
var cut = RenderComponent<MAlert>(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<MAlert>(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);
Expand All @@ -115,12 +103,11 @@ public void RenderAlertWithIcon()
public void RenderAlertWithWithLight()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -130,72 +117,67 @@ public void RenderAlertWithWithLight()
public void RenderWithMaxHeight()
{
// Act
var cut = RenderComponent<MAlert>(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<MAlert>(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<MAlert>(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<MAlert>(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<MAlert>(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);
Expand All @@ -205,12 +187,11 @@ public void RenderAlertWithOutlined()
public void RenderAlertWithProminent()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -220,12 +201,11 @@ public void RenderAlertWithProminent()
public void RenderAlertWithRounded()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -235,12 +215,11 @@ public void RenderAlertWithRounded()
public void RenderAlertWithShaped()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -250,12 +229,11 @@ public void RenderAlertWithShaped()
public void RenderAlertWithText()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -265,12 +243,11 @@ public void RenderAlertWithText()
public void RenderAlertWithTile()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -280,12 +257,11 @@ public void RenderAlertWithTile()
public void RenderAlertWithValue()
{
//Act
var cut = RenderComponent<MAlert>(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);
Expand All @@ -295,7 +271,7 @@ public void RenderAlertWithValue()
public void RenderWithChildContent()
{
// Arrange & Act
var cut = RenderComponent<MAlert>(props =>
var cut = Render(props =>
{
props.Add(alert => alert.ChildContent, "<span>Hello world</span>");
});
Expand Down
Loading

0 comments on commit 6646e6c

Please sign in to comment.