File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,4 +239,28 @@ describe('DashboardClient', () => {
239239 const generateLink = screen . getByRole ( 'link' , { name : / g e n e r a t e y o u r o w n / 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 ( / C a n n o t c o m p a r e a p r o f i l e w i t h i t s e l f / i) ) . toBeDefined ( ) ;
264+ } ) ;
265+ } ) ;
242266} ) ;
You can’t perform that action at this time.
0 commit comments