cache search result workflow
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / catalog / __tests__ / catalogReducer-test.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
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
7 *
8 *      http: //www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 'use strict';
18
19 import { NAME, ASC, DESC } from 'features/catalog/catalogConstants';
20 import catalogReducer, { initialState } from 'features/catalog/catalogReducer';
21 import { updateWorkflow } from 'features/catalog/catalogActions';
22
23 describe('Catalog Reducer', () => {
24     const state = {
25         paging: {
26             offset: 1,
27             limit: 1,
28             count: 1,
29             hasMore: false,
30             total: 2
31         },
32         sort: {
33             [NAME]: ASC
34         },
35         items: [
36             {
37                 id: 'c5b7ca1a0f7944bfa948b85b32c5f314',
38                 name: 'Workflow_2',
39                 description: null,
40                 versionStates: ['DRAFT'],
41                 versions: null
42             },
43             {
44                 id: '221336ef3f1645c686bc81899368ac27',
45                 name: 'Workflow_1',
46                 description: null,
47                 versionStates: ['DRAFT'],
48                 versions: null
49             }
50         ]
51     };
52
53     const sort = {
54         [NAME]: DESC
55     };
56
57     const offset = 0;
58
59     const dataPayload = {
60         paging: {
61             offset,
62             limit: 10,
63             count: 2,
64             hasMore: false,
65             total: 2
66         },
67         items: [
68             {
69                 id: 'c5b7ca1a0f7944bfa948b85b32c5f314',
70                 name: 'Workflow_2',
71                 description: null,
72                 versionStates: ['DRAFT'],
73                 versions: null
74             },
75             {
76                 id: '221336ef3f1645c686bc81899368ac27',
77                 name: 'Workflow_1',
78                 description: null,
79                 versionStates: ['DRAFT'],
80                 versions: null
81             }
82         ]
83     };
84
85     it('returns the initial state', () => {
86         expect(catalogReducer(undefined, {})).toEqual(initialState);
87     });
88
89     it('should replace results when page is first', () => {
90         expect(
91             catalogReducer(state, updateWorkflow({ sort, ...dataPayload }))
92         ).toEqual({
93             ...initialState,
94             sort,
95             ...dataPayload
96         });
97     });
98
99     it('should add results when page is not first', () => {
100         expect(
101             catalogReducer(
102                 state,
103                 updateWorkflow({ sort, ...{ ...dataPayload, offset: 2 } })
104             ).items
105         ).toEqual(
106             expect.arrayContaining([...dataPayload.items, ...state.items])
107         );
108     });
109
110 });