-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: 726 changepassword cypress fix + firebase emulator (#751)
* firebase emulator added * changepassword e2e tests fixed
- Loading branch information
1 parent
b2a7289
commit ad41129
Showing
16 changed files
with
176 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,61 @@ | ||
const email = Cypress.env('email'); | ||
const currentPassword = Cypress.env('currentPassword'); | ||
const newPassword = Cypress.env('currentPassword') + 'TEST'; | ||
|
||
let beforeEachFailed = false; | ||
|
||
describe.skip('Change Password Screen', () => { | ||
before(() => {}); | ||
const currentPassword = 'IloveOrangeCones123!'; | ||
const newPassword = currentPassword + 'TEST'; | ||
const email = 'cypressTestUser@mobilitydata.org'; | ||
|
||
describe('Change Password Screen', () => { | ||
beforeEach(() => { | ||
beforeEachFailed = false; | ||
// As per issue #458 the beforeEach of this test file sometimes fail. | ||
// Instead of failing the tests in that case issue a warning. | ||
// This should be removed once the issue is resolved. | ||
try { | ||
// Visit the login page and login | ||
cy.visit('/sign-in'); | ||
cy.get('input[id="email"]').clear().type(email); | ||
cy.get('input[id="password"]').clear().type(currentPassword); | ||
cy.get('button[type="submit"]').click(); | ||
// Wait for the user to be redirected to the home page | ||
cy.location('pathname').should('eq', '/account', { timeout: 30000 }); | ||
// Visit the change password page | ||
cy.visit('/change-password'); | ||
} catch (error) { | ||
beforeEachFailed = true; | ||
cy.log(`Warning: ${error.message}`); | ||
} | ||
cy.visit('/'); | ||
cy.get('[data-testid="home-title"]').should('exist'); | ||
cy.createNewUserAndSignIn(email, currentPassword); | ||
cy.get('[data-cy="accountHeader"]').should('exist'); // assures that the user is signed in | ||
cy.visit('/change-password'); | ||
}); | ||
|
||
it('should render components', () => { | ||
if (beforeEachFailed) { | ||
cy.log('Skipping test due to beforeEach failure'); | ||
return; | ||
} | ||
// Check that the current password field exists | ||
cy.get('input[id="currentPassword"]').should('exist'); | ||
|
||
// Check that the new password field exists | ||
cy.get('input[id="newPassword"]').should('exist'); | ||
|
||
// Check that the confirm new password field exists | ||
cy.get('input[id="confirmNewPassword"]').should('exist'); | ||
}); | ||
|
||
it('should show error when current password is incorrect', () => { | ||
if (beforeEachFailed) { | ||
cy.log('Skipping test due to beforeEach failure'); | ||
return; | ||
} | ||
// Type the wrong current password | ||
cy.get('input[id="currentPassword"]').type('wrong'); | ||
|
||
// Type the new password | ||
cy.get('input[id="newPassword"]').type(newPassword); | ||
|
||
// Confirm the new password | ||
cy.get('input[id="confirmNewPassword"]').type(newPassword); | ||
|
||
// Submit the form | ||
cy.get('button[type="submit"]').click(); | ||
|
||
// Check that the error message is displayed | ||
cy.contains( | ||
'The password is invalid or the user does not have a password. (auth/wrong-password).', | ||
).should('exist'); | ||
}); | ||
|
||
it('should change password', () => { | ||
if (beforeEachFailed) { | ||
cy.log('Skipping test due to beforeEach failure'); | ||
return; | ||
} | ||
// Type the current password | ||
cy.intercept('POST', '/retrieveUserInformation', { | ||
statusCode: 200, | ||
body: { | ||
result: { | ||
uid: 'ep4EwJvgNhfEER152EfzLSI0MBG2', | ||
isRegisteredToReceiveAPIAnnouncements: false, | ||
organization: '', | ||
fullName: 'Alessandro', | ||
registrationCompletionTime: '2024-09-24T15:34:55.381Z', | ||
}, | ||
}, | ||
}); | ||
cy.get('input[id="currentPassword"]').type(currentPassword); | ||
|
||
// Type the new password | ||
cy.get('input[id="newPassword"]').type(newPassword); | ||
|
||
// Confirm the new password | ||
cy.get('input[id="confirmNewPassword"]').type(newPassword); | ||
|
||
// Submit the form | ||
cy.get('button[type="submit"]').click(); | ||
|
||
// Check that the password was changed successfully | ||
cy.contains('Change Password Succeeded').should('exist'); | ||
cy.get('[cy-data="goToAccount"]').click(); | ||
cy.location('pathname').should('eq', '/account'); | ||
|
||
// Reset the password back to the original password | ||
cy.visit('/change-password'); | ||
cy.get('input[id="currentPassword"]').type(newPassword); | ||
cy.get('input[id="newPassword"]').type(currentPassword); | ||
cy.get('input[id="confirmNewPassword"]').type(currentPassword); | ||
cy.get('button[type="submit"]').click(); | ||
cy.contains('Change Password Succeeded').should('exist'); | ||
// logout | ||
cy.get('[data-cy="signOutButton"]').click(); | ||
cy.get('[data-cy="confirmSignOutButton"]').should('exist').click(); | ||
cy.visit('/sign-in'); | ||
cy.get('[data-cy="signInEmailInput"]').type(email); | ||
cy.get('[data-cy="signInPasswordInput"]').type(newPassword); | ||
cy.get('[data-testid="signin"]').click(); | ||
cy.location('pathname').should('eq', '/account'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import './commands'; | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Dispatches loginSuccess action to the store with the given user profile | ||
* Simulates the login of a user | ||
*/ | ||
injectAuthenticatedUser(): void; | ||
namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Dispatches loginSuccess action to the store with the given user profile | ||
* Simulates the login of a user | ||
* @param email email of the user to inject | ||
*/ | ||
injectAuthenticatedUser(email: string): void; | ||
|
||
/** | ||
* Selects a dropdown item in a MUI dropdown | ||
* @param elementKey selector of the dropdown element | ||
* @param dropDownDataValue data value of the dropdown item to select | ||
*/ | ||
muiDropdownSelect(elementKey: string, dropDownDataValue: string): void; | ||
/** | ||
* Selects a dropdown item in a MUI dropdown | ||
* @param elementKey selector of the dropdown element | ||
* @param dropDownDataValue data value of the dropdown item to select | ||
*/ | ||
muiDropdownSelect(elementKey: string, dropDownDataValue: string): void; | ||
|
||
/** | ||
* Tests if an element has the MUI error | ||
* @param elementKey selector of the element to assert the MUI error class | ||
*/ | ||
assetMuiError(elementKey: string): void; | ||
} | ||
/** | ||
* Tests if an element has the MUI error | ||
* @param elementKey selector of the element to assert the MUI error class | ||
*/ | ||
assetMuiError(elementKey: string): void; | ||
|
||
/** | ||
* Wipes the firebase auth state, creates a user and signs in. Injects the user into the store | ||
* @param email email of the new user | ||
* @param password password of the new user | ||
*/ | ||
createNewUserAndSignIn(email: string, password: string): void; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
"storage": { | ||
"port": 9199 | ||
}, | ||
"auth": { | ||
"port": 9099 | ||
}, | ||
"ui": { | ||
"enabled": true | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.