Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Core/Components/Dialog/FluentDialogProvider.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@foreach (var dialog in DialogService.Items.Values.OrderBy(i => i.Index))
{
<FluentDialog Id="@dialog.Id"
Class="@dialog.Options?.Class"
Style="@dialog.Options?.Style"
Class="@dialog.Options?.ClassValue"
Style="@dialog.Options?.StyleValue"
Data="@dialog.Options?.Data"
Instance="@dialog"
OnStateChange="@(dialog.Options?.OnStateChange ?? EmptyOnStateChange)"
Expand Down
7 changes: 6 additions & 1 deletion src/Core/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DescriptionAttribute>();

if (memberInfo.Length == 0)
{
return string.Empty;
}

var attribute = memberInfo[0].GetCustomAttribute<DescriptionAttribute>();
var result = attribute?.Description ?? value.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture);

return result;
Expand Down
13 changes: 13 additions & 0 deletions tests/Core/Components/Base/BaseHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ private static bool IsSubclassOfGenericType(Type? type, Type genericType)
{
while (type != null && type != typeof(object))
{
// Interface
if (genericType.IsInterface)
{
foreach (var item in type.GetInterfaces())
{
if (item == genericType)
{
return true;
}
}
}

// Class
var cur = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
if (cur == genericType)
{
Expand Down
8 changes: 5 additions & 3 deletions tests/Core/Components/Base/ComponentBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public class ComponentBaseTests : TestContext
/// </summary>
private static readonly Type[] Excluded = new[]
{
typeof(AspNetCore.Components._Imports)
typeof(AspNetCore.Components._Imports),
typeof(DialogOptions),
};

/// <summary>
/// List of customized actions to initialize the component with a specific type.
/// </summary>
private static readonly Dictionary<Type, Func<Type, Type>> 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)) },
};

/// <summary />
Expand Down Expand Up @@ -70,7 +72,7 @@ public void ComponentBase_DefaultProperties(string blazor, string html)

JSInterop.Mode = JSRuntimeMode.Loose;

foreach (var componentType in BaseHelpers.GetDerivedTypes<FluentComponentBase>(except: Excluded))
foreach (var componentType in BaseHelpers.GetDerivedTypes<IFluentComponentBase>(except: Excluded))
{
// Convert to generic type if needed
var type = ComponentInitializer.ContainsKey(componentType)
Expand Down
29 changes: 29 additions & 0 deletions tests/Core/Components/Dialog/FluentDialogTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -468,4 +469,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<Templates.DialogRender>(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);
}
}
1 change: 1 addition & 0 deletions tests/Core/Components/Grid/FluentGridTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 14 additions & 0 deletions tests/Core/Components/Layout/FluentLayoutTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,18 @@
});

}

[Fact]
public void FluentLayout_InvalidArea()
{
// Arrange && Act
var cut = Render(@<FluentLayout GlobalScrollbar="false">
<FluentLayoutItem Area="(LayoutArea)999" Height="36px">Content</FluentLayoutItem>
<FluentLayoutItem Area="(LayoutArea)888" Height="42px" Sticky="true">Aside</FluentLayoutItem>
</FluentLayout>);

// Assert
Assert.Contains("style=\"height: 36px;\" area=\"\"", cut.Markup);
Assert.Contains("style=\"height: 42px;\" area=\"\"", cut.Markup);
}
}
6 changes: 4 additions & 2 deletions tests/Core/Components/Slack/FluentStackTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
[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)]
[InlineData("justify-content: start; align-items: end;", Orientation.Vertical, Fuib.HorizontalAlignment.Right)]
[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
Expand All @@ -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(@<FluentStack Orientation="@((Orientation)orientation)" VerticalAlignment="@alignment" />);
var styles = cut.Find("div").GetAttribute("style");

Output.WriteLine($"{orientation}, {alignment} => {styles}");

// Assert
Assert.Contains(expectedStyle, styles);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Core/Components/TextInput/FluentTextInputTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/Core/Migration/AppearanceExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down