UsersListPage.test.tsx 1.4 KB

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