test: add change own user data test

This commit is contained in:
Jakub P.
2024-09-24 18:42:30 +02:00
parent c8dae9ea9a
commit 55ebe2cc0b
5 changed files with 126 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ export class AuthenticatedPage extends BasePage {
super(page); super(page);
this.profileMenuButton = this.page.getByTestId('profile-menu-button'); this.profileMenuButton = this.page.getByTestId('profile-menu-button');
this.logoutMenuItem = this.page.getByTestId('logout-item');
this.adminMenuItem = this.page.getByRole('menuitem', { name: 'Admin' }); this.adminMenuItem = this.page.getByRole('menuitem', { name: 'Admin' });
this.userInterfaceDrawerItem = this.page.getByTestId( this.userInterfaceDrawerItem = this.page.getByTestId(
'user-interface-drawer-link' 'user-interface-drawer-link'
@@ -18,4 +19,9 @@ export class AuthenticatedPage extends BasePage {
this.typographyLogo = this.page.getByTestId('typography-logo'); this.typographyLogo = this.page.getByTestId('typography-logo');
this.customLogo = this.page.getByTestId('custom-logo'); this.customLogo = this.page.getByTestId('custom-logo');
} }
async logout() {
await this.profileMenuButton.click();
await this.logoutMenuItem.click();
}
} }

View File

@@ -35,7 +35,7 @@ exports.test = test.extend({
userInterfacePage: async ({ page }, use) => { userInterfacePage: async ({ page }, use) => {
await use(new UserInterfacePage(page)); await use(new UserInterfacePage(page));
}, },
...adminFixtures ...adminFixtures,
}); });
exports.publicTest = test.extend({ exports.publicTest = test.extend({
@@ -49,21 +49,18 @@ exports.publicTest = test.extend({
await use(loginPage); await use(loginPage);
}, },
acceptInvitationPage: async ({ page }, use) => { acceptInvitationPage: async ({ page }, use) => {
const acceptInvitationPage = new AcceptInvitation(page); const acceptInvitationPage = new AcceptInvitation(page);
await use(acceptInvitationPage); await use(acceptInvitationPage);
}, },
adminSetupPage: async ({ page }, use) => { adminSetupPage: async ({ page }, use) => {
const adminSetupPage = new AdminSetupPage(page); const adminSetupPage = new AdminSetupPage(page);
await use(adminSetupPage); await use(adminSetupPage);
}, },
adminCreateUserPage: async ({ page }, use) => {
adminCreateUserPage: async ({page}, use) => {
const adminCreateUserPage = new AdminCreateUserPage(page); const adminCreateUserPage = new AdminCreateUserPage(page);
await use(adminCreateUserPage); await use(adminCreateUserPage);
} },
}); });
expect.extend({ expect.extend({

View File

@@ -0,0 +1,21 @@
const { AuthenticatedPage } = require('./authenticated-page');
export class MyProfilePage extends AuthenticatedPage {
constructor(page) {
super(page);
this.fullName = this.page.locator('[name="fullName"]');
this.email = this.page.locator('[name="email"]');
this.newPassword = this.page.locator('[name="password"]');
this.passwordConfirmation = this.page.locator('[name="confirmPassword"]');
this.updateProfileButton = this.page.getByTestId('update-profile-button');
this.settingsMenuItem = this.page.getByRole('menuitem', {
name: 'Settings',
});
}
async navigateTo() {
await this.profileMenuButton.click();
await this.settingsMenuItem.click();
}
}

View File

@@ -0,0 +1,95 @@
const { publicTest, expect } = require('../../fixtures/index');
const { AdminUsersPage } = require('../../fixtures/admin/users-page');
const { MyProfilePage } = require('../../fixtures/my-profile-page');
publicTest.describe('My Profile', () => {
publicTest(
'user should be able to change own data',
async ({ acceptInvitationPage, adminCreateUserPage, loginPage, page }) => {
let acceptInvitationLink;
adminCreateUserPage.seed(
Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)
);
const testUser = adminCreateUserPage.generateUser();
const adminUsersPage = new AdminUsersPage(page);
const myProfilePage = new MyProfilePage(page);
await publicTest.step('login as Admin', async () => {
await loginPage.login();
await expect(loginPage.page).toHaveURL('/flows');
});
await publicTest.step('create new user', async () => {
await adminUsersPage.navigateTo();
await adminUsersPage.createUserButton.click();
await adminCreateUserPage.fullNameInput.fill(testUser.fullName);
await adminCreateUserPage.emailInput.fill(testUser.email);
await adminCreateUserPage.roleInput.click();
await adminCreateUserPage.page
.getByRole('option', { name: 'Admin' })
.click();
await adminCreateUserPage.createButton.click();
const snackbar = await adminUsersPage.getSnackbarData(
'snackbar-create-user-success'
);
await expect(snackbar.variant).toBe('success');
});
await publicTest.step('copy invitation link', async () => {
const invitationMessage =
await adminCreateUserPage.acceptInvitationLink;
acceptInvitationLink = await invitationMessage.getAttribute('href');
});
await publicTest.step('logout', async () => {
await myProfilePage.logout();
});
await publicTest.step('accept invitation', async () => {
await page.goto(acceptInvitationLink);
await acceptInvitationPage.acceptInvitation(process.env.LOGIN_PASSWORD);
});
await publicTest.step('login as new Admin', async () => {
await loginPage.login(testUser.email, process.env.LOGIN_PASSWORD);
await expect(loginPage.loginButton).not.toBeVisible();
await expect(page).toHaveURL('/flows');
});
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.newPassword.fill(
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
);
await myProfilePage.passwordConfirmation.fill(
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
);
await myProfilePage.updateProfileButton.click();
});
await publicTest.step('logout', async () => {
await myProfilePage.logout();
});
await publicTest.step('login with new credentials', async () => {
await loginPage.login(
'a' + testUser.email,
process.env.LOGIN_PASSWORD + process.env.LOGIN_PASSWORD
);
await expect(loginPage.loginButton).not.toBeVisible();
await expect(page).toHaveURL('/flows');
});
await publicTest.step('verify changed data', async () => {
await myProfilePage.navigateTo();
await expect(myProfilePage.fullName).toHaveValue('abecadło');
await expect(myProfilePage.email).toHaveValue('a' + testUser.email);
});
}
);
});

View File

@@ -160,6 +160,7 @@ function ProfileSettings() {
variant="contained" variant="contained"
type="submit" type="submit"
disabled={!isDirty || !isValid || isSubmitting} disabled={!isDirty || !isValid || isSubmitting}
data-test="update-profile-button"
> >
{formatMessage('profileSettings.updateProfile')} {formatMessage('profileSettings.updateProfile')}
</Button> </Button>