reducers.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { itemReducer, makeExploreItemState } from './reducers';
  2. import { ExploreId, ExploreItemState } from 'app/types/explore';
  3. import { reducerTester } from 'test/core/redux/reducerTester';
  4. import { scanStartAction, scanStopAction } from './actionTypes';
  5. import { Reducer } from 'redux';
  6. import { ActionOf } from 'app/core/redux/actionCreatorFactory';
  7. describe('Explore item reducer', () => {
  8. describe('scanning', () => {
  9. test('should start scanning', () => {
  10. const scanner = jest.fn();
  11. const initalState = {
  12. ...makeExploreItemState(),
  13. scanning: false,
  14. scanner: undefined,
  15. };
  16. reducerTester()
  17. .givenReducer(itemReducer as Reducer<ExploreItemState, ActionOf<any>>, initalState)
  18. .whenActionIsDispatched(scanStartAction({ exploreId: ExploreId.left, scanner }))
  19. .thenStateShouldEqual({
  20. ...makeExploreItemState(),
  21. scanning: true,
  22. scanner,
  23. });
  24. });
  25. test('should stop scanning', () => {
  26. const scanner = jest.fn();
  27. const initalState = {
  28. ...makeExploreItemState(),
  29. scanning: true,
  30. scanner,
  31. scanRange: {},
  32. };
  33. reducerTester()
  34. .givenReducer(itemReducer as Reducer<ExploreItemState, ActionOf<any>>, initalState)
  35. .whenActionIsDispatched(scanStopAction({ exploreId: ExploreId.left }))
  36. .thenStateShouldEqual({
  37. ...makeExploreItemState(),
  38. scanning: false,
  39. scanner: undefined,
  40. scanRange: undefined,
  41. });
  42. });
  43. });
  44. });