Merge remote-tracking branch 'origin/main' into 19836-new-tooltip-impl
[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 { API_TOKEN_KEY } from "services/auth-service/auth-service";
6
7 import 'jest-localstorage-mock';
8 import { ServiceRepository, createServices } from "services/services";
9 import { configureStore, RootStore } from "../store";
10 import { createBrowserHistory } from "history";
11 import { Config, mockConfig } from 'common/config';
12 import { ApiActions } from "services/api/api-actions";
13 import { ACCOUNT_LINK_STATUS_KEY } from 'services/link-account-service/link-account-service';
14 import Axios from "axios";
15 import MockAdapter from "axios-mock-adapter";
16 import { ImportMock } from 'ts-mock-imports';
17 import * as servicesModule from "services/services";
18 import { SessionStatus } from "models/session";
19 import { openRunProcess } from './workflow-panel-actions';
20 import { runProcessPanelActions } from 'store/run-process-panel/run-process-panel-actions';
21 import { initialize } from 'redux-form';
22 import { RUN_PROCESS_BASIC_FORM } from 'views/run-process-panel/run-process-basic-form';
23 import { RUN_PROCESS_INPUTS_FORM } from 'views/run-process-panel/run-process-inputs-form';
24 import { ResourceKind } from 'models/resource';
25 import { WorkflowResource } from 'models/workflow';
26
27 describe('workflow-panel-actions', () => {
28     const axiosInst = Axios.create({ headers: {} });
29     const axiosMock = new MockAdapter(axiosInst);
30
31     let store: RootStore;
32     let services: ServiceRepository;
33     const config: any = {};
34     const actions: ApiActions = {
35         progressFn: (id: string, working: boolean) => { },
36         errorFn: (id: string, message: string) => { }
37     };
38     let importMocks: any[];
39
40     beforeEach(() => {
41         axiosMock.reset();
42         services = createServices(mockConfig({}), actions, axiosInst);
43         store = configureStore(createBrowserHistory(), services, config);
44         localStorage.clear();
45         importMocks = [];
46     });
47
48     afterEach(() => {
49         importMocks.map(m => m.restore());
50     });
51
52     it('opens the run process panel', async () => {
53         const wflist: WorkflowResource[] = [{
54             uuid: "zzzzz-7fd4e-0123456789abcde",
55             name: "foo",
56             description: "",
57             definition: "$graph: []",
58             kind: ResourceKind.WORKFLOW,
59             ownerUuid: "",
60             createdAt: "",
61             modifiedByClientUuid: "",
62             modifiedByUserUuid: "",
63             modifiedAt: "",
64             href: "",
65             etag: ""
66         }];
67         axiosMock
68             .onGet("/workflows")
69             .reply(200, {
70                 items: wflist
71             }).onGet("/links")
72             .reply(200, {
73                 items: []
74             });
75
76         const dispatchMock = jest.fn();
77         const dispatchWrapper = (action: any) => {
78             dispatchMock(action);
79             return store.dispatch(action);
80         };
81
82         await openRunProcess("zzzzz-7fd4e-0123456789abcde", "zzzzz-tpzed-0123456789abcde", "testing", { inputparm: "value" })(dispatchWrapper, store.getState, services);
83         expect(dispatchMock).toHaveBeenCalledWith(runProcessPanelActions.SET_WORKFLOWS(wflist));
84         expect(dispatchMock).toHaveBeenCalledWith(runProcessPanelActions.SET_SELECTED_WORKFLOW(wflist[0]));
85         expect(dispatchMock).toHaveBeenCalledWith(initialize(RUN_PROCESS_BASIC_FORM, { name: "testing" }));
86         expect(dispatchMock).toHaveBeenCalledWith(initialize(RUN_PROCESS_INPUTS_FORM, { inputparm: "value" }));
87     });
88 });