Skip to content

Commit

Permalink
Merge pull request #85 from intuitem/CA-191-Test-that-user-permission…
Browse files Browse the repository at this point in the history
…s-are-working-correctly

Ca 191 Test that a created user can login to his account
  • Loading branch information
eric-intuitem authored Feb 28, 2024
2 parents 71977c6 + 625b9c5 commit c1d8247
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 135 deletions.
3 changes: 2 additions & 1 deletion frontend/src/routes/(app)/users/[id=uuid]/edit/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<p class="text-gray-500 text-sm">
In case the user cannot set their own password, you can <a
href="{$page.url.pathname}/set-password"
class="text-primary-700 hover:text-primary-500">set a temporary password</a
class="text-primary-700 hover:text-primary-500"
data-testid="set-password-btn">set a temporary password</a
>. Please use a strong one and make sure to inform the user to change it as soon as possible.
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
mandatory
/>
<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" data-testid="save-button" type="submit"
>Set Password</button
>
</p>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/(authentication)/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
href="/password-reset"
class="flex items-center space-x-2 text-primary-800 hover:text-primary-600"
>
<p class="">Forgot password?</p>
<p class="" data-testid="forgot-password-btn">Forgot password?</p>
</a>
</div>
<p class="">
<button class="btn variant-filled-primary font-semibold w-full" type="submit"
<button class="btn variant-filled-primary font-semibold w-full" data-testid="login-btn" type="submit"
>Log in</button
>
</p>
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -h " ]] || [[ " ${SCRIPT_LONG_ARGS[@]} "
echo " --retries=COUNT Set the number of retries for the tests"
echo " --timeout=MS Set the timeout for the tests in milliseconds"
echo " -v Show the output of the backend server"
echo " --workers=COUNT Number of concurrent workers or percentage of logical CPU cores, use 1 to run in a single worker (default: 1)"
echo -e " --workers=COUNT Number of concurrent workers or percentage of logical CPU cores, use 1 to run in a single worker (default: 1)\nBe aware that increasing the number of workers may reduce tests accuracy and stability."
exit 0
fi

Expand Down
9 changes: 2 additions & 7 deletions frontend/tests/functional/detailed/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ baseTest.skip('login page as expected title', async ({ page }) => {
await expect.soft(page.getByRole('heading', { name: 'Hello there 👋' })).toBeVisible();
});

test('login / logout process is working properly', async ({
loginPage,
analyticsPage: overviewPage,
sideBar,
page
}) => {
test('login / logout process is working properly', async ({ loginPage, analyticsPage, sideBar, page }) => {
await loginPage.hasUrl(1);
await expect.soft(page.getByRole('heading', { name: 'Login into your account' })).toBeVisible();
await loginPage.login();
await overviewPage.hasUrl();
await analyticsPage.hasUrl();
sideBar.moreButton.click();
sideBar.logoutButton.click();
await loginPage.hasUrl(0);
Expand Down
58 changes: 29 additions & 29 deletions frontend/tests/functional/nav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ type StringMap = {
};

test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, page }) => {
test.slow();

await test.step('proper redirection to the overview page after login', async () => {
await analyticsPage.hasUrl();
await analyticsPage.hasTitle();
setHttpResponsesListener(page);
});

await test.step('navigation link are working properly', async () => {
//TODO delete this when page titles are fixed
const temporaryPageTitle: StringMap = {
'X-Rays': 'X rays',
'Backup & restore': 'Backup restore'
};
test.slow();
await test.step('proper redirection to the analytics page after login', async () => {
await analyticsPage.hasUrl();
await analyticsPage.hasTitle();
setHttpResponsesListener(page);
});
await test.step('navigation link are working properly', async () => {
//TODO delete this when page titles are fixed
const temporaryPageTitle: StringMap = {
'X-Rays': "X rays",
'Backup & restore': "Backup restore"
};

const locals = localItems(languageTag());

for await (const [key, value] of sideBar.items) {
for await (const item of value) {
if (item.href !== '/role-assignments') {
await sideBar.click(key, item.href);
await expect(page).toHaveURL(item.href);
if (item.name in temporaryPageTitle) {
await expect.soft(logedPage.pageTitle).toHaveText([temporaryPageTitle[item.name]]);
} else {
await expect.soft(logedPage.pageTitle).toHaveText(locals[item.name]);
}
}
}
}
});
for await (const [key, value] of sideBar.items) {
for await (const item of value) {
if (item.href !== '/role-assignments') {
await sideBar.click(key, item.href);
await expect(page).toHaveURL(item.href);
if (item.name in temporaryPageTitle) {
await expect.soft(logedPage.pageTitle).toHaveText(temporaryPageTitle[item.name]);
} else {
await expect.soft(logedPage.pageTitle).toHaveText(locals[item.name]);
}
}
}
}
});

await test.step('user email is showing properly', async () => {
await expect(page.getByTestId('sidebar-user-account-display')).toHaveText(logedPage.email);
Expand Down
22 changes: 11 additions & 11 deletions frontend/tests/functional/startup.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { test } from '../utils/test-utils.js';

test('startup tests', async ({ loginPage, analyticsPage: overviewPage, page }) => {
await test.step('proper redirection to the login page', async () => {
await page.goto('/');
await loginPage.hasUrl(1);
await loginPage.login();
await overviewPage.hasUrl();
});
test('startup tests', async ({ loginPage, analyticsPage, page }) => {
await test.step('proper redirection to the login page', async () => {
await page.goto('/');
await loginPage.hasUrl(1);
await loginPage.login();
await analyticsPage.hasUrl();
});

await test.step('proper redirection to the overview page after login', async () => {
await overviewPage.hasUrl();
await overviewPage.hasTitle();
});
await test.step('proper redirection to the analytics page after login', async () => {
await analyticsPage.hasUrl();
await analyticsPage.hasTitle();
});
});
78 changes: 78 additions & 0 deletions frontend/tests/functional/user-permissions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { test, expect, setHttpResponsesListener, TestContent } from '../utils/test-utils.js';

const vars = TestContent.generateTestVars();

test.beforeEach('create user', async ({ logedPage, usersPage, foldersPage, sideBar, page }) => {
setHttpResponsesListener(page);

await foldersPage.goto();
await foldersPage.createItem({
name: vars.folderName,
description: vars.description
});

await usersPage.goto();
await usersPage.createItem({
email: vars.user.email
});

await usersPage.editItemButton(vars.user.email).click();
await usersPage.form.fill({
first_name: vars.user.firstName,
last_name: vars.user.lastName,
user_groups: [
`${vars.folderName} - ${vars.usergroups.analyst}`,
`${vars.folderName} - ${vars.usergroups.auditor}`,
`${vars.folderName} - ${vars.usergroups.domainManager}`,
`${vars.folderName} - ${vars.usergroups.validator}`,
],
});
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');
await expect(sideBar.logoutButton).toBeVisible();
await sideBar.logoutButton.click();
await logedPage.hasUrl(0);
});

test('created user can log to his account', async ({
loginPage,
page
}) => {
await loginPage.login(vars.user.email, vars.user.password);
await expect(page).toHaveURL(/.*\/analytics/);
});

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();
}
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();
await expect(usersPage.getRow(vars.user.email)).not.toBeVisible();
});
Loading

0 comments on commit c1d8247

Please sign in to comment.