-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(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
- Loading branch information
1 parent
aa7bb87
commit ec47642
Showing
7 changed files
with
209 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/react'; | |
import { AppWrapper } from '@/tests/utils'; | ||
|
||
import { MainLayout } from '../MainLayout'; | ||
import { useAuthStore } from '../auth'; | ||
import { useConfigStore } from '../config'; | ||
|
||
jest.mock('next/navigation', () => ({ | ||
|
@@ -19,6 +20,19 @@ describe('MainLayout', () => { | |
useConfigStore.setState({ | ||
config: { RELEASE: '1.0.0', FEATURES: { TEAMS: true }, LANGUAGES: [] }, | ||
}); | ||
useAuthStore.setState({ | ||
authenticated: true, | ||
userData: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
abilities: { | ||
contacts: { canView: true }, | ||
teams: { canView: true }, | ||
mailboxes: { canView: true }, | ||
}, | ||
}, | ||
}); | ||
|
||
render(<MainLayout />, { wrapper: AppWrapper }); | ||
|
||
|
@@ -35,10 +49,57 @@ describe('MainLayout', () => { | |
).toBeInTheDocument(); | ||
}); | ||
|
||
it('checks menu rendering with no abilities', () => { | ||
useConfigStore.setState({ | ||
config: { RELEASE: '1.0.0', FEATURES: { TEAMS: true }, LANGUAGES: [] }, | ||
}); | ||
useAuthStore.setState({ | ||
authenticated: true, | ||
userData: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
abilities: { | ||
contacts: { canView: false }, | ||
teams: { canView: false }, | ||
mailboxes: { canView: false }, | ||
}, | ||
}, | ||
}); | ||
|
||
render(<MainLayout />, { wrapper: AppWrapper }); | ||
|
||
expect( | ||
screen.queryByRole('button', { | ||
// Changé de getByRole à queryByRole | ||
name: /Teams button/i, | ||
}), | ||
).not.toBeInTheDocument(); // | ||
|
||
expect( | ||
screen.queryByRole('button', { | ||
name: /Mail Domains button/i, | ||
}), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('checks menu rendering without team feature', () => { | ||
useConfigStore.setState({ | ||
config: { RELEASE: '1.0.0', FEATURES: { TEAMS: false }, LANGUAGES: [] }, | ||
}); | ||
useAuthStore.setState({ | ||
authenticated: true, | ||
userData: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
abilities: { | ||
contacts: { canView: true }, | ||
teams: { canView: true }, | ||
mailboxes: { canView: true }, | ||
}, | ||
}, | ||
}); | ||
|
||
render(<MainLayout />, { wrapper: AppWrapper }); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,11 @@ describe('getMailDomainAccesses', () => { | |
{ | ||
id: '2', | ||
role: Role.VIEWER, | ||
user: { id: '12', name: 'username2', email: '[email protected]' }, | ||
user: { | ||
id: '12', | ||
name: 'username2', | ||
email: '[email protected]', | ||
}, | ||
can_set_role_to: [Role.VIEWER], | ||
}, | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,92 @@ 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": "[email protected]", | ||
"language": "en-us", | ||
"name": "E2E Chromium", | ||
"timezone": "UTC", | ||
"is_device": false, | ||
"is_staff": false, | ||
"abilities": { | ||
"contacts": { | ||
"canView": true, | ||
"canCreate": true | ||
}, | ||
"teams": { | ||
"canView": true, | ||
"canCreate": false | ||
}, | ||
"mailboxes": { | ||
"canView": true, | ||
"canCreate": 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": "[email protected]", | ||
"language": "en-us", | ||
"name": "E2E ChromiumMM", | ||
"timezone": "UTC", | ||
"is_device": false, | ||
"is_staff": false, | ||
"abilities": { | ||
"contacts": { | ||
"canView": true, | ||
"canCreate": true | ||
}, | ||
"teams": { | ||
"canView": true, | ||
"canCreate": true | ||
}, | ||
"mailboxes": { | ||
"canView": true, | ||
"canCreate": 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, | ||
|