UsersTable.test.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { ConfirmModal } from '@grafana/ui';
  4. import { OrgUser } from 'app/types';
  5. import UsersTable, { Props } from './UsersTable';
  6. import { getMockUsers } from './__mocks__/userMocks';
  7. jest.mock('app/core/core', () => ({
  8. contextSrv: {
  9. hasPermission: () => true,
  10. hasPermissionInMetadata: () => true,
  11. licensedAccessControlEnabled: () => false,
  12. },
  13. }));
  14. const setup = (propOverrides?: object) => {
  15. const props: Props = {
  16. users: [] as OrgUser[],
  17. onRoleChange: jest.fn(),
  18. onRemoveUser: jest.fn(),
  19. };
  20. Object.assign(props, propOverrides);
  21. return shallow(<UsersTable {...props} />);
  22. };
  23. describe('Render', () => {
  24. it('should render component', () => {
  25. const wrapper = setup();
  26. expect(wrapper).toMatchSnapshot();
  27. });
  28. it('should render users table', () => {
  29. const wrapper = setup({
  30. users: getMockUsers(5),
  31. });
  32. expect(wrapper).toMatchSnapshot();
  33. });
  34. });
  35. describe('Remove modal', () => {
  36. it('should render correct amount', () => {
  37. const wrapper = setup({
  38. users: getMockUsers(3),
  39. });
  40. expect(wrapper.find(ConfirmModal).length).toEqual(0);
  41. });
  42. });