Skip to content

Commit a0261cb

Browse files
authored
Test/UI theme quick presets (JhaSourav07#2186)
## Description Fixes JhaSourav07#1513 ## Pillar - [ ] 🎨 Pillar 1 β€” New Theme Design - [ ] πŸ“ Pillar 2 β€” Geometric SVG Improvement - [ ] πŸ• Pillar 3 β€” Timezone Logic Optimization - [X] πŸ› οΈ Other (Bug fix, refactoring, docs) ## Visual Preview No visual changes ## Checklist before requesting a review: - [X] I have read the `CONTRIBUTING.md` file. - [X] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [X] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [X] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [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 (no raw elements, smooth animations, correct fonts). - [X] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents bc1b9fa + a75321c commit a0261cb

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)