2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http: //www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import { runSaga } from 'redux-saga';
20 import { takeLatest, throttle } from 'redux-saga/effects';
28 } from 'features/catalog/catalogConstants';
29 import catalogApi from '../catalogApi';
30 import { fetchWorkflow, updateWorkflow } from 'features/catalog/catalogActions';
31 import catalogSaga, { fetchWorkflowSaga } from 'features/catalog/catalogSagas';
33 jest.mock('../catalogApi');
35 describe('Catalog Sagas', () => {
36 it('should watch for `fetchWorkflow` action', () => {
37 const gen = catalogSaga();
39 expect(gen.next().value).toEqual(
40 takeLatest(fetchWorkflow, fetchWorkflowSaga)
43 expect(gen.next().value).toEqual(
44 throttle(SEARCH_BUFFER, SEARCH_CHANGED, fetchWorkflowSaga)
46 expect(gen.next().done).toBe(true);
49 it('should get workflows and put `updateWorkflow` action', async () => {
54 const searchNameFilter = undefined;
63 searchNameFilter: 'w',
66 id: 'c5b7ca1a0f7944bfa948b85b32c5f314',
69 versionStates: ['DRAFT'],
73 id: '221336ef3f1645c686bc81899368ac27',
76 versionStates: ['DRAFT'],
81 const dispatched = [];
83 catalogApi.getWorkflows.mockReturnValue(data);
87 dispatch: action => dispatched.push(action)
90 fetchWorkflow(sort, offset)
93 expect(dispatched).toEqual(
94 expect.arrayContaining([updateWorkflow({ sort, ...data })])
97 expect(catalogApi.getWorkflows).toBeCalledWith(