@@ -4,20 +4,38 @@ import assert from 'assert'
44Given ( 'the register page is open' , async function ( ) {
55 const page = this . page
66 if ( ! page ) throw new Error ( 'Page not initialized' )
7+
8+ // Mock the login API so the test doesn't need MongoDB
9+ await page . route ( '**/login' , async ( route ) => {
10+ await route . fulfill ( {
11+ status : 200 ,
12+ contentType : 'application/json' ,
13+ body : JSON . stringify ( {
14+ message : 'Login successful for Alice' ,
15+ token : 'mock-jwt-token' ,
16+ username : 'Alice'
17+ } )
18+ } )
19+ } )
20+
721 await page . goto ( 'http://localhost:5173' )
822} )
923
10- When ( 'I enter {string} as the username and submit' , async function ( username ) {
24+ When ( 'I enter {string} as the username and {string} as the password and submit' , async function ( username , password ) {
1125 const page = this . page
1226 if ( ! page ) throw new Error ( 'Page not initialized' )
1327 await page . fill ( '#username' , username )
28+ await page . fill ( '#password' , password )
1429 await page . click ( '.submit-button' )
1530} )
1631
17- Then ( 'I should see a welcome message containing {string} ' , async function ( expected ) {
32+ Then ( 'I should be redirected to the lobby ' , async function ( ) {
1833 const page = this . page
1934 if ( ! page ) throw new Error ( 'Page not initialized' )
20- await page . waitForSelector ( '.success-message' , { timeout : 5000 } )
21- const text = await page . textContent ( '.success-message' )
22- assert . ok ( text && text . includes ( expected ) , `Expected success message to include "${ expected } ", got: "${ text } "` )
35+
36+ // After successful login, the app sets localStorage and navigates to ?view=lobby.
37+ // Wait for the lobby content to appear (profile-username is only rendered on the lobby page).
38+ await page . waitForSelector ( '.profile-username' , { timeout : 10000 } )
39+ const text = await page . textContent ( '.profile-username' )
40+ assert . ok ( text && text . includes ( 'Alice' ) , `Expected lobby to show "Alice", got: "${ text } "` )
2341} )
0 commit comments