From aa7f0fbcd5b7b8348be3123a02a9792afb062aa5 Mon Sep 17 00:00:00 2001 From: Alexis Date: Tue, 5 Mar 2024 11:41:30 +0100 Subject: [PATCH] add complete user set password process test to the 'created user can log to his account' test --- .../first-connexion/+page.svelte | 2 +- .../tests/functional/user-permissions.test.ts | 61 +++++++++++-------- frontend/tests/utils/test-utils.ts | 1 - 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/frontend/src/routes/(authentication)/first-connexion/+page.svelte b/frontend/src/routes/(authentication)/first-connexion/+page.svelte index 0f39faee3..b801dc4cd 100644 --- a/frontend/src/routes/(authentication)/first-connexion/+page.svelte +++ b/frontend/src/routes/(authentication)/first-connexion/+page.svelte @@ -57,7 +57,7 @@ label="Confirm new password" />

-

diff --git a/frontend/tests/functional/user-permissions.test.ts b/frontend/tests/functional/user-permissions.test.ts index 701b06eae..713096538 100644 --- a/frontend/tests/functional/user-permissions.test.ts +++ b/frontend/tests/functional/user-permissions.test.ts @@ -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(); @@ -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'); @@ -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(); diff --git a/frontend/tests/utils/test-utils.ts b/frontend/tests/utils/test-utils.ts index 16c8271ca..6f165f93e 100644 --- a/frontend/tests/utils/test-utils.ts +++ b/frontend/tests/utils/test-utils.ts @@ -35,7 +35,6 @@ type Fixtures = { export const test = base.extend({ mailer: async ({ context }, use) => { await use(new Mailer(await context.newPage())); - await context.close(); }, sideBar: async ({ page }, use) => {