|
1 | 1 | 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'; |
4 | 3 | import { ThemeQuickPresets } from './ThemeQuickPresets'; |
5 | 4 | import { THEME_KEYS } from '../types'; |
| 5 | +import { themes } from '../../../lib/svg/themes'; |
6 | 6 |
|
7 | 7 | const validKeys = THEME_KEYS.filter((k) => k !== 'auto' && k !== 'random'); |
8 | 8 |
|
@@ -40,13 +40,41 @@ describe('ThemeQuickPresets', () => { |
40 | 40 | }); |
41 | 41 |
|
42 | 42 | it('clicking a button calls onThemeChange with correct theme key', async () => { |
43 | | - const user = userEvent.setup(); |
44 | 43 | render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />); |
45 | 44 | const inactiveKey = validKeys.find((k) => k !== 'dark')!; |
46 | 45 | const inactiveBtn = screen.getByRole('button', { |
47 | 46 | name: new RegExp(`apply ${inactiveKey} theme`, 'i'), |
48 | 47 | }); |
49 | | - await user.click(inactiveBtn); |
| 48 | + fireEvent.click(inactiveBtn); |
50 | 49 | expect(onThemeChange).toHaveBeenCalledWith(inactiveKey); |
51 | 50 | }); |
52 | 51 | }); |
| 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