@@ -11,10 +11,11 @@ test.describe('signup and email verification', () => {
1111 const uniqueId = `${ usernamePrefix ( ) } ${ Date . now ( ) } ` ;
1212 const email = `${ uniqueId } ${ emailSuffix ( ) } ` ;
1313
14- await page . goto ( '/signup' ) ;
15-
14+ await page . goto ( '/' ) ;
1615 await dismissCookieBanner ( page ) ;
1716
17+ await page . locator ( 'a[href="/signup"]' ) . click ( ) ;
18+
1819 await page . locator ( '#username' ) . fill ( uniqueId ) ;
1920 await page . locator ( '#email' ) . fill ( email ) ;
2021 await page . locator ( '#password' ) . fill ( password ( ) ) ;
@@ -42,4 +43,63 @@ test.describe('signup and email verification', () => {
4243 const session = await page . request . get ( '/editor/session' ) ;
4344 expect ( ( await session . json ( ) ) . verified ) . toBe ( 'verified' ) ;
4445 } ) ;
46+
47+ test ( 'cannot sign up with an already-used username or email' , async ( {
48+ page
49+ } ) => {
50+ const uniqueId = `${ usernamePrefix ( ) } ${ Date . now ( ) } ` ;
51+ const email = `${ uniqueId } ${ emailSuffix ( ) } ` ;
52+
53+ await page . goto ( '/' ) ;
54+
55+ await dismissCookieBanner ( page ) ;
56+
57+ await page . locator ( 'a[href="/signup"]' ) . click ( ) ;
58+
59+ await page . locator ( '#username' ) . fill ( uniqueId ) ;
60+ await page . locator ( '#email' ) . fill ( email ) ;
61+ await page . locator ( '#password' ) . fill ( password ( ) ) ;
62+ await page . locator ( '#confirmPassword' ) . fill ( password ( ) ) ;
63+
64+ await page . getByRole ( 'button' , { name : 'Sign Up' , exact : true } ) . click ( ) ;
65+
66+ // Successful signup logs the user in and redirects to the editor
67+ await expect ( page . locator ( '.editor-holder' ) ) . toBeVisible ( {
68+ timeout : 15_000
69+ } ) ;
70+
71+ await page . locator ( `button:has-text("${ uniqueId } ")` ) . click ( ) ;
72+ await page . locator ( '#account-logout' ) . click ( ) ;
73+
74+ await expect ( page . locator ( 'a[href="/signup"]' ) ) . toBeVisible ( {
75+ timeout : 5_000
76+ } ) ;
77+ await page . locator ( 'a[href="/signup"]' ) . click ( ) ;
78+
79+ // Fill the input field and move away, error appears on blur
80+ await page . locator ( '#username' ) . fill ( uniqueId ) ;
81+ await page . locator ( '#email' ) . click ( ) ;
82+ await expect (
83+ page
84+ . locator ( '.form-error' )
85+ . filter ( { hasText : 'This username is already taken.' } )
86+ ) . toBeVisible ( { timeout : 5_000 } ) ;
87+ await page . locator ( '#email' ) . fill ( email ) ;
88+ await page . locator ( '#password' ) . click ( ) ;
89+ await expect (
90+ page
91+ . locator ( '.form-error' )
92+ . filter ( { hasText : 'This email is already taken.' } )
93+ ) . toBeVisible ( { timeout : 5_000 } ) ;
94+
95+ // Now fill passwords — email error will disappear but that's fine
96+ // we already asserted on it above
97+ await page . locator ( '#password' ) . fill ( password ( ) ) ;
98+ await page . locator ( '#confirmPassword' ) . fill ( password ( ) ) ;
99+
100+ // Submit button should still be disabled due to duplicate username/email
101+ await expect (
102+ page . getByRole ( 'button' , { name : 'Sign Up' , exact : true } )
103+ ) . toBeDisabled ( ) ;
104+ } ) ;
45105} ) ;
0 commit comments