Skip to content

Commit 0d1ade5

Browse files
committed
test(ThemeQuickPresets): add responsive and high-contrast preset coverage
1 parent 2da01d1 commit 0d1ade5

1 file changed

Lines changed: 53 additions & 7 deletions

File tree

app/customize/components/ThemeQuickPresets.test.tsx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,77 @@ describe('ThemeQuickPresets', () => {
8686
});
8787
});
8888

89-
describe('ThemeQuickPresets responsive rendering', () => {
89+
describe('ThemeQuickPresets responsive rendering & high-contrast', () => {
9090
const onThemeChange = vi.fn();
9191

9292
beforeEach(() => {
9393
onThemeChange.mockClear();
9494
});
9595

96-
it('renders every preset with accessible labels, high-contrast styling, and wrap layout', () => {
96+
it('checks rendering of preset buttons on sm and lg viewports', () => {
97+
window.innerWidth = 375;
98+
window.dispatchEvent(new Event('resize'));
99+
100+
const { rerender } = render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
101+
102+
expect(screen.getAllByRole('button', { name: /apply .+ theme/i })).toHaveLength(
103+
validKeys.length
104+
);
105+
106+
window.innerWidth = 1280;
107+
window.dispatchEvent(new Event('resize'));
108+
109+
rerender(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
110+
111+
expect(screen.getAllByRole('button', { name: /apply .+ theme/i })).toHaveLength(
112+
validKeys.length
113+
);
114+
});
115+
116+
it('checks rendering of all preset buttons with accessible labels', () => {
97117
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
98118

99119
const presetButtons = screen.getAllByRole('button', { name: /apply .+ theme/i });
100120
expect(presetButtons).toHaveLength(validKeys.length);
121+
});
101122

123+
it('active preset is announced to screen readers via aria-pressed', () => {
124+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
102125
expect(
103126
screen.getByRole('button', { name: /apply dark theme/i }).getAttribute('aria-pressed')
104127
).toBe('true');
128+
});
105129

106-
const highContrastButton = screen.getByRole('button', { name: /apply highcontrast theme/i });
107-
expect(highContrastButton).toBeDefined();
108-
expect(highContrastButton.getAttribute('title')).toBe('Highcontrast');
109-
expect(highContrastButton.getAttribute('style')).toContain('rgb(10, 10, 10)');
130+
it('check if wrapper div uses flex and wrap so buttons reflow on narrow viewports', () => {
131+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
132+
const buttons = screen.getAllByRole('button');
133+
const grid = buttons.at(0)?.parentElement;
110134

111-
const grid = highContrastButton.closest('div');
112135
expect(grid).not.toBeNull();
113136
expect(grid?.style.display).toBe('flex');
114137
expect(grid?.style.flexWrap).toBe('wrap');
115138
});
139+
140+
it('check if each preset button has theme bg colour(inline)', () => {
141+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
142+
const buttons = screen.getAllByRole('button');
143+
144+
buttons.forEach((btn) => {
145+
expect(btn.getAttribute('style')).not.toBeNull();
146+
expect(btn.getAttribute('style')).toMatch(/background/i);
147+
});
148+
});
149+
150+
it('checking if highcontrast is inactive when different theme is active', () => {
151+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
152+
const hcBtn = screen.getByRole('button', { name: /apply highcontrast theme/i });
153+
154+
expect(hcBtn.getAttribute('aria-pressed')).toBe('false');
155+
});
156+
157+
it('check if highcontrast button becomes active when selected', () => {
158+
render(<ThemeQuickPresets theme="highcontrast" onThemeChange={onThemeChange} />);
159+
const hcBtn = screen.getByRole('button', { name: /apply highcontrast theme/i });
160+
expect(hcBtn.getAttribute('aria-pressed')).toBe('true');
161+
});
116162
});

0 commit comments

Comments
 (0)