Skip to content

Commit 65404ff

Browse files
committed
add an integration test to make sure dark mode toggling works through localstorage
1 parent 380b793 commit 65404ff

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
label={buttonText}
3636
icon={buttonIcon}
3737
on:click={cycleDarkModePreference}
38+
data-testid="dark-mode-icon-button"
3839
/>
3940
</Tooltip>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
// starts on day mode
23+
// const button = page.getByRole('button', { name: dayLabel });
24+
const button = page.getByTestId('dark-mode-icon-button');
25+
26+
await expect(button).toBeVisible();
27+
28+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
29+
null, // nothing in local storage yet
30+
);
31+
32+
// after day is system mode
33+
await button.click();
34+
await expect(button).toHaveAttribute('aria-label', systemDefaultLabel);
35+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
36+
JSON.stringify('system'),
37+
);
38+
39+
// after system is dark mode
40+
await button.click();
41+
await expect(button).toHaveAttribute('aria-label', nightLabel);
42+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
43+
JSON.stringify(true),
44+
);
45+
46+
// cycle back to day
47+
await button.click();
48+
await expect(button).toHaveAttribute('aria-label', dayLabel);
49+
expect(await page.evaluate(() => localStorage.getItem('dark mode'))).toBe(
50+
JSON.stringify(false),
51+
);
52+
});
53+
});

0 commit comments

Comments
 (0)