reducers.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  2. import { TeamsState, TeamState } from '../../../types';
  3. import { getMockTeam, getMockTeamGroups, getMockTeamMember } from '../__mocks__/teamMocks';
  4. import {
  5. initialTeamsState,
  6. initialTeamState,
  7. setSearchMemberQuery,
  8. setSearchQuery,
  9. teamGroupsLoaded,
  10. teamLoaded,
  11. teamMembersLoaded,
  12. teamReducer,
  13. teamsLoaded,
  14. teamsReducer,
  15. } from './reducers';
  16. describe('teams reducer', () => {
  17. describe('when teamsLoaded is dispatched', () => {
  18. it('then state should be correct', () => {
  19. reducerTester<TeamsState>()
  20. .givenReducer(teamsReducer, { ...initialTeamsState })
  21. .whenActionIsDispatched(teamsLoaded([getMockTeam()]))
  22. .thenStateShouldEqual({
  23. ...initialTeamsState,
  24. hasFetched: true,
  25. teams: [getMockTeam()],
  26. });
  27. });
  28. });
  29. describe('when setSearchQueryAction is dispatched', () => {
  30. it('then state should be correct', () => {
  31. reducerTester<TeamsState>()
  32. .givenReducer(teamsReducer, { ...initialTeamsState })
  33. .whenActionIsDispatched(setSearchQuery('test'))
  34. .thenStateShouldEqual({
  35. ...initialTeamsState,
  36. searchQuery: 'test',
  37. });
  38. });
  39. });
  40. });
  41. describe('team reducer', () => {
  42. describe('when loadTeamsAction is dispatched', () => {
  43. it('then state should be correct', () => {
  44. reducerTester<TeamState>()
  45. .givenReducer(teamReducer, { ...initialTeamState })
  46. .whenActionIsDispatched(teamLoaded(getMockTeam()))
  47. .thenStateShouldEqual({
  48. ...initialTeamState,
  49. team: getMockTeam(),
  50. });
  51. });
  52. });
  53. describe('when loadTeamMembersAction is dispatched', () => {
  54. it('then state should be correct', () => {
  55. reducerTester<TeamState>()
  56. .givenReducer(teamReducer, { ...initialTeamState })
  57. .whenActionIsDispatched(teamMembersLoaded([getMockTeamMember()]))
  58. .thenStateShouldEqual({
  59. ...initialTeamState,
  60. members: [getMockTeamMember()],
  61. });
  62. });
  63. });
  64. describe('when setSearchMemberQueryAction is dispatched', () => {
  65. it('then state should be correct', () => {
  66. reducerTester<TeamState>()
  67. .givenReducer(teamReducer, { ...initialTeamState })
  68. .whenActionIsDispatched(setSearchMemberQuery('member'))
  69. .thenStateShouldEqual({
  70. ...initialTeamState,
  71. searchMemberQuery: 'member',
  72. });
  73. });
  74. });
  75. describe('when loadTeamGroupsAction is dispatched', () => {
  76. it('then state should be correct', () => {
  77. reducerTester<TeamState>()
  78. .givenReducer(teamReducer, { ...initialTeamState })
  79. .whenActionIsDispatched(teamGroupsLoaded(getMockTeamGroups(1)))
  80. .thenStateShouldEqual({
  81. ...initialTeamState,
  82. groups: getMockTeamGroups(1),
  83. });
  84. });
  85. });
  86. });