test: add reset password tests

This commit is contained in:
Jakub P.
2024-09-27 23:16:16 +02:00
parent d3caadf4af
commit eb814c2fb0
2 changed files with 110 additions and 16 deletions

View File

@@ -6,9 +6,11 @@ export class MyProfilePage extends AuthenticatedPage {
this.fullName = this.page.locator('[name="fullName"]');
this.email = this.page.locator('[name="email"]');
this.currentPassword = this.page.locator('[name="currentPassword"]');
this.newPassword = this.page.locator('[name="password"]');
this.passwordConfirmation = this.page.locator('[name="confirmPassword"]');
this.updateProfileButton = this.page.getByTestId('update-profile-button');
this.updatePasswordButton = this.page.getByTestId('update-password-button');
this.settingsMenuItem = this.page.getByRole('menuitem', {
name: 'Settings',
});

View File

@@ -1,17 +1,19 @@
const { publicTest, expect } = require('../../fixtures/index');
const { AdminUsersPage } = require('../../fixtures/admin/users-page');
const { MyProfilePage } = require('../../fixtures/my-profile-page');
const { LoginPage } = require('../../fixtures/login-page');
publicTest.describe('My Profile', () => {
publicTest(
'user should be able to change own data',
let testUser;
publicTest.beforeEach(
async ({ acceptInvitationPage, adminCreateUserPage, loginPage, page }) => {
let acceptInvitationLink;
adminCreateUserPage.seed(
Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)
);
const testUser = adminCreateUserPage.generateUser();
testUser = adminCreateUserPage.generateUser();
const adminUsersPage = new AdminUsersPage(page);
const myProfilePage = new MyProfilePage(page);
@@ -49,27 +51,76 @@ publicTest.describe('My Profile', () => {
await publicTest.step('accept invitation', async () => {
await page.goto(acceptInvitationLink);
await acceptInvitationPage.acceptInvitation(process.env.LOGIN_PASSWORD);
await acceptInvitationPage.acceptInvitation(LoginPage.defaultPassword);
});
await publicTest.step('login as new Admin', async () => {
await loginPage.login(testUser.email, process.env.LOGIN_PASSWORD);
await loginPage.login(testUser.email, LoginPage.defaultPassword);
await expect(loginPage.loginButton).not.toBeVisible();
await expect(page).toHaveURL('/flows');
});
}
);
publicTest('user should be able to change own data', async ({ page }) => {
const myProfilePage = new MyProfilePage(page);
await publicTest.step('change own data', async () => {
await myProfilePage.navigateTo();
await myProfilePage.fullName.fill('abecadło');
await myProfilePage.email.fill('a' + testUser.email);
await myProfilePage.updateProfileButton.click();
});
await publicTest.step('verify changed data', async () => {
await expect(myProfilePage.fullName).toHaveValue('abecadło');
await expect(myProfilePage.email).toHaveValue('a' + testUser.email);
await page.reload();
await expect(myProfilePage.fullName).toHaveValue('abecadło');
await expect(myProfilePage.email).toHaveValue('a' + testUser.email);
});
});
publicTest(
'user should not be able to change email to already existing one',
async ({ page }) => {
const myProfilePage = new MyProfilePage(page);
await publicTest.step('change email to existing one', async () => {
await myProfilePage.navigateTo();
await myProfilePage.email.fill(LoginPage.defaultEmail);
await myProfilePage.updateProfileButton.click();
});
await publicTest.step('verify error message', async () => {
const snackbar = await myProfilePage.getSnackbarData(
'snackbar-update-profile-settings-error'
);
await expect(snackbar.variant).toBe('error');
});
}
);
publicTest(
'user should be able to change own password',
async ({ loginPage, page }) => {
const myProfilePage = new MyProfilePage(page);
await publicTest.step('change own password', async () => {
await myProfilePage.navigateTo();
await myProfilePage.currentPassword.fill(LoginPage.defaultPassword);
await myProfilePage.newPassword.fill(
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
LoginPage.defaultPassword + LoginPage.defaultPassword
);
await myProfilePage.passwordConfirmation.fill(
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
LoginPage.defaultPassword + LoginPage.defaultPassword
);
await myProfilePage.updateProfileButton.click();
await myProfilePage.updatePasswordButton.click();
});
await publicTest.step('logout', async () => {
@@ -78,17 +129,58 @@ publicTest.describe('My Profile', () => {
await publicTest.step('login with new credentials', async () => {
await loginPage.login(
'a' + testUser.email,
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
testUser.email,
LoginPage.defaultPassword + LoginPage.defaultPassword
);
await expect(loginPage.loginButton).not.toBeVisible();
await expect(page).toHaveURL('/flows');
});
await publicTest.step('verify changed data', async () => {
await publicTest.step('verify if user is the same', async () => {
await myProfilePage.navigateTo();
await expect(myProfilePage.fullName).toHaveValue('abecadło');
await expect(myProfilePage.email).toHaveValue('a' + testUser.email);
await expect(myProfilePage.email).toHaveValue(testUser.email);
});
}
);
publicTest(
'user should not be able to change own password if current one is incorrect',
async ({ loginPage, page }) => {
const myProfilePage = new MyProfilePage(page);
await publicTest.step('change own password', async () => {
await myProfilePage.navigateTo();
await myProfilePage.currentPassword.fill('wrongpassword');
await myProfilePage.newPassword.fill(
LoginPage.defaultPassword + LoginPage.defaultPassword
);
await myProfilePage.passwordConfirmation.fill(
LoginPage.defaultPassword + LoginPage.defaultPassword
);
await myProfilePage.updatePasswordButton.click();
});
await publicTest.step('verify error message', async () => {
const snackbar = await myProfilePage.getSnackbarData(
'snackbar-update-password-error'
);
await expect(snackbar.variant).toBe('error');
});
await publicTest.step('logout', async () => {
await myProfilePage.logout();
});
await publicTest.step('login with old credentials', async () => {
await loginPage.login(testUser.email, LoginPage.defaultPassword);
await expect(loginPage.loginButton).not.toBeVisible();
await expect(page).toHaveURL('/flows');
});
await publicTest.step('verify if user is the same', async () => {
await myProfilePage.navigateTo();
await expect(myProfilePage.email).toHaveValue(testUser.email);
});
}
);