reducers.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Action, ActionTypes } from './actionTypes';
  2. import { itemReducer, makeExploreItemState } from './reducers';
  3. import { ExploreId } from 'app/types/explore';
  4. describe('Explore item reducer', () => {
  5. describe('scanning', () => {
  6. test('should start scanning', () => {
  7. let state = makeExploreItemState();
  8. const action: Action = {
  9. type: ActionTypes.ScanStart,
  10. payload: {
  11. exploreId: ExploreId.left,
  12. scanner: jest.fn(),
  13. },
  14. };
  15. state = itemReducer(state, action);
  16. expect(state.scanning).toBeTruthy();
  17. expect(state.scanner).toBe(action.payload.scanner);
  18. });
  19. test('should stop scanning', () => {
  20. let state = makeExploreItemState();
  21. const start: Action = {
  22. type: ActionTypes.ScanStart,
  23. payload: {
  24. exploreId: ExploreId.left,
  25. scanner: jest.fn(),
  26. },
  27. };
  28. state = itemReducer(state, start);
  29. expect(state.scanning).toBeTruthy();
  30. const action: Action = {
  31. type: ActionTypes.ScanStop,
  32. payload: {
  33. exploreId: ExploreId.left,
  34. },
  35. };
  36. state = itemReducer(state, action);
  37. expect(state.scanning).toBeFalsy();
  38. expect(state.scanner).toBeUndefined();
  39. });
  40. });
  41. });