(e2e) add specific accounts for testing

This creates a bunch of accounts with various profiles
to allow testing in a specific "mode"
This commit is contained in:
Quentin BEY
2024-11-13 16:54:54 +01:00
committed by BEY Quentin
parent 6123e11dd4
commit 59f3499799
13 changed files with 394 additions and 48 deletions

View File

@@ -1,18 +1,27 @@
import { Page, expect } from '@playwright/test';
export const keyCloakSignIn = async (page: Page, browserName: string) => {
export const keyCloakSignIn = async (
page: Page,
browserName: string,
accountName?: string,
) => {
// Use the account name to use a specific account defined in
// the Keycloak/backend demo data creation script.
const title = await page.locator('h1').first().textContent({
timeout: 5000,
});
if (title?.includes('Sign in to your account')) {
await page
.getByRole('textbox', { name: 'username' })
.fill(`user-e2e-${browserName}`);
const username = accountName
? `jean.${accountName}`
: `user-e2e-${browserName}`;
const password = accountName
? `password-e2e-jean.${accountName}`
: `password-e2e-${browserName}`;
await page
.getByRole('textbox', { name: 'password' })
.fill(`password-e2e-${browserName}`);
if (title?.includes('Sign in to your account')) {
await page.getByRole('textbox', { name: 'username' }).fill(username);
await page.getByRole('textbox', { name: 'password' }).fill(password);
await page.click('input[type="submit"]', { force: true });
}

View File

@@ -3,12 +3,10 @@ import { expect, test } from '@playwright/test';
import { keyCloakSignIn } from './common';
test.describe('Config', () => {
test.beforeEach(async ({ page, browserName }) => {
test('it checks the config api is called', async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
});
test('it checks the config api is called', async ({ page }) => {
const responsePromise = page.waitForResponse(
(response) =>
response.url().includes('/config/') && response.status() === 200,
@@ -35,7 +33,12 @@ test.describe('Config', () => {
test('it checks that the config can deactivate the feature "teams"', async ({
page,
browserName,
}) => {
await page.goto('/');
// Login with a user who has the visibility on the groups
await keyCloakSignIn(page, browserName, 'team-member');
await page.route('**/api/v1.0/config/', async (route) => {
const request = route.request();
if (request.method().includes('GET')) {
@@ -61,10 +64,6 @@ test.describe('Config', () => {
}),
).toBeHidden();
await expect(
page.getByRole('button', {
name: 'Add a mail domain',
}),
).toBeVisible();
await expect(page.getByText('Mail Domains')).toBeVisible();
});
});

View File

@@ -41,7 +41,7 @@ test.describe('Keyboard navigation', () => {
const page = await browser.newPage();
await page.goto('/');
await keyCloakSignIn(page, browserName);
await keyCloakSignIn(page, browserName, 'team-owner-mail-member');
void mockApiRequests(page);

View File

@@ -10,22 +10,14 @@ test.describe('Language', () => {
});
test('checks the language picker', async ({ page }) => {
await expect(
page.getByRole('button', {
name: 'Create a new team',
}),
).toBeVisible();
await expect(page.getByText('Groups')).toBeVisible();
const header = page.locator('header').first();
await header.getByRole('combobox').getByText('EN').click();
await header.getByRole('option', { name: 'FR' }).click();
await expect(header.getByRole('combobox').getByText('FR')).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Créer un nouveau groupe',
}),
).toBeVisible();
await expect(page.getByText('Groupes')).toBeVisible();
});
test('checks lang attribute of html tag updates when user changes language', async ({

View File

@@ -130,7 +130,8 @@ const navigateToMailboxCreationFormForMailDomainFr = async (
test.describe('Mail domain create mailbox', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
// Login with a user who has the visibility on the mail domains
await keyCloakSignIn(page, browserName, 'mail-member');
});
test('checks user can create a mailbox when he has post ability', async ({

View File

@@ -113,14 +113,13 @@ const assertFilledMailboxesTableElementsAreVisible = async (
};
test.describe('Mail domain', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
});
test('redirects to 404 page when the mail domain requested does not exist', async ({
page,
browserName,
}) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
await page.route('**/api/v1.0/mail-domains/?page=*', async (route) => {
await route.fulfill({
json: {
@@ -143,6 +142,11 @@ test.describe('Mail domain', () => {
});
test.describe('user is administrator or owner', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName, 'mail-owner');
});
test.describe('mail domain is enabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{
@@ -479,6 +483,11 @@ test.describe('Mail domain', () => {
});
test.describe('user is member', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName, 'mail-member');
});
test.describe('mail domain is enabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{

View File

@@ -75,7 +75,7 @@ test.describe('Mail domains', () => {
test.describe('checks all the elements are visible', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
await keyCloakSignIn(page, browserName, 'mail-member');
});
test('checks the sort button', async ({ page }) => {

View File

@@ -4,7 +4,7 @@ import { addNewMember, createTeam, keyCloakSignIn } from './common';
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
await keyCloakSignIn(page, browserName, 'team-member');
});
test.describe('Members Delete', () => {
@@ -17,9 +17,7 @@ test.describe('Members Delete', () => {
const table = page.getByLabel('List members card').getByRole('table');
const cells = table.getByRole('row').nth(1).getByRole('cell');
await expect(cells.nth(1)).toHaveText(
new RegExp(`E2E ${browserName}`, 'i'),
);
await expect(cells.nth(1)).toHaveText('Jean Group Member');
await cells.nth(4).getByLabel('Member options').click();
await page.getByLabel('Open the modal to delete this member').click();
@@ -46,7 +44,7 @@ test.describe('Members Delete', () => {
// find row where regexp match the name
const cells = table
.getByRole('row')
.filter({ hasText: new RegExp(`E2E ${browserName}`, 'i') })
.filter({ hasText: 'E2E Group Member' })
.getByRole('cell');
await cells.nth(4).getByLabel('Member options').click();
await page.getByLabel('Open the modal to delete this member').click();
@@ -118,7 +116,7 @@ test.describe('Members Delete', () => {
// find row where regexp match the name
const myCells = table
.getByRole('row')
.filter({ hasText: new RegExp(`E2E ${browserName}`, 'i') })
.filter({ hasText: 'E2E Group Member' })
.getByRole('cell');
await myCells.nth(4).getByLabel('Member options').click();
@@ -148,7 +146,7 @@ test.describe('Members Delete', () => {
// find row where regexp match the name
const myCells = table
.getByRole('row')
.filter({ hasText: new RegExp(`E2E ${browserName}`, 'i') })
.filter({ hasText: 'E2E Group Member' })
.getByRole('cell');
await myCells.nth(4).getByLabel('Member options').click();

View File

@@ -4,7 +4,7 @@ import { createTeam, keyCloakSignIn } from './common';
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
await keyCloakSignIn(page, browserName, 'team-owner-mail-member');
});
test.describe('Menu', () => {