17306: Added browser tests, filtering writable entities
[arvados.git] / src / store / run-process-panel / run-process-panel-actions.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { runProcess } from "./run-process-panel-actions";
6
7 jest.mock("../navigation/navigation-action", () => ({
8     navigateTo: (link: any) => link,
9 }));
10
11 jest.mock("~/models/process", () => ({
12     createWorkflowMounts: jest.fn(),
13 }));
14
15 jest.mock("redux-form", () => ({
16     reduxForm: () => (c: any) => c,
17     getFormValues: (name: string) => () => {
18         switch (name) {
19             case "runProcessBasicForm":
20                 return {
21                     name: "basicFormTestName",
22                     description: "basicFormTestDescription",
23                 };
24             case "runProcessInputsForm":
25                 return {};
26             default:
27                 return null;
28         }
29     },
30 }));
31
32 describe("run-process-panel-actions", () => {
33     describe("runProcess", () => {
34         const newProcessUUID = 'newProcessUUID';
35         let dispatch: any, getState: any, services: any;
36
37         beforeEach(() => {
38             dispatch = jest.fn();
39             services = {
40                 containerRequestService: {
41                     create: jest.fn().mockImplementation(async () => ({
42                         uuid: newProcessUUID,
43                     })),
44                 },
45             };
46         });
47
48         it("should return when userUuid is null", async () => {
49             // given
50             getState = () => ({
51                 auth: {},
52             });
53
54             // when
55             await runProcess(dispatch, getState, services);
56
57             // then
58             expect(dispatch).not.toHaveBeenCalled();
59         });
60
61         it("should run workflow with project-uuid", async () => {
62             // given
63             getState = () => ({
64                 auth: {
65                     user: {
66                         email: "test@gmail.com",
67                         firstName: "TestFirstName",
68                         lastName: "TestLastName",
69                         uuid: "ce8i5-tpzed-yid70bw31f51234",
70                         ownerUuid: "ce8i5-tpzed-000000000000000",
71                         isAdmin: false,
72                         isActive: true,
73                         username: "testfirstname",
74                         prefs: {
75                             profile: {},
76                         },
77                     },
78                 },
79                 runProcessPanel: {
80                     processPathname: "/projects/ce8i5-tpzed-yid70bw31f51234",
81                     processOwnerUuid: "ce8i5-tpzed-yid70bw31f51234",
82                     selectedWorkflow: {
83                         href: "/workflows/ce8i5-7fd4e-2tlnerdkxnl4fjt",
84                         kind: "arvados#workflow",
85                         etag: "8gh5xlhlgo61yqscyl1spw8tc",
86                         uuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
87                         ownerUuid: "ce8i5-tpzed-o4njwilpp4ov321",
88                         createdAt: "2020-07-15T19:40:50.296041000Z",
89                         modifiedByClientUuid: "ce8i5-ozdt8-libnr89sc5nq111",
90                         modifiedByUserUuid: "ce8i5-tpzed-o4njwilpp4ov321",
91                         modifiedAt: "2020-07-15T19:40:50.296376000Z",
92                         name: "revsort.cwl",
93                         description:
94                             "Reverse the lines in a document, then sort those lines.",
95                         definition:
96                             '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "hints":[{"class":"http://arvados.org/cwl#WorkflowRunnerResources","acrContainerImage":"arvados/jobs:2.0.4", "ramMin": 16000}], "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
97                     },
98                 },
99             });
100
101             // when
102             await runProcess(dispatch, getState, services);
103
104             // then
105             expect(services.containerRequestService.create).toHaveBeenCalledWith({
106                 command: [
107                     "arvados-cwl-runner",
108                     "--api=containers",
109                     "--local",
110                     "--project-uuid=ce8i5-tpzed-yid70bw31f51234",
111                     "/var/lib/cwl/workflow.json#main",
112                     "/var/lib/cwl/cwl.input.json",
113                 ],
114                 containerImage: "arvados/jobs:2.0.4",
115                 cwd: "/var/spool/cwl",
116                 description: "basicFormTestDescription",
117                 mounts: undefined,
118                 name: "basicFormTestName",
119                 outputName: undefined,
120                 outputPath: "/var/spool/cwl",
121                 ownerUuid: "ce8i5-tpzed-yid70bw31f51234",
122                 priority: 1,
123                 properties: {
124                     workflowName: "revsort.cwl",
125                     workflowUuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
126                 },
127                 runtimeConstraints: {
128                     API: true,
129                     ram: 16256 * (1024 * 1024),
130                     vcpus: 1,
131                 },
132                 schedulingParameters: { max_run_time: undefined },
133                 state: "Committed",
134             });
135
136             // and
137             expect(dispatch).toHaveBeenCalledWith(newProcessUUID);
138         });
139     });
140 });