Skip to content

Commit 7bc9c64

Browse files
authored
test(dashboard): verify exit compare mode resets state properly (JhaSourav07#1156)
## Description Added a new test case in components/dashboard/DashboardClient.test.tsx to verify the state reset logic for the "Exit Compare Mode" functionality. The test simulates a successful comparison fetch, asserts the appearance of the exit button, clicks it, and finally verifies that the UI reverts to the default single-profile state (the original compare button returns and the exit button is removed from the DOM). Fixes JhaSourav07#1065 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="948" height="387" alt="Screenshot 2026-05-29 102110" src="https://github.com/user-attachments/assets/e494f792-8302-44f5-8441-6bf0e2cebe4c" /> ## 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 starred 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. [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions.
2 parents 1a6179c + ad75648 commit 7bc9c64

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

components/dashboard/DashboardClient.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,54 @@ describe('DashboardClient', () => {
233233
expect(screen.getAllByText('Shivangi').length).toBeGreaterThan(0);
234234
expect(screen.getAllByText('Sourav').length).toBeGreaterThan(0);
235235
});
236+
237+
// =========================================================================
238+
// ISSUE OBJECTIVE: Add a test for exiting compare mode
239+
// =========================================================================
240+
it('exits compare mode and restores single profile view', async () => {
241+
// Mock successful fetch response to enter compare mode first
242+
const mockFetch = vi.fn().mockImplementation(() =>
243+
Promise.resolve({
244+
ok: true,
245+
json: () => Promise.resolve(mockSecondData),
246+
})
247+
);
248+
vi.stubGlobal('fetch', mockFetch);
249+
250+
render(<DashboardClient initialData={mockInitialData} username="Shivangi1515" />);
251+
252+
// 1. Enter compare mode
253+
const compareBtn = screen.getByText('Compare Profile');
254+
fireEvent.click(compareBtn);
255+
256+
const input = screen.getByPlaceholderText('Enter GitHub Username');
257+
fireEvent.change(input, { target: { value: 'JhaSourav07' } });
258+
259+
const submitBtn = screen.getByText('Compare');
260+
fireEvent.click(submitBtn);
261+
262+
// Wait for state to update and Exit button to render
263+
await waitFor(() => {
264+
expect(screen.getByText('Exit Compare Mode')).toBeDefined();
265+
});
266+
267+
// 2. Assert 'Exit Compare Mode' button is visible
268+
const exitBtn = screen.getByText('Exit Compare Mode');
269+
expect(exitBtn).toBeDefined();
270+
271+
// 3. Click it
272+
fireEvent.click(exitBtn);
273+
274+
// 4. Assert 'Compare Profile' button is visible again
275+
expect(screen.getByText('Compare Profile')).toBeDefined();
276+
277+
// 5. Assert 'Exit Compare Mode' button is gone
278+
expect(screen.queryByText('Exit Compare Mode')).toBeNull();
279+
280+
// Verify the second profile is removed from the DOM
281+
expect(screen.queryByText('Sourav')).toBeNull();
282+
});
283+
236284
it('generate your own button points to root /', () => {
237285
render(<DashboardClient initialData={mockInitialData} username="Shivangi1515" />);
238286

0 commit comments

Comments
 (0)