@@ -14,7 +14,7 @@ import {
1414 type LocalTrackedCalls ,
1515} from './localApi'
1616import LoginPageActions from './LoginPageActions'
17- import { passAgreementsDialog , TEXT , type MockParams } from './utilities'
17+ import { passAgreementsDialog , TEXT , VALID_PASSWORD , type MockParams } from './utilities'
1818export * from './utilities'
1919
2020export const getText = ( key : TextId , ...replacements : Replacements [ TextId ] ) => {
@@ -28,23 +28,35 @@ export function getAuthFilePath() {
2828}
2929
3030/** Perform a successful login. */
31- async function loginIfNeeded ( page : Page , actions : LoginPageActions < Context > ) {
31+ async function login ( { page } : MockParams , email = 'email@example.com' , password = VALID_PASSWORD ) {
3232 const authFile = getAuthFilePath ( )
33+
34+ await waitForLoaded ( page )
3335 const isLoggedIn = ( await page . getByTestId ( 'before-auth-layout' ) . count ( ) ) === 0
36+
3437 if ( isLoggedIn ) {
3538 test . info ( ) . annotations . push ( {
3639 type : 'skip' ,
3740 description : 'Already logged in' ,
3841 } )
39- const agreementModalVisible = ( await page . locator ( '#agreements-modal' ) . count ( ) ) > 0
40- if ( agreementModalVisible ) {
41- await passAgreementsDialog ( { page } )
42- await page . context ( ) . storageState ( { path : authFile } )
43- }
44- } else {
45- await actions . login ( )
46- await page . context ( ) . storageState ( { path : authFile } )
42+ return
4743 }
44+
45+ return test . step ( 'Login' , async ( ) => {
46+ test . info ( ) . annotations . push ( {
47+ type : 'Login' ,
48+ description : 'Performing login' ,
49+ } )
50+ await page . getByPlaceholder ( TEXT . emailPlaceholder ) . fill ( email )
51+ await page . getByPlaceholder ( TEXT . passwordPlaceholder ) . fill ( password )
52+ await page . getByRole ( 'button' , { name : TEXT . login , exact : true } ) . getByText ( TEXT . login ) . click ( )
53+
54+ await expect ( page . getByText ( TEXT . loadingAppMessage ) ) . not . toBeVisible ( )
55+
56+ await passAgreementsDialog ( { page } )
57+
58+ await page . context ( ) . storageState ( { path : authFile } )
59+ } )
4860}
4961
5062/** Wait for the page to load. */
@@ -132,7 +144,7 @@ export function mockAllAndLogin({
132144 const actions = mockAll ( { page, setupAPI, setupLocalAPI } )
133145
134146 const driveActions = actions
135- . step ( 'Pass login screen ' , ( page , _ctx , actions ) => loginIfNeeded ( page , actions ) )
147+ . step ( 'Login ' , ( page ) => login ( { page } ) )
136148 . step ( 'Wait for dashboard to load' , waitForDashboardToLoad )
137149 . into ( DrivePageActions < Context > )
138150 return goToCloudFirst ? driveActions . goToCategory . cloud ( ) : driveActions
0 commit comments