-
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.
Drawer test added with TestContextBase class
- Loading branch information
1 parent
99e3207
commit b33d229
Showing
3 changed files
with
101 additions
and
2 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,70 @@ | ||
// ----------------------------------------------------------------------- | ||
// SPDX-FileCopyrightText: 2024 Siemens AG | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// ----------------------------------------------------------------------- | ||
|
||
using Bunit; | ||
using Microsoft.AspNetCore.Components; | ||
using SiemensIXBlazor.Components; | ||
|
||
namespace SiemensIXBlazor.Tests | ||
{ | ||
public class DrawerTests : TestContextBase | ||
{ | ||
[Fact] | ||
public void DrawerRendersCorrectly() | ||
{ | ||
// Arrange | ||
var cut = RenderComponent<Drawer>( | ||
("Id", "testId"), | ||
("CloseOnClickOutside", true), | ||
("FullHeight", false), | ||
("MaxWidth", 28), | ||
("MinWidth", 16), | ||
("Show", true), | ||
("Width", 16) | ||
); | ||
|
||
// Assert | ||
cut.MarkupMatches("<ix-drawer minwidth=\"16\" id=\"testId\" show=\"\" close-on-click-outside=\"\" max-width=\"28\" min-width=\"16\" width=\"16\"></ix-drawer>"); | ||
} | ||
|
||
[Fact] | ||
public async Task ClosedEventWorks() | ||
{ | ||
// Arrange | ||
var closed = false; | ||
var cut = RenderComponent<Drawer>( | ||
("Id", "drawer"), | ||
("ClosedEvent", EventCallback.Factory.Create(this, () => closed = true)) | ||
); | ||
|
||
// Act | ||
await cut.Instance.Closed(); | ||
|
||
// Assert | ||
Assert.True(closed); | ||
} | ||
|
||
[Fact] | ||
public async Task OpenedEventWorks() | ||
{ | ||
// Arrange | ||
var opened = false; | ||
var cut = RenderComponent<Drawer>( | ||
("Id", "drawer"), | ||
("OpenedEvent", EventCallback.Factory.Create(this, () => opened = true)) | ||
); | ||
|
||
// Act | ||
await cut.Instance.Opened(); | ||
|
||
// Assert | ||
Assert.True(opened); | ||
} | ||
} | ||
} |
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,29 @@ | ||
// ----------------------------------------------------------------------- | ||
// SPDX-FileCopyrightText: 2024 Siemens AG | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// ----------------------------------------------------------------------- | ||
|
||
using Bunit; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.JSInterop; | ||
using Moq; | ||
|
||
namespace SiemensIXBlazor.Tests; | ||
|
||
public class TestContextBase : TestContext | ||
{ | ||
public TestContextBase() | ||
{ | ||
Mock<IJSRuntime> jsRuntimeMock = new(); | ||
Mock<IJSObjectReference> jsObjectReferenceMock = new(); | ||
|
||
// Mock of module import for JSRuntime | ||
jsRuntimeMock.Setup(x => x.InvokeAsync<IJSObjectReference>("import", It.IsAny<object[]>())) | ||
.Returns(new ValueTask<IJSObjectReference>(jsObjectReferenceMock.Object)); | ||
Services.AddSingleton(jsRuntimeMock.Object); | ||
} | ||
} |
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