Skip to content

Commit ad75648

Browse files
committed
test(dashboard): verify exit compare mode resets state properly (#ISSUE_NUMBER)
1 parent 3f40d88 commit ad75648

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)