(frontend) use user abilities to show or not the features

use the abilities to show or not the Teams / Mailbox features as well as the
object creation button
This commit is contained in:
Nathan Panchout
2024-11-12 10:22:49 +01:00
committed by BEY Quentin
parent 6be1b63277
commit 6123e11dd4
7 changed files with 205 additions and 24 deletions

View File

@@ -13,7 +13,7 @@ test.describe('Menu', () => {
name: 'Teams',
isDefault: true,
expectedUrl: '/teams/',
expectedText: 'Create a new team',
expectedText: 'Teams',
},
{
name: 'Mail Domains',
@@ -62,6 +62,94 @@ test.describe('Menu', () => {
});
}
test(`it checks that the menu is not displaying when no abilities`, async ({
page,
}) => {
await page.route('**/api/v1.0/users/me/', async (route) => {
await route.fulfill({
json: {
id: '52de4dcf-5ca0-4b7f-9841-3a18e8cb6a95',
email: 'user@chromium.e2e',
language: 'en-us',
name: 'E2E Chromium',
timezone: 'UTC',
is_device: false,
is_staff: false,
abilities: {
contacts: {
can_view: true,
can_create: true,
},
teams: {
can_view: true,
can_create: false,
},
mailboxes: {
can_view: true,
can_create: false,
},
},
},
});
});
const menu = page.locator('menu').first();
let buttonMenu = menu.getByLabel(`Teams button`);
await buttonMenu.click();
await expect(
page.getByText('Click on team to view details').first(),
).toBeVisible();
buttonMenu = menu.getByLabel(`Mail Domains`);
await buttonMenu.click();
await expect(
page.getByText('Click on mailbox to view details').first(),
).toBeVisible();
});
test(`it checks that the menu is not displaying when all abilities`, async ({
page,
}) => {
await page.route('**/api/v1.0/users/me/', async (route) => {
await route.fulfill({
json: {
id: '52de4dcf-5ca0-4b7f-9841-3a18e8cb6a95',
email: 'user@chromium.e2e',
language: 'en-us',
name: 'E2E ChromiumMM',
timezone: 'UTC',
is_device: false,
is_staff: false,
abilities: {
contacts: {
can_view: true,
can_create: true,
},
teams: {
can_view: true,
can_create: true,
},
mailboxes: {
can_view: true,
can_create: true,
},
},
},
});
});
const menu = page.locator('menu').first();
let buttonMenu = menu.getByLabel(`Teams button`);
await buttonMenu.click();
await expect(page.getByText('Create a new team').first()).toBeVisible();
buttonMenu = menu.getByLabel(`Mail Domains`);
await buttonMenu.click();
await expect(page.getByText('Add a mail domain').first()).toBeVisible();
});
test(`it checks that the sub menu is still highlighted`, async ({
page,
browserName,