2018-10-03 02:43:10 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import UsersTable, { Props } from './UsersTable';
|
|
|
|
import { OrgUser } from 'app/types';
|
|
|
|
import { getMockUsers } from './__mocks__/userMocks';
|
2020-04-15 09:49:20 -05:00
|
|
|
import { ConfirmModal } from '@grafana/ui';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
2021-04-22 05:19:41 -05:00
|
|
|
jest.mock('app/core/core', () => ({
|
|
|
|
contextSrv: {
|
|
|
|
hasPermission: () => true,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2018-10-03 02:43:10 -05:00
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
const props: Props = {
|
|
|
|
users: [] as OrgUser[],
|
|
|
|
onRoleChange: jest.fn(),
|
|
|
|
onRemoveUser: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
return shallow(<UsersTable {...props} />);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
|
|
|
it('should render component', () => {
|
|
|
|
const wrapper = setup();
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render users table', () => {
|
|
|
|
const wrapper = setup({
|
|
|
|
users: getMockUsers(5),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2020-04-15 09:49:20 -05:00
|
|
|
|
|
|
|
describe('Remove modal', () => {
|
|
|
|
it('should render correct amount', () => {
|
|
|
|
const wrapper = setup({
|
|
|
|
users: getMockUsers(3),
|
|
|
|
});
|
|
|
|
expect(wrapper.find(ConfirmModal).length).toEqual(4);
|
|
|
|
});
|
|
|
|
});
|