Skip to content

Commit

Permalink
add complete user set password process test to the 'created user can …
Browse files Browse the repository at this point in the history
…log to his account' test
  • Loading branch information
Alexdev8 committed Mar 5, 2024
1 parent 23ab45d commit aa7f0fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
label="Confirm new password"
/>
<p class="pt-3">
<button class="btn variant-filled-primary font-semibold w-full" type="submit"
<button class="btn variant-filled-primary font-semibold w-full" type="submit" data-testid="set-password-btn"
>{m.setPassword()}</button
>
</p>
Expand Down
61 changes: 36 additions & 25 deletions frontend/tests/functional/user-permissions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LoginPage } from '../utils/login-page.js';
import { SideBar } from '../utils/sidebar.js';
import { test, expect, setHttpResponsesListener, TestContent } from '../utils/test-utils.js';

const vars = TestContent.generateTestVars();
Expand Down Expand Up @@ -29,18 +31,6 @@ test.beforeEach('create user', async ({ logedPage, usersPage, foldersPage, sideB
});
await usersPage.form.saveButton.click();
await usersPage.isToastVisible('.+ successfully saved: ' + vars.user.email);

page.on('dialog', dialog => dialog.accept()); // Accept the alert dialog

await usersPage.editItemButton(vars.user.email).click();
await page.getByTestId('set-password-btn').click();
await expect(page).toHaveURL(/.*\/users\/.+\/edit\/set-password/);
await usersPage.form.fill({
new_password: vars.user.password,
confirm_new_password: vars.user.password
});
await usersPage.form.saveButton.click();
await usersPage.isToastVisible('The password was successfully set');

await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
Expand All @@ -50,27 +40,48 @@ test.beforeEach('create user', async ({ logedPage, usersPage, foldersPage, sideB
});

test('created user can log to his account', async ({
loginPage,
mailer,
page
}) => {
await loginPage.login(vars.user.email, vars.user.password);
await expect(page).toHaveURL(/.*\/analytics/);
await expect(mailer.page.getByText('{{').last()).toBeHidden(); // Wait for mailhog to load the emails
const lastMail = await mailer.getLastEmail();
await lastMail.hasWelcomeEmailDetails();
await lastMail.hasEmailRecipient(vars.user.email);

await lastMail.open();
const pagePromise = page.context().waitForEvent('page');
await mailer.emailContent.setPasswordButton.click();
const setPasswordPage = await pagePromise;
await setPasswordPage.waitForLoadState();
await expect(setPasswordPage).toHaveURL(await mailer.emailContent.setPasswordButton.getAttribute('href') || 'Set password link could not be found');

const setLoginPage = new LoginPage(setPasswordPage);
await setLoginPage.newPasswordInput.fill(vars.user.password);
await setLoginPage.confirmPasswordInput.fill(vars.user.password);
await setLoginPage.setPasswordButton.click();

await setLoginPage.isToastVisible('Your password was successfully set. Welcome to CISO Assistant.');

await setLoginPage.login(vars.user.email, vars.user.password);
await expect(setLoginPage.page).toHaveURL('/analytics');

// logout to prevent sessions conflicts
const sideBar = new SideBar(setPasswordPage);
await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
await expect(sideBar.logoutButton).toBeVisible();
await sideBar.logoutButton.click();
await setLoginPage.hasUrl(0);

await setPasswordPage.close();
});

test.afterEach('cleanup', async ({ loginPage, sideBar, foldersPage, usersPage, page }) => {
if (loginPage.email === vars.user.email) {
await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
await expect(sideBar.logoutButton).toBeVisible();
await sideBar.logoutButton.click();
await loginPage.hasUrl(0);
await loginPage.login();
}
test.afterEach('cleanup', async ({ loginPage, foldersPage, usersPage, page }) => {
await loginPage.login();
await foldersPage.goto();
await foldersPage.deleteItemButton(vars.folderName).click();
await foldersPage.deleteModalConfirmButton.click();
await expect(foldersPage.getRow(vars.folderName)).not.toBeVisible();

await usersPage.goto();
await usersPage.deleteItemButton(vars.user.email).click();
await usersPage.deleteModalConfirmButton.click();
Expand Down
1 change: 0 additions & 1 deletion frontend/tests/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Fixtures = {
export const test = base.extend<Fixtures>({
mailer: async ({ context }, use) => {
await use(new Mailer(await context.newPage()));
await context.close();
},

sideBar: async ({ page }, use) => {
Expand Down

0 comments on commit aa7f0fb

Please sign in to comment.