Skip to content

Commit ed4fc4a

Browse files
authored
test(ThemeSelector): add responsive rendering suite for Dracula/Neon … (JhaSourav07#1867)
## Description Fixes JhaSourav07#1512 ## 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 preview needed test only change ## 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 6968850 + 7cc7233 commit ed4fc4a

1 file changed

Lines changed: 34 additions & 42 deletions

File tree

app/customize/components/ThemeSelector.test.tsx

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -137,65 +137,57 @@ describe('ThemeSelector - Custom Variations (Variation 4)', () => {
137137
});
138138
});
139139

140-
describe('ThemeSelector - Custom Variations (Variation 4)', () => {
140+
describe('ThemeSelector responsive rendering', () => {
141141
const onThemeChange = vi.fn();
142142

143143
afterEach(() => {
144144
vi.clearAllMocks();
145145
});
146146

147-
it('renders ThemeSelector successfully and layout structure exists', () => {
148-
const { container } = render(<ThemeSelector theme="dark" onThemeChange={onThemeChange} />);
147+
it('check if the root container holds its flex-col layout when switch from Dracula -> Neon', () => {
148+
const { container, rerender } = render(
149+
<ThemeSelector theme="dracula" onThemeChange={onThemeChange} />
150+
);
151+
const root = container.firstChild as HTMLElement;
152+
expect(root.className).toContain('flex-col');
149153

150-
// ThemeSelector renders successfully
151-
expect(screen.getByRole('combobox')).toBeTruthy();
152-
expect(screen.getByText('Theme Preset')).toBeTruthy();
153-
154-
// Layout structure exists
155-
const mainContainer = container.firstChild as HTMLElement;
156-
expect(mainContainer).toBeTruthy();
157-
expect(mainContainer.className).toContain('flex');
158-
expect(mainContainer.className).toContain('flex-col');
159-
expect(mainContainer.className).toContain('gap-1.5');
154+
rerender(<ThemeSelector theme="neon" onThemeChange={onThemeChange} />);
155+
expect(root.className).toContain('flex-col');
160156
});
161157

162-
it('verifies that selecting Dracula preset calls onThemeChange("dracula")', async () => {
163-
const user = userEvent.setup();
164-
render(<ThemeSelector theme="dark" onThemeChange={onThemeChange} />);
158+
it('check if active preset button updates when switching from Dracula to Neon', () => {
159+
const { rerender } = render(<ThemeSelector theme="dracula" onThemeChange={onThemeChange} />);
165160

166-
// Select Dracula preset via accessibility query
167-
const draculaBtn = screen.getByRole('button', { name: /apply dracula theme/i });
168-
expect(draculaBtn).toBeTruthy();
161+
expect(
162+
screen.getByRole('button', { name: /apply dracula theme/i }).getAttribute('aria-pressed')
163+
).toBe('true');
169164

170-
// Click it
171-
await user.click(draculaBtn);
165+
rerender(<ThemeSelector theme="neon" onThemeChange={onThemeChange} />);
172166

173-
// Verify onThemeChange was called with 'dracula'
174-
expect(onThemeChange).toHaveBeenCalledWith('dracula');
167+
expect(
168+
screen.getByRole('button', { name: /apply neon theme/i }).getAttribute('aria-pressed')
169+
).toBe('true');
170+
expect(
171+
screen.getByRole('button', { name: /apply dracula theme/i }).getAttribute('aria-pressed')
172+
).toBe('false');
175173
});
176174

177-
it('verifies that selecting Neon preset calls onThemeChange("neon")', async () => {
178-
const user = userEvent.setup();
179-
render(<ThemeSelector theme="dark" onThemeChange={onThemeChange} />);
175+
it('check if select value reflects the active theme after switch Dracula -> Neon', () => {
176+
const { rerender } = render(<ThemeSelector theme="dracula" onThemeChange={onThemeChange} />);
177+
const select = screen.getByRole('combobox') as HTMLSelectElement;
178+
expect(select.value).toBe('dracula');
180179

181-
// Select Neon preset via accessibility query
182-
const neonBtn = screen.getByRole('button', { name: /apply neon theme/i });
183-
expect(neonBtn).toBeTruthy();
184-
185-
// Click it
186-
await user.click(neonBtn);
187-
188-
// Verify onThemeChange was called with 'neon'
189-
expect(onThemeChange).toHaveBeenCalledWith('neon');
180+
rerender(<ThemeSelector theme="neon" onThemeChange={onThemeChange} />);
181+
expect(select.value).toBe('neon');
190182
});
191183

192-
it('verifies the select dropdown calls onThemeChange with the selected theme', async () => {
193-
const user = userEvent.setup();
194-
render(<ThemeSelector theme="dark" onThemeChange={onThemeChange} />);
195-
196-
const select = screen.getByRole('combobox');
197-
await user.selectOptions(select, 'sunset');
184+
it('colour swatches update to the new theme after switching', () => {
185+
const { rerender } = render(<ThemeSelector theme="dracula" onThemeChange={onThemeChange} />);
186+
const draculaSwatches = screen.getAllByTitle(/^(bg|accent|text):/i);
187+
expect(draculaSwatches.length).toBe(3);
198188

199-
expect(onThemeChange).toHaveBeenCalledWith('sunset');
189+
rerender(<ThemeSelector theme="neon" onThemeChange={onThemeChange} />);
190+
// swatches should still be 3, now reflecting neon's palette
191+
expect(screen.getAllByTitle(/^(bg|accent|text):/i).length).toBe(3);
200192
});
201193
});

0 commit comments

Comments
 (0)