-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add ContentHeader component's unit tests.
- Loading branch information
1 parent
c1c00f2
commit 7b00a20
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Bunit; | ||
using Microsoft.AspNetCore.Components; | ||
using SiemensIXBlazor.Components; | ||
using SiemensIXBlazor.Components.Avatar; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class ContentHeaderTests: TestContextBase | ||
{ | ||
[Fact] | ||
public void ContentHeaderRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ContentHeader>(parameters => { | ||
parameters.Add(p => p.Id, "testId"); | ||
parameters.Add(p => p.HasBackButton, true); | ||
parameters.Add(p => p.HeaderSubTitle, "testHeaderSubTitle"); | ||
parameters.Add(p => p.HeaderTitle, "testHeaderTitle"); | ||
parameters.Add(p => p.Variant, Enums.ContentHeader.ContentHeaderVariant.primary); | ||
}); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-content-header id=\"testId\" has-back-button=\"\" header-title=\"testHeaderTitle\" header-subtitle=\"testHeaderSubTitle\" variant=\"primary\"></ix-content-header>"); | ||
} | ||
|
||
[Fact] | ||
public void ContentHeaderRendersChildContent() | ||
{ | ||
// Arrange | ||
var expectedContent = "Expected content"; | ||
|
||
// Act | ||
var cut = RenderComponent<ContentHeader>(parameters => parameters | ||
.Add(p => p.ChildContent, builder => | ||
{ | ||
builder.AddContent(0, expectedContent); | ||
})); | ||
|
||
// Assert | ||
Assert.Contains(expectedContent, cut.Markup); | ||
} | ||
|
||
[Fact] | ||
public void BackButtonClickedEventTriggeredCorrectly() | ||
{ | ||
// Arrange | ||
var eventTriggered = false; | ||
var cut = RenderComponent<ContentHeader>(parameters => parameters.Add(p => p.BackButtonClickedEvent, EventCallback.Factory.Create(this, () => eventTriggered = true))); | ||
|
||
// Act | ||
cut.Instance.BackButtonClickedEvent.InvokeAsync(true); | ||
|
||
// Assert | ||
Assert.True(eventTriggered); | ||
} | ||
|
||
} | ||
} |