(app-desk) create invitation

Invite the selected members to the team.
To have a successful invitation:
- none user has this email
- an invitation is not pending for this email and
  this team
This commit is contained in:
Anthony LC
2024-03-22 16:09:30 +01:00
committed by Anthony LC
parent bb9edd21da
commit 897b68038f
5 changed files with 85 additions and 20 deletions

View File

@@ -18,13 +18,9 @@ export const keyCloakSignIn = async (page: Page, browserName: string) => {
}
};
export const randomTeamsName = (
teamName: string,
browserName: string,
length: number,
) =>
export const randomName = (name: string, browserName: string, length: number) =>
Array.from({ length }, (_el, index) => {
return `${teamName}-${browserName}-${Math.floor(Math.random() * 10000)}-${index}`;
return `${browserName}-${Math.floor(Math.random() * 10000)}-${index}-${name}`;
});
export const createTeam = async (
@@ -36,7 +32,7 @@ export const createTeam = async (
const panel = page.getByLabel('Teams panel').first();
const buttonCreate = page.getByRole('button', { name: 'Create the team' });
const randomTeams = randomTeamsName(teamName, browserName, length);
const randomTeams = randomName(teamName, browserName, length);
for (let i = 0; i < randomTeams.length; i++) {
await panel.getByRole('button', { name: 'Add a team' }).click();

View File

@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test';
import { createTeam, keyCloakSignIn } from './common';
import { createTeam, keyCloakSignIn, randomName } from './common';
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
@@ -60,16 +60,31 @@ test.describe('Members Create', () => {
await expect(page.getByRole('radio', { name: 'Admin' })).toBeVisible();
});
test('it selects non existing email', async ({ page, browserName }) => {
await createTeam(page, 'member-modal-search-user', browserName, 1);
test('it sends an invitation', async ({ page, browserName }) => {
await createTeam(page, 'member-invitation', browserName, 1);
await page.getByLabel('Add members to the team').click();
const inputSearch = page.getByLabel(/Find a member to add to the team/);
await inputSearch.fill('test@test.fr');
await page.getByRole('option', { name: 'test@test.fr' }).click();
await expect(page.getByText('test@test.fr', { exact: true })).toBeVisible();
await expect(page.getByLabel(`Remove test@test.fr`)).toBeVisible();
const email = randomName('test@test.fr', browserName, 1)[0];
await inputSearch.fill(email);
await page.getByRole('option', { name: email }).click();
await expect(page.getByText(email, { exact: true })).toBeVisible();
await expect(page.getByLabel(`Remove ${email}`)).toBeVisible();
await page.getByRole('radio', { name: 'Owner' }).click();
const responsePromise = page.waitForResponse(
(response) =>
response.url().includes('/invitations/') && response.status() === 201,
);
await page.getByRole('button', { name: 'Validate' }).click();
await expect(page.getByText(`Invitation sent to ${email}`)).toBeVisible();
const response = await responsePromise;
expect(response.ok()).toBeTruthy();
});
});

View File

@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test';
import { createTeam, keyCloakSignIn, randomTeamsName } from './common';
import { createTeam, keyCloakSignIn, randomName } from './common';
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
@@ -46,7 +46,7 @@ test.describe('Team', () => {
await page.getByLabel(`Open the team options modal`).click();
const teamName = randomTeamsName('new-team-update-name', browserName, 1)[0];
const teamName = randomName('new-team-update-name', browserName, 1)[0];
await page.getByText('New name...', { exact: true }).fill(teamName);
await page