reducers.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  2. import { ApiKeysState } from '../../../types';
  3. import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
  4. import {
  5. apiKeysLoaded,
  6. apiKeysReducer,
  7. includeExpiredToggled,
  8. initialApiKeysState,
  9. isFetching,
  10. setSearchQuery,
  11. } from './reducers';
  12. describe('API Keys reducer', () => {
  13. it('should set keys', () => {
  14. reducerTester<ApiKeysState>()
  15. .givenReducer(apiKeysReducer, { ...initialApiKeysState })
  16. .whenActionIsDispatched(
  17. apiKeysLoaded({ keys: getMultipleMockKeys(4), keysIncludingExpired: getMultipleMockKeys(6) })
  18. )
  19. .thenStateShouldEqual({
  20. ...initialApiKeysState,
  21. keys: getMultipleMockKeys(4),
  22. keysIncludingExpired: getMultipleMockKeys(6),
  23. hasFetched: true,
  24. });
  25. });
  26. it('should set search query', () => {
  27. reducerTester<ApiKeysState>()
  28. .givenReducer(apiKeysReducer, { ...initialApiKeysState })
  29. .whenActionIsDispatched(setSearchQuery('test query'))
  30. .thenStateShouldEqual({
  31. ...initialApiKeysState,
  32. searchQuery: 'test query',
  33. });
  34. });
  35. it('should toggle the includeExpired state', () => {
  36. reducerTester<ApiKeysState>()
  37. .givenReducer(apiKeysReducer, { ...initialApiKeysState })
  38. .whenActionIsDispatched(includeExpiredToggled())
  39. .thenStateShouldEqual({
  40. ...initialApiKeysState,
  41. includeExpired: true,
  42. });
  43. });
  44. it('should set state when fetching', () => {
  45. reducerTester<ApiKeysState>()
  46. .givenReducer(apiKeysReducer, { ...initialApiKeysState })
  47. .whenActionIsDispatched(isFetching())
  48. .thenStateShouldEqual({
  49. ...initialApiKeysState,
  50. hasFetched: false,
  51. });
  52. });
  53. });