Skip to content

Commit

Permalink
rework tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anu6is committed Dec 20, 2024
1 parent ee0861c commit 167abe2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<MudLayout Style="height:100vh">
<MudDrawerContainer>
<MudDrawer Open Fixed Elevation="1" Class="px-4" Style="width:auto"
<MudDrawer Open Fixed Elevation="1" Class="@_class" Style="width:auto"
Breakpoint="Breakpoint.None" Variant="DrawerVariant.Persistent" ClipMode="DrawerClipMode.Docked">
<MudDrawerHeader>
<MudText Typo="Typo.h6">Static Input Tests</MudText>
Expand All @@ -15,10 +15,10 @@
@foreach (var component in _testComponents.Keys)
{
<MudStaticNavGroup Title="@component">
@foreach (var test in _testComponents[component])
@foreach (var test in _testComponents[component])
{
<MudNavLink @key="test.Name" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.List"
Href="@Navigation.GetUriWithQueryParameter("Test", test.Name)">
Href="@Navigation.GetUriWithQueryParameter("Test", test.Name)">
@test.Name
</MudNavLink>
}
Expand Down Expand Up @@ -48,7 +48,8 @@
};

private Dictionary<string, List<Type>> _testComponents = new();

private string _class = Environment.GetEnvironmentVariable("TEST_ENVIRONMENT")?.Equals("true") is true ? "d-none" : "px-4";

protected override void OnInitialized()
{
var availableComponentTypes = GetTestComponentTypes().ToArray();
Expand Down
3 changes: 2 additions & 1 deletion tests/StaticInput.UnitTests/Components/ButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Bunit.TestDoubles;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Playwright;
using MudBlazor.StaticInput;
using StaticInput.UnitTests.Fixtures;
using StaticInput.UnitTests.Viewer.Components.Tests.Button;
Expand Down Expand Up @@ -110,7 +111,7 @@ public async Task ResetButton_Should_Clear_Form()
await input.FillAsync(email);
await Expect(input).ToHaveValueAsync(email);

await Page.Locator("button").ClickAsync();
await Page.GetByRole(AriaRole.Button, new() { Name = "Reset" }).ClickAsync();

await Expect(input).ToBeEmptyAsync();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/StaticInput.UnitTests/Components/CheckBoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AngleSharp.Css.Dom;
using Bunit;
using FluentAssertions;
using Microsoft.Playwright;
using MudBlazor.StaticInput;
using StaticInput.UnitTests.Fixtures;
using StaticInput.UnitTests.Viewer.Components.Tests.CheckBox;
Expand Down Expand Up @@ -107,7 +108,7 @@ public async Task CheckBox_Should_Checked_To_Submit()
await Page.GotoAsync(url);

var checkbox = Page.Locator("input[type='checkbox']");
var button = Page.Locator("button");
var button = Page.GetByRole(AriaRole.Button, new() { Name = "Submit" });

await Expect(checkbox).ToBeCheckedAsync(new() { Checked = false });

Expand Down
7 changes: 5 additions & 2 deletions tests/StaticInput.UnitTests/Components/NavMenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public async Task Group_Collapses_Expands_On_Click()

await Page.GotoAsync(url);

var button = Page.Locator("nav button");
var menuGroup = Page.Locator(".mud-collapse-container");
var button = Page.GetByLabel("Toggle Settings");
var menuGroup = Page.GetByLabel("Settings", new() { Exact = true })
.Locator("div")
.Filter(new() { HasText = "Users Security" })
.First;

var menuClasses = await menuGroup.GetAttributeAsync("class");
var ariaValue = await menuGroup.GetAttributeAsync("aria-hidden");
Expand Down
3 changes: 2 additions & 1 deletion tests/StaticInput.UnitTests/Components/SwitchTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Microsoft.Playwright;
using MudBlazor.StaticInput;
using StaticInput.UnitTests.Fixtures;
using StaticInput.UnitTests.Viewer.Components.Tests.Switch;
Expand Down Expand Up @@ -98,7 +99,7 @@ public async Task Switch_Should_BeSelected_To_Submit()
await Page.GotoAsync(url);

var checkbox = Page.Locator("input[type='checkbox']");
var button = Page.Locator("button");
var button = Page.GetByRole(AriaRole.Button, new() { Name = "Submit" });

await Expect(checkbox).ToBeCheckedAsync(new() { Checked = false });

Expand Down
5 changes: 3 additions & 2 deletions tests/StaticInput.UnitTests/Components/TextFieldTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bunit;
using FluentAssertions;
using Microsoft.Playwright;
using MudBlazor.StaticInput;
using StaticInput.UnitTests.Fixtures;
using StaticInput.UnitTests.Viewer.Components.Tests.TextField;
Expand Down Expand Up @@ -164,7 +165,7 @@ public async Task TextField_DataAnnotations_Are_Functional()
await Page.GotoAsync(url);

var field = Page.GetByLabel("Short string");
var button = Page.Locator("button");
var button = Page.GetByRole(AriaRole.Button, new() { Name = "Validate" });

await button.ClickAsync();

Expand Down Expand Up @@ -212,7 +213,7 @@ public async Task TextField_AdornmentButton_IsClickable()

await Page.GotoAsync(url);

var button = Page.Locator("button");
var button = Page.GetByRole(AriaRole.Button);
var message = string.Empty;

Page.Dialog += async (_, dialog) =>
Expand Down
9 changes: 7 additions & 2 deletions tests/StaticInput.UnitTests/TestSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ public TestSetup(IMessageSink messageSink) : base(messageSink)
process.Kill();
}

_testViewerProcess = Process.Start(new ProcessStartInfo()
var startInfo = new ProcessStartInfo()
{
FileName = "dotnet",
Arguments = $"run --project {GetProjectPath()}"
});
};

startInfo.EnvironmentVariables.Add("TEST_ENVIRONMENT", "true");


_testViewerProcess = Process.Start(startInfo);

messageSink.OnMessage(new DiagnosticMessage($"Started {_testViewerProcess?.ProcessName} with ID: {_testViewerProcess?.Id}"));
}
Expand Down

0 comments on commit 167abe2

Please sign in to comment.