|
| 1 | +import { test, expect, selectors, getCSSVariable, getThemeAttribute, goToThemedPage, themeColors } from '../fixtures/setup'; |
| 2 | + |
| 3 | +test.describe('Component Styles - Light Mode', () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await goToThemedPage(page); |
| 6 | + expect(await getThemeAttribute(page)).toBe('light'); |
| 7 | + }); |
| 8 | + |
| 9 | + test('header has correct light mode colors', async ({ page }) => { |
| 10 | + const bgColor = await getCSSVariable(page, '--color-bg-main'); |
| 11 | + expect(bgColor).toBe(themeColors.light['--color-bg-main']); |
| 12 | + }); |
| 13 | + |
| 14 | + test('body text uses light mode color', async ({ page }) => { |
| 15 | + const textColor = await getCSSVariable(page, '--color-text-main'); |
| 16 | + expect(textColor).toBe(themeColors.light['--color-text-main']); |
| 17 | + }); |
| 18 | + |
| 19 | + test('border uses light mode color', async ({ page }) => { |
| 20 | + const borderColor = await getCSSVariable(page, '--color-line-gray'); |
| 21 | + expect(borderColor).toBe(themeColors.light['--color-line-gray']); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +test.describe('Component Styles - Dark Mode', () => { |
| 26 | + test.beforeEach(async ({ page }) => { |
| 27 | + await goToThemedPage(page); |
| 28 | + await page.click(selectors.themeToggleButton); |
| 29 | + expect(await getThemeAttribute(page)).toBe('dark'); |
| 30 | + }); |
| 31 | + |
| 32 | + test('background uses dark mode color', async ({ page }) => { |
| 33 | + const bgColor = await getCSSVariable(page, '--color-bg-main'); |
| 34 | + expect(bgColor).toBe(themeColors.dark['--color-bg-main']); |
| 35 | + }); |
| 36 | + |
| 37 | + test('text uses dark mode color', async ({ page }) => { |
| 38 | + const textColor = await getCSSVariable(page, '--color-text-main'); |
| 39 | + expect(textColor).toBe(themeColors.dark['--color-text-main']); |
| 40 | + }); |
| 41 | + |
| 42 | + test('border uses dark mode color', async ({ page }) => { |
| 43 | + const borderColor = await getCSSVariable(page, '--color-line-gray'); |
| 44 | + expect(borderColor).toBe(themeColors.dark['--color-line-gray']); |
| 45 | + }); |
| 46 | + |
| 47 | + test('background light variable uses dark mode value', async ({ page }) => { |
| 48 | + const bgLight = await getCSSVariable(page, '--color-bg-light'); |
| 49 | + expect(bgLight).toBe(themeColors.dark['--color-bg-light']); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +test.describe('Rendered Element Colors', () => { |
| 54 | + test('body background is dark in dark mode', async ({ page }) => { |
| 55 | + await goToThemedPage(page); |
| 56 | + await page.click(selectors.themeToggleButton); |
| 57 | + |
| 58 | + const bodyBg = await page.evaluate(() => getComputedStyle(document.body).backgroundColor); |
| 59 | + expect(bodyBg).toBe('rgb(24, 24, 27)'); |
| 60 | + }); |
| 61 | + |
| 62 | + test('body background is white in light mode', async ({ page }) => { |
| 63 | + await goToThemedPage(page); |
| 64 | + |
| 65 | + const bodyBg = await page.evaluate(() => getComputedStyle(document.body).backgroundColor); |
| 66 | + expect(bodyBg).toBe('rgb(255, 255, 255)'); |
| 67 | + }); |
| 68 | + |
| 69 | + test('header background is dark in dark mode', async ({ page }) => { |
| 70 | + await goToThemedPage(page); |
| 71 | + await page.click(selectors.themeToggleButton); |
| 72 | + |
| 73 | + const headerBg = await page.evaluate(() => { |
| 74 | + const header = document.querySelector('header.docs-header'); |
| 75 | + return header ? getComputedStyle(header).backgroundColor : ''; |
| 76 | + }); |
| 77 | + expect(headerBg).toBe('rgb(24, 24, 27)'); |
| 78 | + }); |
| 79 | + |
| 80 | + test('header background is white in light mode', async ({ page }) => { |
| 81 | + await goToThemedPage(page); |
| 82 | + |
| 83 | + const headerBg = await page.evaluate(() => { |
| 84 | + const header = document.querySelector('header.docs-header'); |
| 85 | + return header ? getComputedStyle(header).backgroundColor : ''; |
| 86 | + }); |
| 87 | + expect(headerBg).toBe('rgb(255, 255, 255)'); |
| 88 | + }); |
| 89 | + |
| 90 | + test('body text color changes in dark mode', async ({ page }) => { |
| 91 | + await goToThemedPage(page); |
| 92 | + await page.click(selectors.themeToggleButton); |
| 93 | + |
| 94 | + const bodyColor = await page.evaluate(() => getComputedStyle(document.body).color); |
| 95 | + expect(bodyColor).toBe('rgb(228, 228, 231)'); |
| 96 | + }); |
| 97 | +}); |
| 98 | + |
| 99 | +test.describe('Component Styles - Toggle Consistency', () => { |
| 100 | + test('all CSS variables update when toggling from light to dark', async ({ page }) => { |
| 101 | + await goToThemedPage(page); |
| 102 | + |
| 103 | + // Verify light mode variables |
| 104 | + for (const [variable, expected] of Object.entries(themeColors.light)) { |
| 105 | + const value = await getCSSVariable(page, variable); |
| 106 | + expect(value, `Light mode ${variable}`).toBe(expected); |
| 107 | + } |
| 108 | + |
| 109 | + // Toggle to dark |
| 110 | + await page.click(selectors.themeToggleButton); |
| 111 | + |
| 112 | + // Verify dark mode variables |
| 113 | + for (const [variable, expected] of Object.entries(themeColors.dark)) { |
| 114 | + const value = await getCSSVariable(page, variable); |
| 115 | + expect(value, `Dark mode ${variable}`).toBe(expected); |
| 116 | + } |
| 117 | + }); |
| 118 | + |
| 119 | + test('auth form is visible in both themes', async ({ page }) => { |
| 120 | + await goToThemedPage(page); |
| 121 | + const form = page.locator(selectors.authForm); |
| 122 | + await expect(form).toBeVisible(); |
| 123 | + |
| 124 | + // Toggle to dark |
| 125 | + await page.click(selectors.themeToggleButton); |
| 126 | + await expect(form).toBeVisible(); |
| 127 | + }); |
| 128 | + |
| 129 | + test('header remains visible after theme switch', async ({ page }) => { |
| 130 | + await goToThemedPage(page); |
| 131 | + const header = page.locator(selectors.header); |
| 132 | + await expect(header).toBeVisible(); |
| 133 | + |
| 134 | + await page.click(selectors.themeToggleButton); |
| 135 | + await expect(header).toBeVisible(); |
| 136 | + }); |
| 137 | + |
| 138 | + test('toggle button icon swaps correctly on multiple toggles', async ({ page }) => { |
| 139 | + await goToThemedPage(page); |
| 140 | + const sunIcon = page.locator(selectors.sunIcon); |
| 141 | + const moonIcon = page.locator(selectors.moonIcon); |
| 142 | + |
| 143 | + // Light → sun visible |
| 144 | + await expect(sunIcon).toHaveCSS('display', 'block'); |
| 145 | + await expect(moonIcon).toHaveCSS('display', 'none'); |
| 146 | + |
| 147 | + // Toggle 1: dark → moon visible |
| 148 | + await page.click(selectors.themeToggleButton); |
| 149 | + await expect(sunIcon).toHaveCSS('display', 'none'); |
| 150 | + await expect(moonIcon).toHaveCSS('display', 'block'); |
| 151 | + |
| 152 | + // Toggle 2: light → sun visible |
| 153 | + await page.click(selectors.themeToggleButton); |
| 154 | + await expect(sunIcon).toHaveCSS('display', 'block'); |
| 155 | + await expect(moonIcon).toHaveCSS('display', 'none'); |
| 156 | + |
| 157 | + // Toggle 3: dark → moon visible |
| 158 | + await page.click(selectors.themeToggleButton); |
| 159 | + await expect(sunIcon).toHaveCSS('display', 'none'); |
| 160 | + await expect(moonIcon).toHaveCSS('display', 'block'); |
| 161 | + }); |
| 162 | +}); |
0 commit comments