Skip to content

Commit b082945

Browse files
authored
test(customize): add additional coverage for ThemeQuickPresets component (JhaSourav07#1681)
## Description Fixes JhaSourav07#1030 - `app/customize/components/ThemeQuickPresets.test.tsx` — added `4` additional tests: asserting every button has an `aria-label` starting with `"Apply"`, verifying a button exists for each concrete theme key excluding `auto` and `random`, confirming `aria-pressed` updates correctly when the active theme changes via rerender, and asserting no buttons are rendered for `auto` or `random` themes. 🚀 ## Pillar - 🛠️ Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - I have read the `CONTRIBUTING.md` file. - I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - I have run `npm run format` and `npm run lint` locally and resolved all errors. - My commits follow the Conventional Commits format. - I have starred the repo. - I have made sure that i have only one commit to merge in this PR.
2 parents 962fcda + e7fced3 commit b082945

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
@@ -48,6 +48,41 @@ describe('ThemeQuickPresets', () => {
4848
fireEvent.click(inactiveBtn);
4949
expect(onThemeChange).toHaveBeenCalledWith(inactiveKey);
5050
});
51+
52+
it('each button has an aria-label starting with "Apply"', () => {
53+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
54+
const buttons = screen.getAllByRole('button');
55+
buttons.forEach((btn) => {
56+
expect(btn.getAttribute('aria-label')).toMatch(/^Apply/i);
57+
});
58+
});
59+
60+
it('renders at least one button for each concrete theme excluding auto and random', () => {
61+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
62+
validKeys.forEach((key) => {
63+
const btn = screen.getByRole('button', {
64+
name: new RegExp(`apply ${key} theme`, 'i'),
65+
});
66+
expect(btn).toBeTruthy();
67+
});
68+
});
69+
70+
it('switching active theme updates aria-pressed correctly', () => {
71+
const { rerender } = render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
72+
const darkBtn = screen.getByRole('button', { name: /apply dark theme/i });
73+
expect(darkBtn.getAttribute('aria-pressed')).toBe('true');
74+
75+
rerender(<ThemeQuickPresets theme="neon" onThemeChange={onThemeChange} />);
76+
const neonBtn = screen.getByRole('button', { name: /apply neon theme/i });
77+
expect(neonBtn.getAttribute('aria-pressed')).toBe('true');
78+
expect(darkBtn.getAttribute('aria-pressed')).toBe('false');
79+
});
80+
81+
it('does not render buttons for auto or random themes', () => {
82+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
83+
expect(screen.queryByRole('button', { name: /apply auto theme/i })).toBeNull();
84+
expect(screen.queryByRole('button', { name: /apply random theme/i })).toBeNull();
85+
});
5186
});
5287

5388
describe('ThemeQuickPresets responsive rendering', () => {

0 commit comments

Comments
 (0)