0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/apps/admin-x-settings/test/e2e/general/users/roles.test.ts
Jono M 0e35baaf01
Refactored limit=all queries to be paginated in AdminX (#18324)
refs https://github.com/TryGhost/Product/issues/3832

---

### <samp>🤖 Generated by Copilot at 0095d23</samp>

The pull request adds support for asynchronous and creatable select
inputs in various components, using the `react-select` and
`@tanstack/react-query` libraries. It also adds pagination features to
the newsletters and tiers lists, using a `Button` component and infinite
queries. It refactors and fixes the type and null handling of the select
inputs and their options, using the `SelectOption` type and the
`useFilterableApi` and `debounce` hooks. It removes some unnecessary
props from the browse queries, and adds a new custom hook
`useDefaultRecipientsOptions` for the default recipients component. It
updates the stories and modals to use the new select inputs and options.
2023-09-25 14:03:47 +01:00

95 lines
3.7 KiB
TypeScript

import {expect, test} from '@playwright/test';
import {globalDataRequests, mockApi, responseFixtures} from '../../../utils/e2e';
test.describe('User roles', async () => {
test('Shows users under their role', async ({page}) => {
await mockApi({page, requests: {
...globalDataRequests,
browseUsers: {method: 'GET', path: '/users/?limit=100&include=roles', response: responseFixtures.users}
}});
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}) => {
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=100&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},
editUser: {method: 'PUT', path: `/users/${userToEdit.id}/?include=roles`, response: {
users: [{
...userToEdit,
roles: [responseFixtures.roles.roles.find(role => role.name === 'Editor')!]
}]
}}
}});
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();
await modal.getByRole('button', {name: 'Save & close'}).click();
await expect(modal.getByRole('button', {name: 'Saved'})).toBeVisible();
await expect(activeTab).toHaveText(/No authors 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/
]);
expect(lastApiRequests.editUser?.body).toMatchObject({
users: [{
email: 'author@test.com',
roles: [{
name: 'Editor'
}]
}]
});
});
});