17427: Add unit test for openRunProcess()
[arvados-workbench2.git] / src / store / workflow-panel / workflow-panel-actions.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { getNewExtraToken, initAuth } from "./auth-action";
6 import { API_TOKEN_KEY } from "~/services/auth-service/auth-service";
7
8 import 'jest-localstorage-mock';
9 import { ServiceRepository, createServices } from "~/services/services";
10 import { configureStore, RootStore } from "../store";
11 import { createBrowserHistory } from "history";
12 import { Config, mockConfig } from '~/common/config';
13 import { ApiActions } from "~/services/api/api-actions";
14 import { ACCOUNT_LINK_STATUS_KEY } from '~/services/link-account-service/link-account-service';
15 import Axios from "axios";
16 import MockAdapter from "axios-mock-adapter";
17 import { ImportMock } from 'ts-mock-imports';
18 import * as servicesModule from "~/services/services";
19 import { SessionStatus } from "~/models/session";
20 import { openRunProcess } from './workflow-panel-actions';
21 import { runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
22 import { initialize } from 'redux-form';
23 import { RUN_PROCESS_BASIC_FORM } from '~/views/run-process-panel/run-process-basic-form';
24 import { RUN_PROCESS_INPUTS_FORM } from '~/views/run-process-panel/run-process-inputs-form';
25
26 describe('workflow-panel-actions', () => {
27     const axiosInst = Axios.create({ headers: {} });
28     const axiosMock = new MockAdapter(axiosInst);
29
30     let store: RootStore;
31     let services: ServiceRepository;
32     const config: any = {};
33     const actions: ApiActions = {
34         progressFn: (id: string, working: boolean) => { },
35         errorFn: (id: string, message: string) => { }
36     };
37     let importMocks: any[];
38
39     beforeEach(() => {
40         axiosMock.reset();
41         services = createServices(mockConfig({}), actions, axiosInst);
42         store = configureStore(createBrowserHistory(), services, config);
43         localStorage.clear();
44         importMocks = [];
45     });
46
47     afterEach(() => {
48         importMocks.map(m => m.restore());
49     });
50
51     it('opens the run process panel', async () => {
52         const wflist = [{
53             uuid: "zzzzz-7fd4e-0123456789abcde",
54             name: "foo",
55             description: "",
56             definition: "$graph: []"
57         }];
58         axiosMock
59             .onGet("/workflows")
60             .reply(200, {
61                 items: wflist
62             }).onGet("/links")
63             .reply(200, {
64                 items: []
65             });
66
67         const dispatchMock = jest.fn();
68         const dispatchWrapper = (action: any) => {
69             dispatchMock(action);
70             return store.dispatch(action);
71         };
72
73         await openRunProcess("zzzzz-7fd4e-0123456789abcde", "zzzzz-tpzed-0123456789abcde", "testing", { inputparm: "value" })(dispatchWrapper, store.getState, services);
74         expect(dispatchMock).toHaveBeenCalledWith(runProcessPanelActions.SET_WORKFLOWS(wflist));
75         expect(dispatchMock).toHaveBeenCalledWith(runProcessPanelActions.SET_SELECTED_WORKFLOW(wflist[0]));
76         expect(dispatchMock).toHaveBeenCalledWith(runProcessPanelActions.SET_PROCESS_OWNER_UUID("zzzzz-tpzed-0123456789abcde"));
77         expect(dispatchMock).toHaveBeenCalledWith(initialize(RUN_PROCESS_BASIC_FORM, { name: "testing" }));
78         expect(dispatchMock).toHaveBeenCalledWith(initialize(RUN_PROCESS_INPUTS_FORM, { inputparm: "value" }));
79     });
80 });