2023-02-10 04:12:06 -08:00
|
|
|
import { ChangePasswordModal } from './modals/change-password-modal';
|
2023-08-23 19:59:16 -07:00
|
|
|
import { MfaSetupModal } from './modals/mfa-setup-modal';
|
2023-02-10 04:12:06 -08:00
|
|
|
import { BasePage } from './base';
|
2023-08-24 06:31:37 -07:00
|
|
|
import generateOTPToken from 'cypress-otp';
|
2023-02-10 04:12:06 -08:00
|
|
|
|
|
|
|
const changePasswordModal = new ChangePasswordModal();
|
2023-08-23 19:59:16 -07:00
|
|
|
const mfaSetupModal = new MfaSetupModal();
|
2023-02-10 04:12:06 -08:00
|
|
|
|
|
|
|
export class PersonalSettingsPage extends BasePage {
|
|
|
|
url = '/settings/personal';
|
2023-08-23 19:59:16 -07:00
|
|
|
secret = '';
|
|
|
|
|
2023-02-10 04:12:06 -08:00
|
|
|
getters = {
|
|
|
|
currentUserName: () => cy.getByTestId('current-user-name'),
|
|
|
|
firstNameInput: () => cy.getByTestId('firstName').find('input').first(),
|
|
|
|
lastNameInput: () => cy.getByTestId('lastName').find('input').first(),
|
|
|
|
emailInputContainer: () => cy.getByTestId('email'),
|
|
|
|
emailInput: () => cy.getByTestId('email').find('input').first(),
|
2023-07-28 00:51:07 -07:00
|
|
|
changePasswordLink: () => cy.getByTestId('change-password-link').first(),
|
2023-02-10 04:12:06 -08:00
|
|
|
saveSettingsButton: () => cy.getByTestId('save-settings-button'),
|
2023-08-23 19:59:16 -07:00
|
|
|
enableMfaButton: () => cy.getByTestId('enable-mfa-button'),
|
|
|
|
disableMfaButton: () => cy.getByTestId('disable-mfa-button'),
|
2023-02-10 04:12:06 -08:00
|
|
|
};
|
|
|
|
actions = {
|
|
|
|
loginAndVisit: (email: string, password: string) => {
|
|
|
|
cy.signin({ email, password });
|
|
|
|
cy.visit(this.url);
|
|
|
|
},
|
|
|
|
updateFirstAndLastName: (newFirstName: string, newLastName: string) => {
|
|
|
|
this.getters.firstNameInput().type('{selectall}').type(newFirstName);
|
|
|
|
this.getters.lastNameInput().type('{selectall}').type(newLastName);
|
|
|
|
this.getters.saveSettingsButton().realClick();
|
|
|
|
},
|
|
|
|
updatePassword: (oldPassword: string, newPassword: string) => {
|
|
|
|
changePasswordModal.getters.modalContainer().should('be.visible');
|
|
|
|
changePasswordModal.getters.currentPasswordInput().type('{selectall}').type(oldPassword);
|
|
|
|
changePasswordModal.getters.newPasswordInput().type('{selectall}').type(newPassword);
|
|
|
|
changePasswordModal.getters.repeatPasswordInput().type('{selectall}').type(newPassword);
|
|
|
|
changePasswordModal.getters.changePasswordButton().click();
|
|
|
|
},
|
|
|
|
tryToSetWeakPassword: (oldPassword: string, newPassword: string) => {
|
|
|
|
this.actions.updatePassword(oldPassword, newPassword);
|
2023-07-28 00:51:07 -07:00
|
|
|
changePasswordModal.getters
|
|
|
|
.newPasswordInputContainer()
|
|
|
|
.find('div[class^="_errorInput"]')
|
|
|
|
.should('exist');
|
2023-02-10 04:12:06 -08:00
|
|
|
},
|
|
|
|
updateEmail: (newEmail: string) => {
|
|
|
|
this.getters.emailInput().type('{selectall}').type(newEmail).type('{enter}');
|
|
|
|
},
|
|
|
|
tryToSetInvalidEmail: (newEmail: string) => {
|
|
|
|
this.actions.updateEmail(newEmail);
|
|
|
|
this.getters.emailInputContainer().find('div[class^="_errorInput"]').should('exist');
|
|
|
|
},
|
|
|
|
loginWithNewData: (email: string, password: string) => {
|
|
|
|
cy.signout();
|
|
|
|
this.actions.loginAndVisit(email, password);
|
|
|
|
cy.url().should('match', new RegExp(this.url));
|
|
|
|
},
|
2023-08-23 19:59:16 -07:00
|
|
|
enableMfa: () => {
|
|
|
|
cy.visit(this.url);
|
|
|
|
this.getters.enableMfaButton().click();
|
|
|
|
mfaSetupModal.getters.copySecretToClipboardButton().realClick();
|
|
|
|
cy.readClipboard().then((secret) => {
|
2023-08-24 06:31:37 -07:00
|
|
|
const token = generateOTPToken(secret)
|
|
|
|
|
|
|
|
mfaSetupModal.getters.tokenInput().type(token);
|
|
|
|
mfaSetupModal.getters.downloadRecoveryCodesButton().click();
|
|
|
|
mfaSetupModal.getters.saveButton().click();
|
2023-08-23 19:59:16 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
disableMfa: () => {
|
|
|
|
cy.visit(this.url);
|
|
|
|
this.getters.disableMfaButton().click();
|
|
|
|
},
|
2023-02-10 04:12:06 -08:00
|
|
|
};
|
|
|
|
}
|