Skip to content

Commit fbdd8e4

Browse files
authored
test(dashboard): verified that compare modal input can be cleared (JhaSourav07#1194)
## Description Fixes JhaSourav07#1063 **Context:** The Compare Modal inside the `DashboardClient` component features a 'Clear input' (X) button to clear out the search field if you had typed any username in it. I wrote the test case to verify that it actually works as intended. **Solution:** I added a new test block to `DashboardClient.test.tsx` using Vitest and React Testing Library. The test simulates a user interaction by opening the modal, typing in a username, and verifying that clicking the rendered 'Clear input' button successfully resets the input field to an empty string. Later I had the tests and, all 638 tests are passing successfully. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview of tests passing <img width="1325" height="749" alt="image" src="https://github.com/user-attachments/assets/d51071a2-0a92-4501-96fa-7db909394724" /> ## 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. *(I only wrote test case so no)* - [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). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support. *(I'll join it)*
2 parents 3f05fee + 4d3a180 commit fbdd8e4

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

components/dashboard/DashboardClient.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,31 @@ describe('DashboardClient', () => {
327327
expect(screen.getByText(/Cannot compare a profile with itself/i)).toBeDefined();
328328
});
329329
});
330+
331+
// =========================================================================
332+
// ISSUE OBJECTIVE #1063: Verify compare modal input can be cleared
333+
// =========================================================================
334+
it('verify compare modal input can be cleared', async () => {
335+
render(<DashboardClient initialData={mockInitialData} username="Shivangi1515" />);
336+
337+
// 1. Open modal
338+
const compareBtn = screen.getByText('Compare Profile');
339+
fireEvent.click(compareBtn);
340+
341+
// 2. Type a username into the input
342+
const input = screen.getByPlaceholderText('Enter GitHub Username');
343+
fireEvent.change(input, { target: { value: 'testuser' } });
344+
345+
// 3. Assert 'Clear input' (aria-label) button appears
346+
const clearButton = screen.getByRole('button', { name: 'Clear input' });
347+
expect(clearButton).toBeDefined();
348+
349+
// 4. Click clear button
350+
fireEvent.click(clearButton);
351+
352+
// 5. Assert input value is empty
353+
expect((input as HTMLInputElement).value).toBe('');
354+
});
330355
});
331356
it('shows Most Consistent badge for profile with higher peak streak in compare mode', async () => {
332357
const mockFetch = vi.fn().mockResolvedValue({

0 commit comments

Comments
 (0)