TeamGroupSync.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { Props, TeamGroupSync } from './TeamGroupSync';
  4. import { TeamGroup } from '../../types';
  5. import { getMockTeamGroups } from './__mocks__/teamMocks';
  6. const setup = (propOverrides?: object) => {
  7. const props: Props = {
  8. groups: [] as TeamGroup[],
  9. loadTeamGroups: jest.fn(),
  10. addTeamGroup: jest.fn(),
  11. removeTeamGroup: jest.fn(),
  12. };
  13. Object.assign(props, propOverrides);
  14. const wrapper = shallow(<TeamGroupSync {...props} />);
  15. const instance = wrapper.instance() as TeamGroupSync;
  16. return {
  17. wrapper,
  18. instance,
  19. };
  20. };
  21. describe('Render', () => {
  22. it('should render component', () => {
  23. const { wrapper } = setup();
  24. expect(wrapper).toMatchSnapshot();
  25. });
  26. it('should render groups table', () => {
  27. const { wrapper } = setup({
  28. groups: getMockTeamGroups(3),
  29. });
  30. expect(wrapper).toMatchSnapshot();
  31. });
  32. });
  33. describe('Functions', () => {
  34. it('should call add group', () => {
  35. const { instance } = setup();
  36. instance.setState({ newGroupId: 'some/group' });
  37. const mockEvent = { preventDefault: jest.fn() };
  38. instance.onAddGroup(mockEvent);
  39. expect(instance.props.addTeamGroup).toHaveBeenCalledWith('some/group');
  40. });
  41. it('should call remove group', () => {
  42. const { instance } = setup();
  43. const mockGroup: TeamGroup = { teamId: 1, groupId: 'some/group' };
  44. instance.onRemoveGroup(mockGroup);
  45. expect(instance.props.removeTeamGroup).toHaveBeenCalledWith('some/group');
  46. });
  47. });