2023-06-26 06:12:46 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-08-03 11:29:14 +03:00
|
|
|
import {globalDataRequests, mockApi, responseFixtures} from '../../../utils/e2e';
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
test.describe('User roles', async () => {
|
|
|
|
test('Shows users under their role', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseUsers: {method: 'GET', path: '/users/?limit=all&include=roles', response: responseFixtures.users}
|
|
|
|
}});
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
|
|
|
|
await expect(section.getByTestId('owner-user')).toHaveText(/owner@test\.com/);
|
|
|
|
|
|
|
|
await expect(section.getByRole('tab')).toHaveText([
|
|
|
|
'Administrators',
|
|
|
|
'Editors',
|
|
|
|
'Authors',
|
|
|
|
'Contributors',
|
|
|
|
'Invited'
|
|
|
|
]);
|
|
|
|
|
|
|
|
const activeTab = section.locator('[role=tabpanel]:not(.hidden)');
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Administrators'}).click();
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveText(/administrator@test\.com/);
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Editors'}).click();
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveText(/editor@test\.com/);
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Authors'}).click();
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveText(/author@test\.com/);
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Contributors'}).click();
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveText(/contributor@test\.com/);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Supports changing user role', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const userToEdit = responseFixtures.users.users.find(user => user.email === 'author@test.com')!;
|
|
|
|
|
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseUsers: {method: 'GET', path: '/users/?limit=all&include=roles', response: responseFixtures.users},
|
|
|
|
browseRoles: {method: 'GET', path: '/roles/?limit=all', response: responseFixtures.roles},
|
|
|
|
browseAssignableRoles: {method: 'GET', path: '/roles/?limit=all&permissions=assign', response: responseFixtures.roles},
|
2023-08-10 15:04:23 +03:00
|
|
|
editUser: {method: 'PUT', path: `/users/${userToEdit.id}/?include=roles`, response: {
|
2023-08-03 11:29:14 +03:00
|
|
|
users: [{
|
|
|
|
...userToEdit,
|
|
|
|
roles: [responseFixtures.roles.roles.find(role => role.name === 'Editor')!]
|
|
|
|
}]
|
|
|
|
}}
|
2023-06-26 06:12:46 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
const activeTab = section.locator('[role=tabpanel]:not(.hidden)');
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Authors'}).click();
|
|
|
|
|
|
|
|
const listItem = activeTab.getByTestId('user-list-item').last();
|
|
|
|
await listItem.hover();
|
|
|
|
await listItem.getByRole('button', {name: 'Edit'}).click();
|
|
|
|
|
|
|
|
const modal = page.getByTestId('user-detail-modal');
|
|
|
|
|
|
|
|
await modal.locator('input[value=editor]').check();
|
|
|
|
|
2023-07-26 13:47:52 +03:00
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
await expect(modal.getByRole('button', {name: 'Saved'})).toBeVisible();
|
|
|
|
|
|
|
|
await expect(activeTab).toHaveText(/No users found/);
|
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Editors'}).click();
|
|
|
|
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveCount(2);
|
|
|
|
|
|
|
|
await expect(activeTab.getByTestId('user-list-item')).toHaveText([
|
|
|
|
/author@test\.com/,
|
|
|
|
/editor@test\.com/
|
|
|
|
]);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editUser?.body).toMatchObject({
|
2023-06-26 06:12:46 +03:00
|
|
|
users: [{
|
|
|
|
email: 'author@test.com',
|
|
|
|
roles: [{
|
|
|
|
name: 'Editor'
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|