reducers.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  2. import { OrganizationState, OrgRole } from '../../../types';
  3. import {
  4. initialState,
  5. organizationLoaded,
  6. organizationReducer,
  7. userOrganizationsLoaded,
  8. setOrganizationName,
  9. } from './reducers';
  10. describe('organizationReducer', () => {
  11. describe('when organizationLoaded is dispatched', () => {
  12. it('then state should be correct', () => {
  13. reducerTester<OrganizationState>()
  14. .givenReducer(organizationReducer, { ...initialState })
  15. .whenActionIsDispatched(organizationLoaded({ id: 1, name: 'An org' }))
  16. .thenStateShouldEqual({
  17. organization: { id: 1, name: 'An org' },
  18. userOrgs: [],
  19. });
  20. });
  21. });
  22. describe('when setOrganizationName is dispatched', () => {
  23. it('then state should be correct', () => {
  24. reducerTester<OrganizationState>()
  25. .givenReducer(organizationReducer, { ...initialState, organization: { id: 1, name: 'An org' } })
  26. .whenActionIsDispatched(setOrganizationName('New Name'))
  27. .thenStateShouldEqual({
  28. organization: { id: 1, name: 'New Name' },
  29. userOrgs: [],
  30. });
  31. });
  32. });
  33. describe('when userOrganizationsLoaded is dispatched', () => {
  34. it('then state should be correct', () => {
  35. reducerTester<OrganizationState>()
  36. .givenReducer(organizationReducer, {
  37. ...initialState,
  38. organization: { id: 1, name: 'An org' },
  39. userOrgs: [],
  40. })
  41. .whenActionIsDispatched(userOrganizationsLoaded([{ orgId: 1, name: 'New org', role: OrgRole.Editor }]))
  42. .thenStateShouldEqual({
  43. organization: { id: 1, name: 'An org' },
  44. userOrgs: [{ orgId: 1, name: 'New org', role: OrgRole.Editor }],
  45. });
  46. });
  47. });
  48. });