Skip to content

Commit d15eb6b

Browse files
authored
test(ui): verify responsive rendering of ThemeQuickPresets (JhaSourav07#1675)
## Description Adds additional UI test coverage for `ThemeQuickPresets`. This PR verifies: * All theme preset buttons render correctly. * Accessible preset names are exposed to assistive technologies. * The active preset exposes the correct `aria-pressed` state. * High-contrast theme presets are present and selectable. * The preset container uses a responsive wrapping layout suitable for smaller viewports. No production code was modified. This change only increases component test coverage and helps ensure accessibility and responsive rendering behavior remain stable. Fixes JhaSourav07#1523 ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only change) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally. * [x] I have run the relevant test commands locally. * [x] My commits follow the Conventional Commits format. * [ ] I have updated `README.md` if I added a new theme or URL parameter. (Not applicable) * [x] I have started the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. (Not applicable) * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 4538996 + 872c19d commit d15eb6b

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)