Skip to content

Commit 910da63

Browse files
authored
merge: test(theme-quick-presets): add isolated mock integration tests for preset rendering and interactions (#8072)
## Description This PR introduces a dedicated mock integration test suite for ThemeQuickPresets to improve component reliability and validate its behavior in an isolated environment. The tests mock external dependencies such as theme definitions and available theme keys while focusing on rendering and user interactions. ## Changes Made Added app/customize/components/ThemeQuickPresets.mock-integrations.test.tsx Mocked the themes configuration to provide deterministic test data. Mocked THEME_KEYS to isolate the component from application-wide theme configuration. Added tests to verify: Only selectable themes are rendered (excluding auto and random). The active preset correctly updates the aria-pressed accessibility attribute. Clicking a preset invokes onThemeChange with the selected theme. The correct number of preset buttons is rendered. Active theme styling (tqp-on) is applied correctly. Fixes #6886 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## 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): ...`). - [x] 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. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 83fa0fe + 734e8e1 commit 910da63

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import { ThemeQuickPresets } from './ThemeQuickPresets';
4+
import react from 'react';
5+
6+
vi.mock('../../../lib/svg/themes', () => ({
7+
themes: {
8+
dark: {
9+
bg: '000000',
10+
text: 'ffffff',
11+
accent: '00ff00',
12+
},
13+
light: {
14+
bg: 'ffffff',
15+
text: '000000',
16+
accent: '0066ff',
17+
},
18+
neon: {
19+
bg: '111111',
20+
text: 'ffffff',
21+
accent: 'ff00ff',
22+
},
23+
},
24+
}));
25+
26+
vi.mock('../types', () => ({
27+
THEME_KEYS: ['dark', 'light', 'neon', 'auto', 'random'],
28+
}));
29+
30+
describe('ThemeQuickPresets', () => {
31+
beforeEach(() => {
32+
vi.clearAllMocks();
33+
});
34+
35+
it('renders only selectable themes', () => {
36+
render(<ThemeQuickPresets theme="dark" onThemeChange={vi.fn()} />);
37+
38+
expect(screen.getByLabelText('Apply dark theme')).toBeInTheDocument();
39+
expect(screen.getByLabelText('Apply light theme')).toBeInTheDocument();
40+
expect(screen.getByLabelText('Apply neon theme')).toBeInTheDocument();
41+
42+
expect(screen.queryByLabelText('Apply auto theme')).not.toBeInTheDocument();
43+
expect(screen.queryByLabelText('Apply random theme')).not.toBeInTheDocument();
44+
});
45+
46+
it('marks active theme with aria-pressed', () => {
47+
render(<ThemeQuickPresets theme="light" onThemeChange={vi.fn()} />);
48+
49+
expect(screen.getByLabelText('Apply light theme')).toHaveAttribute('aria-pressed', 'true');
50+
51+
expect(screen.getByLabelText('Apply dark theme')).toHaveAttribute('aria-pressed', 'false');
52+
});
53+
54+
it('calls onThemeChange when clicked', () => {
55+
const onThemeChange = vi.fn();
56+
57+
render(<ThemeQuickPresets theme="dark" onThemeChange={onThemeChange} />);
58+
59+
fireEvent.click(screen.getByLabelText('Apply neon theme'));
60+
61+
expect(onThemeChange).toHaveBeenCalledTimes(1);
62+
expect(onThemeChange).toHaveBeenCalledWith('neon');
63+
});
64+
65+
it('renders one button for every selectable theme', () => {
66+
render(<ThemeQuickPresets theme="dark" onThemeChange={vi.fn()} />);
67+
68+
expect(screen.getAllByRole('button')).toHaveLength(3);
69+
});
70+
71+
it('shows active theme styling', () => {
72+
render(<ThemeQuickPresets theme="dark" onThemeChange={vi.fn()} />);
73+
74+
expect(screen.getByLabelText('Apply dark theme')).toHaveClass('tqp-on');
75+
expect(screen.getByLabelText('Apply light theme')).not.toHaveClass('tqp-on');
76+
});
77+
});

0 commit comments

Comments
 (0)