UsersListPage.test.tsx 1.6 KB

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