-
Notifications
You must be signed in to change notification settings - Fork 475
/
AppBarTests.cs
110 lines (88 loc) · 4.57 KB
/
AppBarTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Dashboard.Resources;
using Aspire.Dashboard.Tests.Integration.Playwright.Infrastructure;
using Aspire.Workload.Tests;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Playwright;
using Xunit;
namespace Aspire.Dashboard.Tests.Integration.Playwright;
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))]
public class AppBarTests : PlaywrightTestsBase<DashboardServerFixture>
{
public AppBarTests(DashboardServerFixture dashboardServerFixture)
: base(dashboardServerFixture)
{
}
[Fact]
public async Task AppBar_Change_Theme()
{
// Arrange
await RunTestAsync(async page =>
{
await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page).DefaultTimeout();
await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null).DefaultTimeout(); // don't guess system theme
await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light").DefaultTimeout();
await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark").DefaultTimeout();
async Task SetAndVerifyTheme(string checkboxText, string? expected)
{
var settingsButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutLaunchSettings });
await settingsButton.ClickAsync();
// Set theme
var checkbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(checkboxText)).First;
await checkbox.ClickAsync();
if (expected != null)
{
await Assertions
.Expect(page.Locator("html"))
.ToHaveAttributeAsync("data-theme", expected);
}
// Close settings.
var closeButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutSettingsDialogClose });
await closeButton.First.ClickAsync();
// Re-open settings and assert that the correct checkbox is checked.
await settingsButton.ClickAsync();
checkbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(checkboxText)).First;
await AsyncTestHelpers.AssertIsTrueRetryAsync(
async () => await checkbox.IsCheckedAsync(),
"Checkbox isn't immediately checked.");
await closeButton.First.ClickAsync();
}
});
}
[Fact]
public async Task AppBar_Change_Theme_ReloadPage()
{
// Arrange
await RunTestAsync(async page =>
{
await SetAndVerifyTheme(Dialogs.SettingsDialogSystemTheme, null).DefaultTimeout(); // don't guess system theme
await SetAndVerifyTheme(Dialogs.SettingsDialogLightTheme, "light").DefaultTimeout();
await SetAndVerifyTheme(Dialogs.SettingsDialogDarkTheme, "dark").DefaultTimeout();
async Task SetAndVerifyTheme(string checkboxText, string? expected)
{
await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page);
var settingsButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutLaunchSettings });
await settingsButton.ClickAsync();
// Set theme
var checkbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(checkboxText)).First;
await checkbox.ClickAsync();
if (expected != null)
{
await Assertions
.Expect(page.Locator("html"))
.ToHaveAttributeAsync("data-theme", expected);
}
// Reload page.
await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page);
// Re-open settings and assert that the correct checkbox is checked.
settingsButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutLaunchSettings });
await settingsButton.ClickAsync();
checkbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(checkboxText)).First;
await AsyncTestHelpers.AssertIsTrueRetryAsync(
async () => await checkbox.IsCheckedAsync(),
"Checkbox isn't immediately checked.");
}
});
}
}