Skip to content

Commit 3d6d5c3

Browse files
committed
test(dashboard): verify error is shown when comparing with same username (JhaSourav07#1064)
1 parent 77a73f6 commit 3d6d5c3

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
@@ -239,4 +239,28 @@ describe('DashboardClient', () => {
239239
const generateLink = screen.getByRole('link', { name: /generate your own/i });
240240
expect(generateLink.getAttribute('href')).toBe('/');
241241
});
242+
// =========================================================================
243+
// ISSUE OBJECTIVE: Verify error is shown when comparing with same username
244+
// =========================================================================
245+
it('shows an error when comparing with the same username (case-insensitive)', async () => {
246+
render(<DashboardClient initialData={mockInitialData} username="Shivangi1515" />);
247+
248+
// 1. Open modal
249+
const compareBtn = screen.getByText('Compare Profile');
250+
fireEvent.click(compareBtn);
251+
252+
// 2. Type the same username as props.username, but all lowercase to test case-insensitivity
253+
const input = screen.getByPlaceholderText('Enter GitHub Username');
254+
fireEvent.change(input, { target: { value: 'shivangi1515' } });
255+
256+
// 3. Click 'Compare'
257+
const submitBtn = screen.getByText('Compare');
258+
fireEvent.click(submitBtn);
259+
260+
// 4. Assert error message 'Cannot compare a profile with itself.' appears
261+
await waitFor(() => {
262+
// Using Regex /.../i to match the text even if there is an emoji next to it!
263+
expect(screen.getByText(/Cannot compare a profile with itself/i)).toBeDefined();
264+
});
265+
});
242266
});

0 commit comments

Comments
 (0)