Skip to content

Commit ea6d9c3

Browse files
committed
Add integration tests for dark mode toggle functionality on desktop and mobile
1 parent 781cf69 commit ea6d9c3

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

src/lib/components/dark-mode-navigation-button.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
tooltip={buttonText}
3434
label={buttonText}
3535
icon={buttonIcon}
36+
data-testid="dark-mode-navigation-button"
3637
/>

src/lib/holocene/navigation/navigation-button.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<div
2626
class="flex h-6 w-6 items-center after:absolute after:left-[calc(100%_+_1.5rem)] after:top-0 after:hidden after:h-8 after:items-center after:bg-slate-800 after:p-1 after:px-2 after:text-xs after:text-white after:content-[attr(data-tooltip)] group-data-[nav=closed]:hover:after:flex"
2727
data-tooltip={tooltip}
28+
aria-hidden="true"
2829
>
2930
<Icon name={icon} {animate} {active} />
3031
</div>

tests/integration/dark-mode-toggle.desktop.spec.ts renamed to tests/integration/dark-mode.desktop.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ test.describe('Dark Mode Toggle', () => {
2020
const dayLabel = 'Day';
2121

2222
// starts on day mode
23-
// const button = page.getByRole('button', { name: dayLabel });
2423
const button = page.getByTestId('dark-mode-icon-button');
2524

2625
await expect(button).toBeVisible();
@@ -31,21 +30,21 @@ test.describe('Dark Mode Toggle', () => {
3130

3231
// after day is system mode
3332
await button.click();
34-
await expect(button).toHaveAttribute('aria-label', systemDefaultLabel);
33+
await expect(button).toHaveAccessibleName(systemDefaultLabel);
3534
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
3635
JSON.stringify('system'),
3736
);
3837

3938
// after system is dark mode
4039
await button.click();
41-
await expect(button).toHaveAttribute('aria-label', nightLabel);
40+
await expect(button).toHaveAccessibleName(nightLabel);
4241
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
4342
JSON.stringify(true),
4443
);
4544

4645
// cycle back to day
4746
await button.click();
48-
await expect(button).toHaveAttribute('aria-label', dayLabel);
47+
await expect(button).toHaveAccessibleName(dayLabel);
4948
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
5049
JSON.stringify(false),
5150
);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
import {
4+
mockWorkflowsApis,
5+
waitForWorkflowsApis,
6+
} from '~/test-utilities/mock-apis';
7+
8+
test.describe('Dark Mode Toggle', () => {
9+
test.beforeEach(async ({ page }) => {
10+
await mockWorkflowsApis(page);
11+
await page.goto('/namespaces/default/workflows');
12+
await waitForWorkflowsApis(page, false);
13+
});
14+
15+
test('user can toggle dark mode between on, off, and system default', async ({
16+
page,
17+
}) => {
18+
const nightLabel = 'Night';
19+
const systemDefaultLabel = 'System Default';
20+
const dayLabel = 'Day';
21+
22+
// on mobile, the dark mode button is in the profile menu
23+
await page.getByTestId('nav-profile-button').click();
24+
25+
// starts on day mode
26+
const button = page.getByTestId('dark-mode-navigation-button');
27+
28+
await expect(button).toBeVisible();
29+
30+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
31+
null, // nothing in local storage yet
32+
);
33+
34+
// after day is system mode
35+
await button.click();
36+
await expect(button).toHaveAccessibleName(systemDefaultLabel);
37+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
38+
JSON.stringify('system'),
39+
);
40+
41+
// after system is dark mode
42+
await button.click();
43+
await expect(button).toHaveAccessibleName(nightLabel);
44+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
45+
JSON.stringify(true),
46+
);
47+
48+
// cycle back to day
49+
await button.click();
50+
await expect(button).toHaveAccessibleName(dayLabel);
51+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
52+
JSON.stringify(false),
53+
);
54+
});
55+
});

0 commit comments

Comments
 (0)