Skip to content

Commit

Permalink
add the test architecture for created users with specific user groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdev8 committed Feb 19, 2024
1 parent 915dd48 commit 328711e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 9 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
10 changes: 5 additions & 5 deletions frontend/tests/functional/nav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ test('sidebar navigation tests', async ({ logedPage, analyticsPage, sideBar, pag

await test.step('more panel links are working properly', async () => {
await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert')
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
await expect(sideBar.profileButton).toBeVisible();
await sideBar.profileButton.click();
await expect(sideBar.morePanel).toHaveAttribute('inert')
await expect(sideBar.morePanel).toHaveAttribute('inert');
await expect(page).toHaveURL('/profile');
await expect.soft(logedPage.pageTitle).toHaveText('Profile');

await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert')
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
await expect(sideBar.aboutButton).toBeVisible();
await sideBar.aboutButton.click();
await expect(sideBar.morePanel).toHaveAttribute('inert')
await expect(sideBar.morePanel).toHaveAttribute('inert');
await expect(logedPage.modalTitle).toBeVisible();
await expect.soft(logedPage.modalTitle).toHaveText('About CISO Assistant');
await page.mouse.click(20, 20); // click outside the modal to close it
await expect(logedPage.modalTitle).not.toBeVisible();

await sideBar.moreButton.click();
await expect(sideBar.morePanel).not.toHaveAttribute('inert')
await expect(sideBar.morePanel).not.toHaveAttribute('inert');
await expect(sideBar.logoutButton).toBeVisible();
await sideBar.logoutButton.click();
await logedPage.hasUrl(0);
Expand Down
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();
});
2 changes: 1 addition & 1 deletion frontend/tests/utils/form-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class FormContent {
this.saveButton = this.page.getByTestId("save-button");
this.cancelButton = this.page.getByTestId("cancel-button");
this.name = name;
this.fields = new Map(fields.map(field => [field.name, {locator: this.page.getByTestId("form-input-" + field.name.replace('_', '-')), type: field.type}]));
this.fields = new Map(fields.map(field => [field.name, {locator: this.page.getByTestId("form-input-" + field.name.replaceAll('_', '-')), type: field.type}]));
}

async fill(values: { [k: string]: any }) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/utils/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
file2: new URL('../utils/test_file.txt', import.meta.url).pathname,
user: {
email: "[email protected]",
password: "password",
password: "pass123wordTest",
firstName: "Test",
lastName: "User",
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/tests/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export const test = base.extend<Fixtures>({
{ name: 'last_name', type: type.TEXT },
{ name: 'user_groups', type: type.SELECT_MULTIPLE_AUTOCOMPLETE },
{ name: 'is_active', type: type.CHECKBOX },
{ name: 'new_password', type: type.TEXT },
{ name: 'confirm_new_password', type: type.TEXT },
]);
await use(uPage);
},
Expand Down

0 comments on commit 328711e

Please sign in to comment.