From 3ce4246cde67afeeaf4dff79c96433a9db836858 Mon Sep 17 00:00:00 2001 From: dvoituron Date: Sat, 16 Dec 2023 17:43:19 +0100 Subject: [PATCH 1/4] Add Icons Tests --- tests/Core/Extensions/SampleIcons.cs | 2 +- ...FluentIcon_ButtonStart.verified.razor.html | 5 + ...Tests.FluentIcon_Color.verified.razor.html | 4 + ...FluentIcon_CustomColor.verified.razor.html | 4 + ...sts.FluentIcon_Default.verified.razor.html | 4 + ...entIcon_Icon_FromImage.verified.razor.html | 4 + ...uentIcon_Icon_ToMarkup.verified.razor.html | 6 + ...con_Icon_ToMarkupColor.verified.razor.html | 6 + ...Icon_Icon_ToMarkupSize.verified.razor.html | 6 + ...Icon_Icon_WithColorRed.verified.razor.html | 4 + ...orRed_OverridenByColor.verified.razor.html | 4 + ..._Icon_WithColorSuccess.verified.razor.html | 4 + ...s.FluentIcon_SlotTitle.verified.razor.html | 5 + ...nTests.FluentIcon_Type.verified.razor.html | 4 + ....FluentIcon_Type_Color.verified.razor.html | 4 + ...Tests.FluentIcon_Width.verified.razor.html | 4 + tests/Core/Icons/FluentIconTests.razor | 183 ++++++++++++++++++ tests/Core/_ToDo/Icons/FluentIconTests.cs | 34 ---- 18 files changed, 252 insertions(+), 35 deletions(-) create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_ButtonStart.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Color.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_CustomColor.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Default.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_FromImage.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkup.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupSize.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed_OverridenByColor.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorSuccess.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_SlotTitle.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Type.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Type_Color.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.FluentIcon_Width.verified.razor.html create mode 100644 tests/Core/Icons/FluentIconTests.razor delete mode 100644 tests/Core/_ToDo/Icons/FluentIconTests.cs diff --git a/tests/Core/Extensions/SampleIcons.cs b/tests/Core/Extensions/SampleIcons.cs index aa484d2b9c..249c6dcd6d 100644 --- a/tests/Core/Extensions/SampleIcons.cs +++ b/tests/Core/Extensions/SampleIcons.cs @@ -8,7 +8,7 @@ public static class SampleIcons public static readonly Icon PresenceAvailable = new Samples.PresenceAvailable(); - private class Samples + internal class Samples { internal class Info : Icon { public Info() : base("Info", IconVariant.Filled, IconSize.Size24, "") { } } diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_ButtonStart.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_ButtonStart.verified.razor.html new file mode 100644 index 0000000000..c0bbf4cbc8 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_ButtonStart.verified.razor.html @@ -0,0 +1,5 @@ + + + My Button \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Color.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Color.verified.razor.html new file mode 100644 index 0000000000..f430837c41 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Color.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_CustomColor.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_CustomColor.verified.razor.html new file mode 100644 index 0000000000..360a14d960 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_CustomColor.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Default.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Default.verified.razor.html new file mode 100644 index 0000000000..cd899d4eaa --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Default.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_FromImage.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_FromImage.verified.razor.html new file mode 100644 index 0000000000..f318d091d6 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_FromImage.verified.razor.html @@ -0,0 +1,4 @@ + +
+ +
\ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkup.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkup.verified.razor.html new file mode 100644 index 0000000000..5cf76e7aab --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkup.verified.razor.html @@ -0,0 +1,6 @@ + +
+ +
\ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html new file mode 100644 index 0000000000..5b977063b8 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html @@ -0,0 +1,6 @@ + +
+ +
\ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupSize.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupSize.verified.razor.html new file mode 100644 index 0000000000..c356107c20 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupSize.verified.razor.html @@ -0,0 +1,6 @@ + +
+ +
\ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed.verified.razor.html new file mode 100644 index 0000000000..03e5d9cbb9 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed_OverridenByColor.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed_OverridenByColor.verified.razor.html new file mode 100644 index 0000000000..f430837c41 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorRed_OverridenByColor.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorSuccess.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorSuccess.verified.razor.html new file mode 100644 index 0000000000..4535566e81 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_WithColorSuccess.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_SlotTitle.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_SlotTitle.verified.razor.html new file mode 100644 index 0000000000..8cc9c30672 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_SlotTitle.verified.razor.html @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Type.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Type.verified.razor.html new file mode 100644 index 0000000000..cd899d4eaa --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Type.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Type_Color.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Type_Color.verified.razor.html new file mode 100644 index 0000000000..f430837c41 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Type_Color.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Width.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Width.verified.razor.html new file mode 100644 index 0000000000..325acc8c48 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Width.verified.razor.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/tests/Core/Icons/FluentIconTests.razor b/tests/Core/Icons/FluentIconTests.razor new file mode 100644 index 0000000000..b2063df137 --- /dev/null +++ b/tests/Core/Icons/FluentIconTests.razor @@ -0,0 +1,183 @@ +@using Microsoft.FluentUI.AspNetCore.Components.Tests.Extensions +@using Xunit; +@inherits TestContext +@code +{ + [Fact] + public void FluentIcon_Default() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Type() + { + // Arrange && Act + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_SlotTitle() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Color() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Type_Color() + { + // Arrange && Act + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_CustomColor() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Width() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_OnClick() + { + var isClicked = false; + + // Arrange + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Act + cut.Find("svg").Click(); + + // Assert + Assert.True(isClicked); + } + + [Fact] + public void FluentIcon_ButtonStart() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@My Button); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_FromImage() + { + // Arrange && Act + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_WithColorRed() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_WithColorRed_OverridenByColor() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_WithColorSuccess() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_ToMarkup() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@
@icon.ToMarkup()
); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_ToMarkupSize() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@
@icon.ToMarkup(size: "100px")
); + + // Assert + cut.Verify(); + } + + [Fact] + public void FluentIcon_Icon_ToMarkupColor() + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@
@icon.ToMarkup(color: "blue")
); + + // Assert + cut.Verify(); + } +} \ No newline at end of file diff --git a/tests/Core/_ToDo/Icons/FluentIconTests.cs b/tests/Core/_ToDo/Icons/FluentIconTests.cs deleted file mode 100644 index 5f7938617d..0000000000 --- a/tests/Core/_ToDo/Icons/FluentIconTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Bunit; -using Microsoft.AspNetCore.Components.Web; -using Xunit; - -namespace Microsoft.FluentUI.AspNetCore.Components.Tests.Icons; - -public class FluentIconTests : TestBase -{ - [Fact(Skip = "Need to figure out how to do this test")] - public void FluentIcon_Default() - { - //Arrange - string slot = default!; - string title = default!; - Color? color = default!; - string customColor = default!; - string width = default!; - Icon value = default!; - Action onClick = _ => { }; - var cut = TestContext.RenderComponent>(parameters => parameters - .Add(p => p.Slot, slot) - .Add(p => p.Title, title) - .Add(p => p.Color, color) - .Add(p => p.CustomColor, customColor) - .Add(p => p.Width, width) - .Add(p => p.Value, value) - .Add(p => p.OnClick, onClick) - ); - //Act - - //Assert - cut.Verify(); - } -} \ No newline at end of file From 6b83030799eb350f805aacae7955e80cc878bfe5 Mon Sep 17 00:00:00 2001 From: dvoituron Date: Sat, 16 Dec 2023 17:45:39 +0100 Subject: [PATCH 2/4] Fix UnitTest --- ...tIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html index 5b977063b8..d3b8496d01 100644 --- a/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html +++ b/tests/Core/Icons/FluentIconTests.FluentIcon_Icon_ToMarkupColor.verified.razor.html @@ -1,6 +1,6 @@
-
\ No newline at end of file From 136276973b2e679288e3df7e2a80a8342955868a Mon Sep 17 00:00:00 2001 From: dvoituron Date: Sat, 16 Dec 2023 17:51:12 +0100 Subject: [PATCH 3/4] Add Exception Test --- tests/Core/Icons/FluentIconTests.razor | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Core/Icons/FluentIconTests.razor b/tests/Core/Icons/FluentIconTests.razor index b2063df137..c6524beb7b 100644 --- a/tests/Core/Icons/FluentIconTests.razor +++ b/tests/Core/Icons/FluentIconTests.razor @@ -67,6 +67,19 @@ cut.Verify(); } + [Fact] + public void FluentIcon_CustomColor_RequiresColorAttribute() + { + Assert.Throws(() => + { + // Arrange && Act + var icon = new SampleIcons.Samples.Info(); + var cut = Render(@); + + // Assert an exception because Color=Color.Custom is required + }); + } + [Fact] public void FluentIcon_Width() { From 83a84c4fe230f4d357478f64b4459c1f7755ae97 Mon Sep 17 00:00:00 2001 From: dvoituron Date: Sat, 16 Dec 2023 18:04:42 +0100 Subject: [PATCH 4/4] Add Missing Test --- tests/Core/Icons/FluentIconTests.razor | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Core/Icons/FluentIconTests.razor b/tests/Core/Icons/FluentIconTests.razor index c6524beb7b..345f4d0cf8 100644 --- a/tests/Core/Icons/FluentIconTests.razor +++ b/tests/Core/Icons/FluentIconTests.razor @@ -128,6 +128,16 @@ cut.Verify(); } + [Fact] + public void FluentIcon_Icon_FromEmptyImage() + { + // Arrange && Act + var icon = new IconFromImage(); + + // Assert + Assert.Empty(icon.Content); + + } [Fact] public void FluentIcon_Icon_WithColorRed() {