Skip to content

Commit 167abe2

Browse files
committed
rework tests
1 parent ee0861c commit 167abe2

7 files changed

Lines changed: 26 additions & 13 deletions

File tree

tests/StaticInput.UnitTests.Viewer/Components/Layout/MainLayout.razor

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<MudLayout Style="height:100vh">
88
<MudDrawerContainer>
9-
<MudDrawer Open Fixed Elevation="1" Class="px-4" Style="width:auto"
9+
<MudDrawer Open Fixed Elevation="1" Class="@_class" Style="width:auto"
1010
Breakpoint="Breakpoint.None" Variant="DrawerVariant.Persistent" ClipMode="DrawerClipMode.Docked">
1111
<MudDrawerHeader>
1212
<MudText Typo="Typo.h6">Static Input Tests</MudText>
@@ -15,10 +15,10 @@
1515
@foreach (var component in _testComponents.Keys)
1616
{
1717
<MudStaticNavGroup Title="@component">
18-
@foreach (var test in _testComponents[component])
18+
@foreach (var test in _testComponents[component])
1919
{
2020
<MudNavLink @key="test.Name" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.List"
21-
Href="@Navigation.GetUriWithQueryParameter("Test", test.Name)">
21+
Href="@Navigation.GetUriWithQueryParameter("Test", test.Name)">
2222
@test.Name
2323
</MudNavLink>
2424
}
@@ -48,7 +48,8 @@
4848
};
4949

5050
private Dictionary<string, List<Type>> _testComponents = new();
51-
51+
private string _class = Environment.GetEnvironmentVariable("TEST_ENVIRONMENT")?.Equals("true") is true ? "d-none" : "px-4";
52+
5253
protected override void OnInitialized()
5354
{
5455
var availableComponentTypes = GetTestComponentTypes().ToArray();

tests/StaticInput.UnitTests/Components/ButtonTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Bunit.TestDoubles;
33
using FluentAssertions;
44
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Playwright;
56
using MudBlazor.StaticInput;
67
using StaticInput.UnitTests.Fixtures;
78
using StaticInput.UnitTests.Viewer.Components.Tests.Button;
@@ -110,7 +111,7 @@ public async Task ResetButton_Should_Clear_Form()
110111
await input.FillAsync(email);
111112
await Expect(input).ToHaveValueAsync(email);
112113

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

115116
await Expect(input).ToBeEmptyAsync();
116117
}

tests/StaticInput.UnitTests/Components/CheckBoxTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AngleSharp.Css.Dom;
22
using Bunit;
33
using FluentAssertions;
4+
using Microsoft.Playwright;
45
using MudBlazor.StaticInput;
56
using StaticInput.UnitTests.Fixtures;
67
using StaticInput.UnitTests.Viewer.Components.Tests.CheckBox;
@@ -107,7 +108,7 @@ public async Task CheckBox_Should_Checked_To_Submit()
107108
await Page.GotoAsync(url);
108109

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

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

tests/StaticInput.UnitTests/Components/NavMenuTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public async Task Group_Collapses_Expands_On_Click()
1313

1414
await Page.GotoAsync(url);
1515

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

1922
var menuClasses = await menuGroup.GetAttributeAsync("class");
2023
var ariaValue = await menuGroup.GetAttributeAsync("aria-hidden");

tests/StaticInput.UnitTests/Components/SwitchTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FluentAssertions;
2+
using Microsoft.Playwright;
23
using MudBlazor.StaticInput;
34
using StaticInput.UnitTests.Fixtures;
45
using StaticInput.UnitTests.Viewer.Components.Tests.Switch;
@@ -98,7 +99,7 @@ public async Task Switch_Should_BeSelected_To_Submit()
9899
await Page.GotoAsync(url);
99100

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

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

tests/StaticInput.UnitTests/Components/TextFieldTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Bunit;
22
using FluentAssertions;
3+
using Microsoft.Playwright;
34
using MudBlazor.StaticInput;
45
using StaticInput.UnitTests.Fixtures;
56
using StaticInput.UnitTests.Viewer.Components.Tests.TextField;
@@ -164,7 +165,7 @@ public async Task TextField_DataAnnotations_Are_Functional()
164165
await Page.GotoAsync(url);
165166

166167
var field = Page.GetByLabel("Short string");
167-
var button = Page.Locator("button");
168+
var button = Page.GetByRole(AriaRole.Button, new() { Name = "Validate" });
168169

169170
await button.ClickAsync();
170171

@@ -212,7 +213,7 @@ public async Task TextField_AdornmentButton_IsClickable()
212213

213214
await Page.GotoAsync(url);
214215

215-
var button = Page.Locator("button");
216+
var button = Page.GetByRole(AriaRole.Button);
216217
var message = string.Empty;
217218

218219
Page.Dialog += async (_, dialog) =>

tests/StaticInput.UnitTests/TestSetup.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ public TestSetup(IMessageSink messageSink) : base(messageSink)
1818
process.Kill();
1919
}
2020

21-
_testViewerProcess = Process.Start(new ProcessStartInfo()
21+
var startInfo = new ProcessStartInfo()
2222
{
2323
FileName = "dotnet",
2424
Arguments = $"run --project {GetProjectPath()}"
25-
});
25+
};
26+
27+
startInfo.EnvironmentVariables.Add("TEST_ENVIRONMENT", "true");
28+
29+
30+
_testViewerProcess = Process.Start(startInfo);
2631

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

0 commit comments

Comments
 (0)