-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: master to test/gokce-unitTest
- Loading branch information
Showing
58 changed files
with
1,990 additions
and
93 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,103 @@ | ||
using System.Diagnostics; | ||
using Bunit; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.JSInterop; | ||
using Moq; | ||
using SiemensIXBlazor.Components.AGGrid; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class AGGridTests : TestContextBase | ||
{ | ||
[Fact] | ||
public void ComponentRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<AGGrid>(); | ||
|
||
// Assert | ||
cut.MarkupMatches("<div id=''></div>"); | ||
} | ||
|
||
[Fact] | ||
public void OnCellClickedPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var eventTriggered = false; | ||
var cut = RenderComponent<AGGrid>(parameters => parameters.Add(p => p.OnCellClicked, EventCallback.Factory.Create(this, () => eventTriggered = true))); | ||
|
||
// Act | ||
cut.Instance.OnCellClicked.InvokeAsync(true); | ||
|
||
//Assert | ||
Assert.True(eventTriggered); | ||
} | ||
|
||
[Fact] | ||
public void IdPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<AGGrid>(parameters => parameters.Add(p => p.Id, "testId")); | ||
|
||
// Assert | ||
Assert.Equal("testId", cut.Instance.Id); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateGrid_ReturnsNull_WhenIdIsEmpty() | ||
{ | ||
// Arrange | ||
var grid = new AGGrid(); | ||
|
||
// Act | ||
var result = await grid.CreateGrid(new GridOptions()); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateGrid_ReturnsJSObjectReference_WhenIdIsNotEmpty() | ||
{ | ||
// Arrange | ||
var gridOptions = new GridOptions(); | ||
Mock<IJSRuntime> jsRuntimeMock = new(); | ||
Mock<IJSObjectReference> jsObjectReferenceMock = new(); | ||
|
||
// Mock of module import for JSRuntime | ||
jsRuntimeMock.Setup(x => x.InvokeAsync<IJSObjectReference>("agGridInterop.createGrid", It.IsAny<object[]>())) | ||
.Returns(new ValueTask<IJSObjectReference>(jsObjectReferenceMock.Object)); | ||
Services.AddSingleton(jsRuntimeMock.Object); | ||
|
||
var cut = RenderComponent<AGGrid>(parameters => parameters.Add(p => p.Id, "testId")); | ||
|
||
// Act | ||
var result = await cut.Instance.CreateGrid(gridOptions); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("agGridInterop.createGrid", It.IsAny<object[]>()), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task GetSelectedRows_ReturnsObject() | ||
{ | ||
// Arrange | ||
var jsRuntimeMock = new Mock<IJSRuntime>(); | ||
Services.AddSingleton(jsRuntimeMock.Object); | ||
var cut = RenderComponent<AGGrid>(parameters => parameters.Add(p => p.Id, "testId")); | ||
var jsObjectReferenceMock = new Mock<IJSObjectReference>(); | ||
jsRuntimeMock.Setup(x => x.InvokeAsync<object>("agGridInterop.getSelectedRows", It.IsAny<object[]>())) | ||
.ReturnsAsync(new object()); | ||
|
||
|
||
// Act | ||
var result = await cut.Instance.GetSelectedRows(jsObjectReferenceMock.Object); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("agGridInterop.getSelectedRows", It.IsAny<object[]>()), Times.Once); | ||
} | ||
} | ||
} |
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
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
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
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,69 @@ | ||
using Bunit; | ||
using SiemensIXBlazor.Components; | ||
using SiemensIXBlazor.Enums.PushCard; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class ActionCardTests: TestContextBase | ||
{ | ||
[Fact] | ||
public void ComponentRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-action-card variant='insight'></ix-action-card>"); | ||
} | ||
|
||
[Fact] | ||
public void IconPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(parameters => parameters.Add(p => p.Icon, "testIcon")); | ||
|
||
// Assert | ||
Assert.Equal("testIcon", cut.Instance.Icon); | ||
} | ||
|
||
[Fact] | ||
public void HeadingPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(parameters => parameters.Add(p => p.Heading, "testHeading")); | ||
|
||
// Assert | ||
Assert.Equal("testHeading", cut.Instance.Heading); | ||
} | ||
|
||
[Fact] | ||
public void SubHeadingPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(parameters => parameters.Add(p => p.SubHeading, "testSubHeading")); | ||
|
||
// Assert | ||
Assert.Equal("testSubHeading", cut.Instance.SubHeading); | ||
} | ||
|
||
[Fact] | ||
public void SelectedPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(parameters => parameters.Add(p => p.Selected, true)); | ||
|
||
// Assert | ||
Assert.True(cut.Instance.Selected); | ||
} | ||
|
||
[Fact] | ||
public void VariantPropertyIsSetCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ActionCard>(parameters => parameters.Add(p => p.Variant, PushCardVariant.insight)); | ||
|
||
// Assert | ||
Assert.Equal(PushCardVariant.insight, cut.Instance.Variant); | ||
} | ||
} | ||
} |
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,37 @@ | ||
using Bunit; | ||
using SiemensIXBlazor.Components; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class ApplicationHeaderTests : TestContextBase | ||
{ | ||
[Fact] | ||
public void ApplicationHeaderRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<ApplicationHeader>(parameters => { | ||
parameters.Add(p => p.Name, "testName"); | ||
}); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-application-header name='testName'></ix-application-header>"); | ||
} | ||
|
||
[Fact] | ||
public void ApplicationHeaderRendersChildContent() | ||
{ | ||
// Arrange | ||
var expectedContent = "Expected content"; | ||
|
||
// Act | ||
var cut = RenderComponent<ApplicationHeader>(parameters => parameters | ||
.Add(p => p.ChildContent, builder => | ||
{ | ||
builder.AddContent(0, expectedContent); | ||
})); | ||
|
||
// Assert | ||
Assert.Contains(expectedContent, cut.Markup); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using Bunit; | ||
using SiemensIXBlazor.Components; | ||
using SiemensIXBlazor.Objects.Application; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class ApplicationTests : TestContextBase | ||
{ | ||
[Fact] | ||
public void ApplicationRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<Application>(parameters => { | ||
parameters.Add(p => p.Id, "testId"); | ||
parameters.Add(p => p.Breakpoints, ["sm", "md", "lg"]); | ||
parameters.Add(p => p.ForceBreakpoint, Enums.ForceBreakpoint.lg); | ||
parameters.Add(p => p.Theme, "testTheme"); | ||
parameters.Add(p => p.ThemeSystemAppearance, true); | ||
}); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-application id='testId' breakpoints=\"['sm','md','lg']\" force-breakpoint='lg' theme='testTheme' theme-system-appearance=''></ix-application>"); | ||
} | ||
|
||
[Fact] | ||
public void AppSwitchConfig_SetsValueAndCallsInitialParameter() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<Application>(); | ||
var config = new AppSwitchConfig(); | ||
|
||
// Act | ||
cut.Instance.AppSwitchConfig = config; | ||
|
||
// Assert | ||
Assert.Equal(config, cut.Instance.AppSwitchConfig); | ||
} | ||
|
||
} | ||
} |
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,21 @@ | ||
using Bunit; | ||
using SiemensIXBlazor.Components.Avatar; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class AvatarTests : TestContextBase | ||
{ | ||
[Fact] | ||
public void AvatarRendersWithoutCrashing() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<Avatar>(parameters => { | ||
parameters.Add(p => p.Image, "testImage"); | ||
parameters.Add(p => p.Initials, "testInitials"); | ||
}); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-avatar image='testImage' initials='testInitials'></ix-avatar>"); | ||
} | ||
} | ||
} |
Oops, something went wrong.