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