Skip to content

Commit e7fced3

Browse files
committed
test(customize): add additional coverage for ThemeQuickPresets component
1 parent 4538996 commit e7fced3

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

app/customize/components/ThemeQuickPresets.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,39 @@ describe('ThemeQuickPresets', () => {
4949
await user.click(inactiveBtn);
5050
expect(onThemeChange).toHaveBeenCalledWith(inactiveKey);
5151
});
52+
53+
it('each button has an aria-label starting with "Apply"', () => {
54+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
55+
const buttons = screen.getAllByRole('button');
56+
buttons.forEach((btn) => {
57+
expect(btn.getAttribute('aria-label')).toMatch(/^Apply/i);
58+
});
59+
});
60+
61+
it('renders at least one button for each concrete theme excluding auto and random', () => {
62+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
63+
validKeys.forEach((key) => {
64+
const btn = screen.getByRole('button', {
65+
name: new RegExp(`apply ${key} theme`, 'i'),
66+
});
67+
expect(btn).toBeTruthy();
68+
});
69+
});
70+
71+
it('switching active theme updates aria-pressed correctly', () => {
72+
const { rerender } = render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
73+
const darkBtn = screen.getByRole('button', { name: /apply dark theme/i });
74+
expect(darkBtn.getAttribute('aria-pressed')).toBe('true');
75+
76+
rerender(<ThemeQuickPresets theme="neon" onThemeChange={onThemeChange} />);
77+
const neonBtn = screen.getByRole('button', { name: /apply neon theme/i });
78+
expect(neonBtn.getAttribute('aria-pressed')).toBe('true');
79+
expect(darkBtn.getAttribute('aria-pressed')).toBe('false');
80+
});
81+
82+
it('does not render buttons for auto or random themes', () => {
83+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
84+
expect(screen.queryByRole('button', { name: /apply auto theme/i })).toBeNull();
85+
expect(screen.queryByRole('button', { name: /apply random theme/i })).toBeNull();
86+
});
5287
});

0 commit comments

Comments
 (0)