diff --git a/tests/StaticInput.UnitTests.Viewer/Components/Layout/MainLayout.razor b/tests/StaticInput.UnitTests.Viewer/Components/Layout/MainLayout.razor index a5fe651..f0c9dd3 100644 --- a/tests/StaticInput.UnitTests.Viewer/Components/Layout/MainLayout.razor +++ b/tests/StaticInput.UnitTests.Viewer/Components/Layout/MainLayout.razor @@ -6,7 +6,7 @@ - Static Input Tests @@ -15,10 +15,10 @@ @foreach (var component in _testComponents.Keys) { - @foreach (var test in _testComponents[component]) + @foreach (var test in _testComponents[component]) { + Href="@Navigation.GetUriWithQueryParameter("Test", test.Name)"> @test.Name } @@ -48,7 +48,8 @@ }; private Dictionary> _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(); diff --git a/tests/StaticInput.UnitTests/Components/ButtonTests.cs b/tests/StaticInput.UnitTests/Components/ButtonTests.cs index d1d87cf..55498c9 100644 --- a/tests/StaticInput.UnitTests/Components/ButtonTests.cs +++ b/tests/StaticInput.UnitTests/Components/ButtonTests.cs @@ -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; @@ -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(); } diff --git a/tests/StaticInput.UnitTests/Components/CheckBoxTests.cs b/tests/StaticInput.UnitTests/Components/CheckBoxTests.cs index 2b4dd44..b5d6062 100644 --- a/tests/StaticInput.UnitTests/Components/CheckBoxTests.cs +++ b/tests/StaticInput.UnitTests/Components/CheckBoxTests.cs @@ -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; @@ -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 }); diff --git a/tests/StaticInput.UnitTests/Components/NavMenuTests.cs b/tests/StaticInput.UnitTests/Components/NavMenuTests.cs index 123a2b9..0292418 100644 --- a/tests/StaticInput.UnitTests/Components/NavMenuTests.cs +++ b/tests/StaticInput.UnitTests/Components/NavMenuTests.cs @@ -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"); diff --git a/tests/StaticInput.UnitTests/Components/SwitchTests.cs b/tests/StaticInput.UnitTests/Components/SwitchTests.cs index 6767e76..77486e6 100644 --- a/tests/StaticInput.UnitTests/Components/SwitchTests.cs +++ b/tests/StaticInput.UnitTests/Components/SwitchTests.cs @@ -1,4 +1,5 @@ using FluentAssertions; +using Microsoft.Playwright; using MudBlazor.StaticInput; using StaticInput.UnitTests.Fixtures; using StaticInput.UnitTests.Viewer.Components.Tests.Switch; @@ -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 }); diff --git a/tests/StaticInput.UnitTests/Components/TextFieldTests.cs b/tests/StaticInput.UnitTests/Components/TextFieldTests.cs index 6bb8586..a95fbf7 100644 --- a/tests/StaticInput.UnitTests/Components/TextFieldTests.cs +++ b/tests/StaticInput.UnitTests/Components/TextFieldTests.cs @@ -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; @@ -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(); @@ -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) => diff --git a/tests/StaticInput.UnitTests/TestSetup.cs b/tests/StaticInput.UnitTests/TestSetup.cs index f7e3462..0f038e6 100644 --- a/tests/StaticInput.UnitTests/TestSetup.cs +++ b/tests/StaticInput.UnitTests/TestSetup.cs @@ -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}")); }