Merge branch '22198-remove-href-field'
[arvados.git] / services / workbench2 / src / store / workflow-panel / workflow-panel-actions.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { isEqual } from "lodash";
6 import { createServices } from "services/services";
7 import { configureStore } from "../store";
8 import { createBrowserHistory } from "history";
9 import { mockConfig } from 'common/config';
10 import Axios from "axios";
11 import MockAdapter from "axios-mock-adapter";
12 import { openRunProcess } from './workflow-panel-actions';
13 import { runProcessPanelActions } from 'store/run-process-panel/run-process-panel-actions';
14 import { initialize } from 'redux-form';
15 import { RUN_PROCESS_INPUTS_FORM, RUN_PROCESS_BASIC_FORM } from 'store/run-process-panel/run-process-panel-actions';
16 import { ResourceKind } from 'models/resource';
17
18 describe('workflow-panel-actions', () => {
19     const axiosInst = Axios.create({ headers: {} });
20     const axiosMock = new MockAdapter(axiosInst);
21
22     let store;
23     let services;
24     const config = {};
25     const actions = {
26         progressFn: (id, working) => { },
27         errorFn: (id, message) => { }
28     };
29     let importMocks;
30
31     beforeEach(() => {
32         axiosMock.reset();
33         services = createServices(mockConfig({}), actions, axiosInst);
34         store = configureStore(createBrowserHistory(), services, config);
35         localStorage.clear();
36         importMocks = [];
37     });
38
39     afterEach(() => {
40         importMocks.map(m => m.restore());
41     });
42
43     it('opens the run process panel', async () => {
44         const wflist = [{
45             uuid: "zzzzz-7fd4e-0123456789abcde",
46             name: "foo",
47             description: "",
48             definition: "$graph: []",
49             kind: ResourceKind.WORKFLOW,
50             ownerUuid: "",
51             createdAt: "",
52             modifiedByUserUuid: "",
53             modifiedAt: "",
54             etag: ""
55         }];
56         axiosMock
57             .onGet("/workflows")
58             .reply(200, {
59                 items: wflist
60             }).onGet("/links")
61             .reply(200, {
62                 items: []
63             });
64
65         const dispatchMock = cy.spy().as('dispatchMock');
66         const dispatchWrapper = (action ) => {
67             dispatchMock(action);
68             return store.dispatch(action);
69         };
70
71         const expectedBasicArgs = {
72             type: "@@redux-form/INITIALIZE",
73             meta: {
74               form: RUN_PROCESS_BASIC_FORM,
75               keepDirty: undefined,
76             },
77             payload: {
78               name: "testing",
79               owner: undefined,
80             }
81           }
82
83         await openRunProcess("zzzzz-7fd4e-0123456789abcde", "zzzzz-tpzed-0123456789abcde", "testing", { inputparm: "value" })(dispatchWrapper, store.getState, services);
84         cy.get('@dispatchMock').then((dispatchMock) => {
85             expect(dispatchMock).to.be.calledWith(runProcessPanelActions.SET_WORKFLOWS(wflist));
86             expect(dispatchMock).to.be.calledWith(runProcessPanelActions.SET_SELECTED_WORKFLOW(wflist[0]));
87             expect(arrayDeeplyIncludesObject(dispatchMock.args, expectedBasicArgs)).to.be.true;
88             expect(dispatchMock).to.be.calledWith(initialize(RUN_PROCESS_INPUTS_FORM, { inputparm: "value" }));
89         });
90     });
91 });
92
93 const arrayDeeplyIncludesObject = (array, object) => {
94     return array.some((item) => {
95         if (isEqual(item, object)) {
96             return true;
97         }
98         if (typeof item === 'object') {
99             return arrayDeeplyIncludesObject(Object.values(item), object);
100         }
101         return false;
102     });
103 };