Skip to content

Commit

Permalink
CounterBadge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vnbaaij committed Oct 8, 2023
1 parent fda8c2b commit b4a3936
Show file tree
Hide file tree
Showing 14 changed files with 643 additions and 1,740 deletions.
2,108 changes: 368 additions & 1,740 deletions examples/Demo/Shared/Microsoft.Fast.Components.FluentUI.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">fluent-button<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">fluent-button<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--neutral-layer-1); color: var(--neutral-fill-inverse-rest); border: 1px solid var(--accent-fill-rest);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">fluent-button<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--neutral-foreground-rest); color: var(--neutral-fill-rest); border: 1px solid var(--neutral-foreground-rest);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--error); color: var(--neutral-fill-rest); border: 1px solid var(--error);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--neutral-layer-1); color: var(--neutral-fill-rest); border: 1px solid var(--neutral-layer-1);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--neutral-layer-1); color: var(--neutral-fill-rest); border: 1px solid var(--neutral-layer-1);" title="1" b-ilbjzymg2o="">1</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="10" b-ilbjzymg2o="">9+</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="10" b-ilbjzymg2o="">10</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="additional_class counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest);" title="10" b-ilbjzymg2o="">10</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

<div class="counterbadge-container" b-ilbjzymg2o="">childcontent<div class="counterbadge" style="left: 50%; bottom: 50%; background-color: var(--accent-fill-rest); color: var(--neutral-fill-rest); border: 1px solid var(--accent-fill-rest); background-color: red;" title="10" b-ilbjzymg2o="">10</div>
</div>
239 changes: 239 additions & 0 deletions tests/Core/CounterBadge/FluentCounterBadgeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
using Bunit;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Microsoft.Fast.Components.FluentUI.Tests.CounterBadge;

public class FluentCounterBadgeTests : TestBase
{
[Inject]
public GlobalState GlobalState { get; set; } = default!;

[Fact]
public void FluentCounterBadge_AttributesDefaultValues()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());
var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Theory]
[InlineData(Appearance.Accent)]
[InlineData(Appearance.Lightweight)]
[InlineData(Appearance.Neutral)]
public void FluentCounterBadge_AppearanceAttribute(Appearance appearance)
{
// Arrange &&
TestContext.Services.AddSingleton(new GlobalState());
var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.Appearance, appearance);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("fluent-button");
});

// Assert
cut.Verify(suffix: appearance.ToString());
}


[Fact]
public void FluentCounterBadge_WithAdditionalCssClass()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());
var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.Class, "additional_class");
parameters.Add(p => p.Count, 10);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_WithAdditionalStyle()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());
var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.Style, "background-color: red");
parameters.Add(p => p.Count, 10);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_ShowOverflowAttribute()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());

var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.ShowOverflow, true);
parameters.Add(p => p.Max, 9);
parameters.Add(p => p.Count, 10);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_BackgroundColorAndColorAttribute()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());
IRenderedComponent<FluentCounterBadge>? cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Accent);
parameters.Add(p => p.Color, Color.Fill);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_BackgroundColorNullAndColorSet()
{
// Arrange, Act && Assert
TestContext.Services.AddSingleton(new GlobalState());
Assert.Throws<ArgumentException>(() => TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, null);
parameters.Add(p => p.Color, Color.Fill);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
}));
}

[Fact]
public void FluentCounterBadge_BackgroundColorSetAndColorNull()
{
// Arrange, Act && Assert
TestContext.Services.AddSingleton(new GlobalState());
Assert.Throws<ArgumentException>(() => TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Accent);
parameters.Add(p => p.Color, null);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
}));
}

[Fact]
public void FluentCounterBadge_BackgroundColorCustom()
{
// Arrange, Act && Assert
TestContext.Services.AddSingleton(new GlobalState());
Assert.Throws<ArgumentException>(() => TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Custom);
parameters.Add(p => p.Color, Color.Custom);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
}));
}

[Fact]
public void FluentCounterBadge_AppearanceOutline()
{
// Arrange, Act && Assert
TestContext.Services.AddSingleton(new GlobalState());
Assert.Throws<ArgumentException>(() => TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.Appearance, Appearance.Outline);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
}));
}

[Fact]
public void FluentCounterBadge_ShowZeroAttribute()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());
var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.ShowZero, true);
parameters.Add(p => p.Count, 10);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_BackgroundColorLightweightLuminanceDark()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());

var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Lightweight);
parameters.Add(p => p.Color, Color.Fill);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_BackgroundColorLightweightLuminanceLight()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());

var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Lightweight);
parameters.Add(p => p.Color, Color.Fill);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}

[Fact]
public void FluentCounterBadge_BackgroundColorErrorLuminanceDark()
{
// Arrange && Act
TestContext.Services.AddSingleton(new GlobalState());

var cut = TestContext.RenderComponent<FluentCounterBadge>(parameters =>
{
parameters.Add(p => p.BackgroundColor, Color.Error);
parameters.Add(p => p.Color, Color.Fill);
parameters.Add(p => p.Count, 1);
parameters.AddChildContent("childcontent");
});

// Assert
cut.Verify();
}
}

0 comments on commit b4a3936

Please sign in to comment.