UsersListPage.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { UsersListPage, Props } from './UsersListPage';
  4. import { Invitee, OrgUser } from 'app/types';
  5. import { getMockUser } from './__mocks__/userMocks';
  6. import appEvents from '../../core/app_events';
  7. import { NavModel } from '@grafana/ui';
  8. jest.mock('../../core/app_events', () => ({
  9. emit: jest.fn(),
  10. }));
  11. const setup = (propOverrides?: object) => {
  12. const props: Props = {
  13. navModel: {
  14. main: {
  15. text: 'Configuration',
  16. },
  17. node: {
  18. text: 'Users',
  19. },
  20. } as NavModel,
  21. users: [] as OrgUser[],
  22. invitees: [] as Invitee[],
  23. searchQuery: '',
  24. externalUserMngInfo: '',
  25. loadInvitees: jest.fn(),
  26. loadUsers: jest.fn(),
  27. updateUser: jest.fn(),
  28. removeUser: jest.fn(),
  29. setUsersSearchQuery: jest.fn(),
  30. hasFetched: false,
  31. };
  32. Object.assign(props, propOverrides);
  33. const wrapper = shallow(<UsersListPage {...props} />);
  34. const instance = wrapper.instance() as UsersListPage;
  35. return {
  36. wrapper,
  37. instance,
  38. };
  39. };
  40. describe('Render', () => {
  41. it('should render component', () => {
  42. const { wrapper } = setup();
  43. expect(wrapper).toMatchSnapshot();
  44. });
  45. it('should render List page', () => {
  46. const { wrapper } = setup({
  47. hasFetched: true,
  48. });
  49. expect(wrapper).toMatchSnapshot();
  50. });
  51. });
  52. describe('Functions', () => {
  53. it('should emit show remove user modal', () => {
  54. const { instance } = setup();
  55. const mockUser = getMockUser();
  56. instance.onRemoveUser(mockUser);
  57. expect(appEvents.emit).toHaveBeenCalled();
  58. });
  59. });