TeamList.test.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { Props, TeamList } from './TeamList';
  4. import { NavModel, Team } from '../../types';
  5. import { getMockTeam, getMultipleMockTeams } from './__mocks__/teamMocks';
  6. const setup = (propOverrides?: object) => {
  7. const props: Props = {
  8. navModel: {
  9. main: {
  10. text: 'Configuration'
  11. },
  12. node: {
  13. text: 'Team List'
  14. }
  15. } as NavModel,
  16. teams: [] as Team[],
  17. loadTeams: jest.fn(),
  18. deleteTeam: jest.fn(),
  19. setSearchQuery: jest.fn(),
  20. searchQuery: '',
  21. teamsCount: 0,
  22. hasFetched: false,
  23. };
  24. Object.assign(props, propOverrides);
  25. const wrapper = shallow(<TeamList {...props} />);
  26. const instance = wrapper.instance() as TeamList;
  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 teams table', () => {
  38. const { wrapper } = setup({
  39. teams: getMultipleMockTeams(5),
  40. teamsCount: 5,
  41. hasFetched: true,
  42. });
  43. expect(wrapper).toMatchSnapshot();
  44. });
  45. });
  46. describe('Life cycle', () => {
  47. it('should call loadTeams', () => {
  48. const { instance } = setup();
  49. instance.componentDidMount();
  50. expect(instance.props.loadTeams).toHaveBeenCalled();
  51. });
  52. });
  53. describe('Functions', () => {
  54. describe('Delete team', () => {
  55. it('should call delete team', () => {
  56. const { instance } = setup();
  57. instance.deleteTeam(getMockTeam());
  58. expect(instance.props.deleteTeam).toHaveBeenCalledWith(1);
  59. });
  60. });
  61. describe('on search query change', () => {
  62. it('should call setSearchQuery', () => {
  63. const { instance } = setup();
  64. const mockEvent = { target: { value: 'test' } };
  65. instance.onSearchQueryChange(mockEvent);
  66. expect(instance.props.setSearchQuery).toHaveBeenCalledWith('test');
  67. });
  68. });
  69. });