Branchwell

Jotley / website / e2e / theme.spec.ts

1import { test, expect } from '@playwright/test';
2
3test.describe('Theme toggle', () => {
4 test('switches theme and persists across navigation', async ({ page }) => {
5 await page.goto('/');
6
7 const html = page.locator('html');
8 const surface = page.getByTestId('page-surface');
9 const darkButton = page.getByRole('button', { name: 'Dark theme' });
10 const lightButton = page.getByRole('button', { name: 'Light theme' });
11
12 await darkButton.click();
13 await expect(html).toHaveClass(/dark/);
14 await expect
15 .poll(async () => page.evaluate(() => localStorage.getItem('theme')))
16 .toBe('dark');
17 const darkBackground = await surface.evaluate((element) => getComputedStyle(element).backgroundColor);
18
19 await page.goto('/privacy');
20 await expect(html).toHaveClass(/dark/);
21
22 await lightButton.click();
23 await expect(html).not.toHaveClass(/dark/);
24 await expect
25 .poll(async () => page.evaluate(() => localStorage.getItem('theme')))
26 .toBe('light');
27 await page.goto('/');
28 const lightBackground = await surface.evaluate((element) => getComputedStyle(element).backgroundColor);
29 expect(lightBackground).not.toBe(darkBackground);
30
31 await page.goto('/tos');
32 await expect(html).not.toHaveClass(/dark/);
33 });
34});
35
36test.describe('Light theme contrast', () => {
37 test.beforeEach(async ({ page }) => {
38 // Set light theme before each test
39 await page.goto('/');
40 await page.getByRole('button', { name: 'Light theme' }).click();
41 await expect(page.locator('html')).not.toHaveClass(/dark/);
42 });
43
44 test('homepage has readable text in light mode', async ({ page }) => {
45 await page.goto('/');
46
47 // Check that main heading is visible
48 const heading = page.getByRole('heading', { name: /every word/i });
49 await expect(heading).toBeVisible();
50
51 // Check that heading text has good contrast (not white on white)
52 const headingColor = await heading.evaluate((el) => {
53 const style = getComputedStyle(el);
54 return style.color;
55 });
56 // Should not be white (rgb(255, 255, 255))
57 expect(headingColor).not.toBe('rgb(255, 255, 255)');
58
59 // Check free app section heading is visible
60 const freeAppHeading = page.getByRole('heading', { name: /completely free\. open source/i });
61 await expect(freeAppHeading).toBeVisible();
62 });
63
64 test('download page has readable text in light mode', async ({ page }) => {
65 await page.goto('/download');
66
67 // Check main heading
68 const heading = page.getByRole('heading', { name: /how to install jotley for mac/i });
69 await expect(heading).toBeVisible();
70
71 // Verify step cards are visible
72 await expect(page.getByRole('heading', { name: 'Open DMG, Drag to Applications & Launch' })).toBeVisible();
73 });
74
75 test('support page has readable text in light mode', async ({ page }) => {
76 await page.goto('/support');
77 await expect(page.getByRole('heading', { name: 'Support', exact: true })).toBeVisible();
78 await expect(page.getByRole('heading', { name: 'Send feedback or report a bug', exact: true })).toBeVisible();
79 });
80});