Skip to content

Commit 5447fd1

Browse files
authored
test(dashboard): verify error is shown when comparing with same username (JhaSourav07#1064) (JhaSourav07#1158)
2 parents f7d23fa + 3d6d5c3 commit 5447fd1

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

components/dashboard/DashboardClient.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,28 @@ describe('DashboardClient', () => {
287287
const generateLink = screen.getByRole('link', { name: /generate your own/i });
288288
expect(generateLink.getAttribute('href')).toBe('/');
289289
});
290+
// =========================================================================
291+
// ISSUE OBJECTIVE: Verify error is shown when comparing with same username
292+
// =========================================================================
293+
it('shows an error when comparing with the same username (case-insensitive)', async () => {
294+
render(<DashboardClient initialData={mockInitialData} username="Shivangi1515" />);
295+
296+
// 1. Open modal
297+
const compareBtn = screen.getByText('Compare Profile');
298+
fireEvent.click(compareBtn);
299+
300+
// 2. Type the same username as props.username, but all lowercase to test case-insensitivity
301+
const input = screen.getByPlaceholderText('Enter GitHub Username');
302+
fireEvent.change(input, { target: { value: 'shivangi1515' } });
303+
304+
// 3. Click 'Compare'
305+
const submitBtn = screen.getByText('Compare');
306+
fireEvent.click(submitBtn);
307+
308+
// 4. Assert error message 'Cannot compare a profile with itself.' appears
309+
await waitFor(() => {
310+
// Using Regex /.../i to match the text even if there is an emoji next to it!
311+
expect(screen.getByText(/Cannot compare a profile with itself/i)).toBeDefined();
312+
});
313+
});
290314
});

0 commit comments

Comments
 (0)