Skip to content

Commit 872c19d

Browse files
committed
test(ui): verify responsive rendering of ThemeQuickPresets
1 parent 4538996 commit 872c19d

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

app/customize/components/ThemeQuickPresets.test.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
2-
import { render, screen } from '@testing-library/react';
3-
import userEvent from '@testing-library/user-event';
2+
import { fireEvent, render, screen } from '@testing-library/react';
43
import { ThemeQuickPresets } from './ThemeQuickPresets';
54
import { THEME_KEYS } from '../types';
5+
import { themes } from '../../../lib/svg/themes';
66

77
const validKeys = THEME_KEYS.filter((k) => k !== 'auto' && k !== 'random');
88

@@ -40,13 +40,41 @@ describe('ThemeQuickPresets', () => {
4040
});
4141

4242
it('clicking a button calls onThemeChange with correct theme key', async () => {
43-
const user = userEvent.setup();
4443
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
4544
const inactiveKey = validKeys.find((k) => k !== 'dark')!;
4645
const inactiveBtn = screen.getByRole('button', {
4746
name: new RegExp(`apply ${inactiveKey} theme`, 'i'),
4847
});
49-
await user.click(inactiveBtn);
48+
fireEvent.click(inactiveBtn);
5049
expect(onThemeChange).toHaveBeenCalledWith(inactiveKey);
5150
});
5251
});
52+
53+
describe('ThemeQuickPresets responsive rendering', () => {
54+
const onThemeChange = vi.fn();
55+
56+
beforeEach(() => {
57+
onThemeChange.mockClear();
58+
});
59+
60+
it('renders every preset with accessible labels, high-contrast styling, and wrap layout', () => {
61+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
62+
63+
const presetButtons = screen.getAllByRole('button', { name: /apply .+ theme/i });
64+
expect(presetButtons).toHaveLength(validKeys.length);
65+
66+
expect(
67+
screen.getByRole('button', { name: /apply dark theme/i }).getAttribute('aria-pressed')
68+
).toBe('true');
69+
70+
const highContrastButton = screen.getByRole('button', { name: /apply highcontrast theme/i });
71+
expect(highContrastButton).toBeDefined();
72+
expect(highContrastButton.getAttribute('title')).toBe('Highcontrast');
73+
expect(highContrastButton.getAttribute('style')).toContain('rgb(10, 10, 10)');
74+
75+
const grid = highContrastButton.closest('div');
76+
expect(grid).not.toBeNull();
77+
expect(grid?.style.display).toBe('flex');
78+
expect(grid?.style.flexWrap).toBe('wrap');
79+
});
80+
});

0 commit comments

Comments
 (0)