2022-05-31 18:58:59 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2022-04-22 14:33:13 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2018-10-03 09:43:10 +02:00
|
|
|
import { OrgUser } from 'app/types';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2023-01-09 11:54:33 +03:00
|
|
|
import { UsersTable, Props } from './UsersTable';
|
2018-10-03 09:43:10 +02:00
|
|
|
import { getMockUsers } from './__mocks__/userMocks';
|
|
|
|
|
|
2021-04-22 13:19:41 +03:00
|
|
|
jest.mock('app/core/core', () => ({
|
|
|
|
|
contextSrv: {
|
|
|
|
|
hasPermission: () => true,
|
2021-12-23 08:08:13 +00:00
|
|
|
hasPermissionInMetadata: () => true,
|
2022-02-03 16:27:53 +01:00
|
|
|
licensedAccessControlEnabled: () => false,
|
2021-04-22 13:19:41 +03:00
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2018-10-03 09:43:10 +02:00
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
|
const props: Props = {
|
|
|
|
|
users: [] as OrgUser[],
|
|
|
|
|
onRoleChange: jest.fn(),
|
|
|
|
|
onRemoveUser: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
2022-05-31 18:58:59 +03:00
|
|
|
render(<UsersTable {...props} />);
|
2018-10-03 09:43:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe('Render', () => {
|
|
|
|
|
it('should render component', () => {
|
2022-05-31 18:58:59 +03:00
|
|
|
expect(() => setup()).not.toThrow();
|
2018-10-03 09:43:10 +02:00
|
|
|
});
|
|
|
|
|
|
2022-05-31 18:58:59 +03:00
|
|
|
it('should render users in table', () => {
|
|
|
|
|
const usersData = getMockUsers(5);
|
|
|
|
|
setup({ users: usersData });
|
2018-10-03 09:43:10 +02:00
|
|
|
|
2022-05-31 18:58:59 +03:00
|
|
|
usersData.forEach((user) => {
|
|
|
|
|
expect(screen.getByText(user.name)).toBeInTheDocument();
|
|
|
|
|
});
|
2018-10-03 09:43:10 +02:00
|
|
|
});
|
2022-08-15 10:58:58 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
2022-11-29 15:20:28 +01:00
|
|
|
it('should render LDAP label', () => {
|
|
|
|
|
const usersData = getMockUsers(5);
|
|
|
|
|
usersData[0].authLabels = ['LDAP'];
|
|
|
|
|
setup({ users: usersData });
|
|
|
|
|
expect(screen.getByText(usersData[0].authLabels[0])).toBeInTheDocument();
|
|
|
|
|
});
|
2018-10-03 09:43:10 +02:00
|
|
|
});
|
2020-04-15 16:49:20 +02:00
|
|
|
|
|
|
|
|
describe('Remove modal', () => {
|
2022-05-31 18:58:59 +03:00
|
|
|
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();
|
2020-04-15 16:49:20 +02:00
|
|
|
});
|
|
|
|
|
});
|