TeamMembers.test.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { mockToolkitActionCreator } from 'test/core/redux/mocks';
  4. import { User } from 'app/core/services/context_srv';
  5. import { OrgRole, TeamMember } from '../../types';
  6. import { Props, State, TeamMembers } from './TeamMembers';
  7. import { getMockTeamMembers } from './__mocks__/teamMocks';
  8. import { setSearchMemberQuery } from './state/reducers';
  9. const signedInUserId = 1;
  10. const setup = (propOverrides?: object) => {
  11. const props: Props = {
  12. members: [] as TeamMember[],
  13. searchMemberQuery: '',
  14. setSearchMemberQuery: mockToolkitActionCreator(setSearchMemberQuery),
  15. addTeamMember: jest.fn(),
  16. syncEnabled: false,
  17. editorsCanAdmin: false,
  18. signedInUser: {
  19. id: signedInUserId,
  20. isGrafanaAdmin: false,
  21. orgRole: OrgRole.Viewer,
  22. } as User,
  23. };
  24. Object.assign(props, propOverrides);
  25. const wrapper = shallow(<TeamMembers {...props} />);
  26. const instance = wrapper.instance() as TeamMembers;
  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 team members', () => {
  38. const { wrapper } = setup({ members: getMockTeamMembers(5, 5) });
  39. expect(wrapper).toMatchSnapshot();
  40. });
  41. });
  42. describe('Functions', () => {
  43. describe('on search member query change', () => {
  44. it('it should call setSearchMemberQuery', () => {
  45. const { instance } = setup({});
  46. instance.onSearchQueryChange('member');
  47. expect(instance.props.setSearchMemberQuery).toHaveBeenCalledWith('member');
  48. });
  49. });
  50. describe('on add user to team', () => {
  51. const { wrapper, instance } = setup({});
  52. const state = wrapper.state() as State;
  53. state.newTeamMember = {
  54. id: 1,
  55. label: '',
  56. avatarUrl: '',
  57. login: '',
  58. name: '',
  59. email: '',
  60. };
  61. instance.onAddUserToTeam();
  62. expect(instance.props.addTeamMember).toHaveBeenCalledWith(1);
  63. });
  64. });