From 1c843a57dbe14c90a13084fe46de7c6085492eb3 Mon Sep 17 00:00:00 2001 From: Denis Voituron Date: Mon, 27 Jan 2025 14:32:15 +0100 Subject: [PATCH 1/3] Add Unit Tests --- .../Dialog/FluentDialogProvider.razor | 4 +-- tests/Core/Components/Base/BaseHelpers.cs | 13 +++++++++ .../Components/Base/ComponentBaseTests.cs | 8 ++++-- .../Components/Dialog/FluentDialogTests.razor | 28 +++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/Core/Components/Dialog/FluentDialogProvider.razor b/src/Core/Components/Dialog/FluentDialogProvider.razor index 7182af2252..7d892b34be 100644 --- a/src/Core/Components/Dialog/FluentDialogProvider.razor +++ b/src/Core/Components/Dialog/FluentDialogProvider.razor @@ -7,8 +7,8 @@ @foreach (var dialog in DialogService.Items.Values.OrderBy(i => i.Index)) { private static readonly Type[] Excluded = new[] { - typeof(AspNetCore.Components._Imports) + typeof(AspNetCore.Components._Imports), + typeof(DialogOptions), }; /// @@ -30,7 +31,8 @@ public class ComponentBaseTests : TestContext /// private static readonly Dictionary> ComponentInitializer = new() { - { typeof(FluentIcon<>), type => type.MakeGenericType(typeof(Samples.Icons.Samples.Info)) } + { typeof(FluentIcon<>), type => type.MakeGenericType(typeof(Samples.Icons.Samples.Info)) }, + { typeof(FluentSelect<>), type => type.MakeGenericType(typeof(int)) }, }; /// @@ -70,7 +72,7 @@ public void ComponentBase_DefaultProperties(string blazor, string html) JSInterop.Mode = JSRuntimeMode.Loose; - foreach (var componentType in BaseHelpers.GetDerivedTypes(except: Excluded)) + foreach (var componentType in BaseHelpers.GetDerivedTypes(except: Excluded)) { // Convert to generic type if needed var type = ComponentInitializer.ContainsKey(componentType) diff --git a/tests/Core/Components/Dialog/FluentDialogTests.razor b/tests/Core/Components/Dialog/FluentDialogTests.razor index 61f7ea7ac5..775d67d773 100644 --- a/tests/Core/Components/Dialog/FluentDialogTests.razor +++ b/tests/Core/Components/Dialog/FluentDialogTests.razor @@ -468,4 +468,32 @@ Assert.Equal(expected, dialog.GetAttribute("size")); } } + + [Fact(Timeout = TEST_TIMEOUT)] + public async Task FluentDialog_MarginPadding() + { + // Arrange + var renderOptions = new Templates.DialogRenderOptions(); + + var dialogOptions = new DialogOptions() + { + Class = "my-class", + Style = "border: 1px solid red;", + Margin = "10px", + Padding = "20px", + }; + dialogOptions.Parameters.Add(nameof(Templates.DialogRender.Options), renderOptions); + dialogOptions.Parameters.Add(nameof(Templates.DialogRender.Name), "John"); + + // Act + var dialogTask = DialogService.ShowDialogAsync(dialogOptions); + + // Don't wait for the dialog to be closed + await Task.CompletedTask; + + // Assert + Assert.Contains("class=\"my-class\"", DialogProvider.Markup); + Assert.Contains("style=\"margin: 10px; padding: 20px; border: 1px solid red;\"", DialogProvider.Markup); + Assert.Contains("{ margin: 10px; padding: 20px; border: 1px solid red; }", DialogProvider.Markup); + } } From ee67aafdcddcf754046596478324718dc36df2b7 Mon Sep 17 00:00:00 2001 From: Denis Voituron Date: Mon, 27 Jan 2025 14:47:34 +0100 Subject: [PATCH 2/3] Add Unit Tests --- src/Core/Extensions/EnumExtensions.cs | 7 ++++++- .../Core/Components/Dialog/FluentDialogTests.razor | 1 + tests/Core/Components/Grid/FluentGridTests.razor | 1 + .../Core/Components/Layout/FluentLayoutTests.razor | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Core/Extensions/EnumExtensions.cs b/src/Core/Extensions/EnumExtensions.cs index 5e0632653b..be75f74738 100644 --- a/src/Core/Extensions/EnumExtensions.cs +++ b/src/Core/Extensions/EnumExtensions.cs @@ -30,8 +30,13 @@ public static class EnumExtensions public static string GetDescription(this Enum value) { var memberInfo = value.GetType().GetMember(value.ToString()); - var attribute = memberInfo[0].GetCustomAttribute(); + if (memberInfo.Length == 0) + { + return string.Empty; + } + + var attribute = memberInfo[0].GetCustomAttribute(); var result = attribute?.Description ?? value.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture); return result; diff --git a/tests/Core/Components/Dialog/FluentDialogTests.razor b/tests/Core/Components/Dialog/FluentDialogTests.razor index 775d67d773..4517a0cc73 100644 --- a/tests/Core/Components/Dialog/FluentDialogTests.razor +++ b/tests/Core/Components/Dialog/FluentDialogTests.razor @@ -47,6 +47,7 @@ [Theory(Timeout = TEST_TIMEOUT)] [InlineData("position=\"start\"", DialogAlignment.Start)] [InlineData("position=\"end\"", DialogAlignment.End)] + [InlineData("", (DialogAlignment)999)] public async Task FluentDialog_Drawer(string expectedContains, DialogAlignment alignment) { // Arrange diff --git a/tests/Core/Components/Grid/FluentGridTests.razor b/tests/Core/Components/Grid/FluentGridTests.razor index 9dba8f1218..5a9deb7a02 100644 --- a/tests/Core/Components/Grid/FluentGridTests.razor +++ b/tests/Core/Components/Grid/FluentGridTests.razor @@ -155,6 +155,7 @@ [InlineData(GridItemSize.Xl, GridItemHidden.Xl)] [InlineData(GridItemSize.Xxl, GridItemHidden.Xxl)] [InlineData(GridItemSize.Xs | GridItemSize.Xxl, GridItemHidden.None)] + [InlineData((GridItemSize)999, GridItemHidden.None)] public void FluentGrid_ConvertToHidden(GridItemSize size, GridItemHidden expected) { Assert.Equal(expected, FluentGridItem.ConvertToHidden(size)); diff --git a/tests/Core/Components/Layout/FluentLayoutTests.razor b/tests/Core/Components/Layout/FluentLayoutTests.razor index dee6c60628..6a11c9c88c 100644 --- a/tests/Core/Components/Layout/FluentLayoutTests.razor +++ b/tests/Core/Components/Layout/FluentLayoutTests.razor @@ -186,4 +186,18 @@ }); } + + [Fact] + public void FluentLayout_InvalidArea() + { + // Arrange && Act + var cut = Render(@ + Content + Aside + ); + + // Assert + Assert.Contains("style=\"height: 36px;\" area=\"\"", cut.Markup); + Assert.Contains("style=\"height: 42px;\" area=\"\"", cut.Markup); + } } From 6ec8cf7e0307834e4c048e0b9f3788f186511296 Mon Sep 17 00:00:00 2001 From: Denis Voituron Date: Mon, 27 Jan 2025 14:59:09 +0100 Subject: [PATCH 3/3] Add Untit Tests --- tests/Core/Components/Slack/FluentStackTests.razor | 6 ++++-- tests/Core/Components/TextInput/FluentTextInputTests.razor | 1 + tests/Core/Migration/AppearanceExtensionsTests.cs | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Core/Components/Slack/FluentStackTests.razor b/tests/Core/Components/Slack/FluentStackTests.razor index f4e0c24987..fe86b4f478 100644 --- a/tests/Core/Components/Slack/FluentStackTests.razor +++ b/tests/Core/Components/Slack/FluentStackTests.razor @@ -36,6 +36,7 @@ [InlineData("justify-content: end; align-items: start;", Orientation.Horizontal, Fuib.HorizontalAlignment.End)] [InlineData("justify-content: stretch; align-items: start;", Orientation.Horizontal, Fuib.HorizontalAlignment.Stretch)] [InlineData("justify-content: space-between; align-items: start;", Orientation.Horizontal, Fuib.HorizontalAlignment.SpaceBetween)] + [InlineData("justify-content: start; align-items: start;", Orientation.Horizontal, (Fuib.HorizontalAlignment)999)] [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, Fuib.HorizontalAlignment.Left)] [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, Fuib.HorizontalAlignment.Start)] [InlineData("justify-content: start; align-items: center;", Orientation.Vertical, Fuib.HorizontalAlignment.Center)] @@ -43,6 +44,7 @@ [InlineData("justify-content: start; align-items: end;", Orientation.Vertical, Fuib.HorizontalAlignment.End)] [InlineData("justify-content: start; align-items: stretch;", Orientation.Vertical, Fuib.HorizontalAlignment.Stretch)] [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, Fuib.HorizontalAlignment.SpaceBetween)] + [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, (Fuib.HorizontalAlignment)999)] public void FluentStack_HorizontalAlignment(string expectedStyle, Orientation orientation, Fuib.HorizontalAlignment alignment) { // Arrange && Act @@ -59,19 +61,19 @@ [InlineData("justify-content: start; align-items: end;", Orientation.Horizontal, Fuib.VerticalAlignment.Bottom)] [InlineData("justify-content: start; align-items: stretch;", Orientation.Horizontal, Fuib.VerticalAlignment.Stretch)] [InlineData("justify-content: start; align-items: start;", Orientation.Horizontal, Fuib.VerticalAlignment.SpaceBetween)] + [InlineData("justify-content: start; align-items: start;", Orientation.Horizontal, (Fuib.VerticalAlignment)999)] [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, Fuib.VerticalAlignment.Top)] [InlineData("justify-content: center; align-items: start;", Orientation.Vertical, Fuib.VerticalAlignment.Center)] [InlineData("justify-content: end; align-items: start;", Orientation.Vertical, Fuib.VerticalAlignment.Bottom)] [InlineData("justify-content: stretch; align-items: start;", Orientation.Vertical, Fuib.VerticalAlignment.Stretch)] [InlineData("justify-content: space-between; align-items: start;", Orientation.Vertical, Fuib.VerticalAlignment.SpaceBetween)] + [InlineData("justify-content: start; align-items: start;", Orientation.Vertical, (Fuib.VerticalAlignment)999)] public void FluentStack_VerticalAlignment(string expectedStyle, Orientation orientation, Fuib.VerticalAlignment alignment) { // Arrange && Act var cut = Render(@); var styles = cut.Find("div").GetAttribute("style"); - Output.WriteLine($"{orientation}, {alignment} => {styles}"); - // Assert Assert.Contains(expectedStyle, styles); } diff --git a/tests/Core/Components/TextInput/FluentTextInputTests.razor b/tests/Core/Components/TextInput/FluentTextInputTests.razor index 5cc4818c80..6d3a2b66d2 100644 --- a/tests/Core/Components/TextInput/FluentTextInputTests.razor +++ b/tests/Core/Components/TextInput/FluentTextInputTests.razor @@ -160,6 +160,7 @@ [Theory] [InlineData(FluentInputAppearance.Filled, TextInputAppearance.FilledDarker)] [InlineData(FluentInputAppearance.Outline, TextInputAppearance.Outline)] + [InlineData((FluentInputAppearance)999, TextInputAppearance.Outline)] public void FluentInputText_ToTextInputAppearance(FluentInputAppearance appearance, TextInputAppearance expected) { var value = AspNetCore.Components.Migration.FluentInputAppearanceExtensions.ToTextInputAppearance(appearance); diff --git a/tests/Core/Migration/AppearanceExtensionsTests.cs b/tests/Core/Migration/AppearanceExtensionsTests.cs index f566ae8177..8cd0fb98cd 100644 --- a/tests/Core/Migration/AppearanceExtensionsTests.cs +++ b/tests/Core/Migration/AppearanceExtensionsTests.cs @@ -20,6 +20,7 @@ public partial class AppearanceExtensionsTests [InlineData(Appearance.Stealth, ButtonAppearance.Default)] [InlineData(Appearance.Filled, ButtonAppearance.Default)] [InlineData(Appearance.Filled | Appearance.Accent, ButtonAppearance.Default)] + [InlineData((Appearance)999, ButtonAppearance.Default)] public void Appearance_ToButtonAppearance(Appearance appearance, ButtonAppearance expected) { Assert.Equal(expected, appearance.ToButtonAppearance());