mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add auth labels and access control metadata to org users search results
* Fix search result JSON model
* Org users: Use API for pagination
* Fix default page size
* Refactor: UsersListPage to functional component
* Refactor: update UsersTable component code style
* Add pagination to the /orgs/{org_id}/users endpoint
* Use pagination on the AdminEditOrgPage
* Add /orgs/{org_id}/users/search endpoint to prevent breaking API
* Use existing search store method
* Remove unnecessary error
* Remove unused
* Add query param to search endpoint
* Fix endpoint docs
* Minor refactor
* Fix number of pages calculation
* Use SearchOrgUsers for all org users methods
* Refactor: GetOrgUsers as a service method
* Minor refactor: rename orgId => orgID
* Fix integration tests
* Fix tests
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { OrgUser } from 'app/types';
|
|
|
|
import { UsersTable, Props } from './UsersTable';
|
|
import { getMockUsers } from './__mocks__/userMocks';
|
|
|
|
jest.mock('app/core/core', () => ({
|
|
contextSrv: {
|
|
hasPermission: () => true,
|
|
hasPermissionInMetadata: () => true,
|
|
licensedAccessControlEnabled: () => false,
|
|
},
|
|
}));
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
const props: Props = {
|
|
users: [] as OrgUser[],
|
|
onRoleChange: jest.fn(),
|
|
onRemoveUser: jest.fn(),
|
|
};
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
render(<UsersTable {...props} />);
|
|
};
|
|
|
|
describe('Render', () => {
|
|
it('should render component', () => {
|
|
expect(() => setup()).not.toThrow();
|
|
});
|
|
|
|
it('should render users in table', () => {
|
|
const usersData = getMockUsers(5);
|
|
setup({ users: usersData });
|
|
|
|
usersData.forEach((user) => {
|
|
expect(screen.getByText(user.name)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should render disabled flag when any of the Users are disabled', () => {
|
|
const usersData = getMockUsers(5);
|
|
usersData[0].isDisabled = true;
|
|
setup({ users: usersData });
|
|
|
|
expect(screen.getByText('Disabled')).toBeInTheDocument();
|
|
});
|
|
it('should render LDAP label', () => {
|
|
const usersData = getMockUsers(5);
|
|
usersData[0].authLabels = ['LDAP'];
|
|
setup({ users: usersData });
|
|
expect(screen.getByText(usersData[0].authLabels[0])).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('Remove modal', () => {
|
|
it('should render confirm check on delete', async () => {
|
|
const usersData = getMockUsers(3);
|
|
setup({ users: usersData });
|
|
const user = userEvent.setup();
|
|
|
|
await user.click(screen.getAllByRole('button', { name: /delete/i })[0]);
|
|
|
|
expect(screen.getByText(/are you sure/i)).toBeInTheDocument();
|
|
});
|
|
});
|