|
| 1 | +import { testSaga } from "redux-saga-test-plan" |
| 2 | +import WorkspaceActions from "src/commons/workspace/WorkspaceActions" |
| 3 | + |
| 4 | +import { combineSagaHandlers } from "../utils" |
| 5 | + |
| 6 | +// Would have used spyOn, but for some reason that doesn't work properly |
| 7 | +jest.mock('src/commons/sagas/SafeEffects', () => ({ |
| 8 | + ...jest.requireActual('src/commons/sagas/SafeEffects'), |
| 9 | + // Mock wrap saga to just be a passthrough so that the identity |
| 10 | + // checking that testSaga uses will pass |
| 11 | + wrapSaga: (x: any) => x |
| 12 | +})) |
| 13 | + |
| 14 | +test('test combineSagaHandlers', () => { |
| 15 | + const mockTakeEveryHandler = jest.fn() |
| 16 | + const mockTakeLatestHandler = jest.fn() |
| 17 | + const mockTakeLeadingHandler = jest.fn() |
| 18 | + |
| 19 | + const saga = combineSagaHandlers({ |
| 20 | + [WorkspaceActions.toggleUsingUpload.type]: mockTakeEveryHandler, |
| 21 | + [WorkspaceActions.toggleFolderMode.type]: { |
| 22 | + takeEvery: mockTakeEveryHandler |
| 23 | + }, |
| 24 | + [WorkspaceActions.toggleUsingCse.type]: { |
| 25 | + takeLatest: mockTakeLatestHandler |
| 26 | + }, |
| 27 | + [WorkspaceActions.toggleUsingSubst.type]: { |
| 28 | + takeLeading: mockTakeLeadingHandler |
| 29 | + } |
| 30 | + }) |
| 31 | + |
| 32 | + testSaga(saga) |
| 33 | + .next() |
| 34 | + .takeEvery(WorkspaceActions.toggleUsingUpload.type, mockTakeEveryHandler) |
| 35 | + .next() |
| 36 | + .takeEvery(WorkspaceActions.toggleFolderMode.type, mockTakeEveryHandler) |
| 37 | + .next() |
| 38 | + .takeLatest(WorkspaceActions.toggleUsingCse.type, mockTakeLatestHandler) |
| 39 | + .next() |
| 40 | + .takeLeading(WorkspaceActions.toggleUsingSubst.type, mockTakeLeadingHandler) |
| 41 | + .next() |
| 42 | + .isDone() |
| 43 | +}) |
0 commit comments