Merge branch '20497-updating-wgs-tutorial'
[arvados.git] / apps / workbench / test / integration / container_requests_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6
7 class ContainerRequestsTest < ActionDispatch::IntegrationTest
8   setup do
9     need_javascript
10   end
11
12   [
13     ['ex_string', 'abc'],
14     ['ex_string_opt', 'abc'],
15     ['ex_int', 12],
16     ['ex_int_opt', 12],
17     ['ex_long', 12],
18     ['ex_double', '12.34', 12.34],
19     ['ex_float', '12.34', 12.34],
20   ].each do |input_id, input_value, expected_value|
21     test "set input #{input_id} with #{input_value}" do
22       request_uuid = api_fixture("container_requests", "uncommitted", "uuid")
23       visit page_with_token("active", "/container_requests/#{request_uuid}")
24       selector = ".editable[data-name='[mounts][/var/lib/cwl/cwl.input.json][content][#{input_id}]']"
25       find(selector).click
26       find(".editable-input input").set(input_value)
27       find("#editable-submit").click
28       assert_no_selector(".editable-popup")
29       assert_selector(selector, text: expected_value || input_value)
30     end
31   end
32
33   test "select value for boolean input" do
34     request_uuid = api_fixture("container_requests", "uncommitted", "uuid")
35     visit page_with_token("active", "/container_requests/#{request_uuid}")
36     selector = ".editable[data-name='[mounts][/var/lib/cwl/cwl.input.json][content][ex_boolean]']"
37     find(selector).click
38     within(".editable-input") do
39       select "true"
40     end
41     find("#editable-submit").click
42     assert_no_selector(".editable-popup")
43     assert_selector(selector, text: "true")
44   end
45
46   test "select value for enum typed input" do
47     request_uuid = api_fixture("container_requests", "uncommitted", "uuid")
48     visit page_with_token("active", "/container_requests/#{request_uuid}")
49     selector = ".editable[data-name='[mounts][/var/lib/cwl/cwl.input.json][content][ex_enum]']"
50     find(selector).click
51     within(".editable-input") do
52       select "b"    # second value
53     end
54     find("#editable-submit").click
55     assert_no_selector(".editable-popup")
56     assert_selector(selector, text: "b")
57   end
58
59   [
60     ['directory_type'],
61     ['file_type'],
62   ].each do |type|
63     test "select value for #{type} input" do
64       request_uuid = api_fixture("container_requests", "uncommitted-with-directory-input", "uuid")
65       visit page_with_token("active", "/container_requests/#{request_uuid}")
66       assert_text 'Provide a value for the following parameter'
67       click_link 'Choose'
68       within('.modal-dialog') do
69         wait_for_ajax
70         collection = api_fixture('collections', 'collection_with_one_property', 'uuid')
71         find("div[data-object-uuid=#{collection}]").click
72         if type == 'ex_file'
73           wait_for_ajax
74           find('.preview-selectable', text: 'bar').click
75         end
76         find('button', text: 'OK').click
77       end
78       page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
79       assert_text 'This workflow does not need any further inputs'
80       click_link "Run"
81       wait_for_ajax
82       assert_text 'This container is queued'
83     end
84   end
85
86   test "Run button enabled once all required inputs are provided" do
87     request_uuid = api_fixture("container_requests", "uncommitted-with-required-and-optional-inputs", "uuid")
88     visit page_with_token("active", "/container_requests/#{request_uuid}")
89     assert_text 'Provide a value for the following parameter'
90
91     page.assert_selector 'a.disabled,button.disabled', text: 'Run'
92
93     selector = ".editable[data-name='[mounts][/var/lib/cwl/cwl.input.json][content][int_required]']"
94     find(selector).click
95     find(".editable-input input").set(2016)
96     find("#editable-submit").click
97
98     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
99     click_link "Run"
100     wait_for_ajax
101     assert_text 'This container is queued'
102   end
103
104   test "Run button enabled when workflow is empty and no inputs are needed" do
105     visit page_with_token("active")
106
107     find('.btn', text: 'Run a process').click
108     within('.modal-dialog') do
109       find('.selectable', text: 'Valid workflow with no definition yaml').click
110       find('.btn', text: 'Next: choose inputs').click
111     end
112
113     assert_text 'This workflow does not need any further inputs'
114     page.assert_selector 'a', text: 'Run'
115   end
116
117   test "Provenance graph shown on committed container requests" do
118     cr = api_fixture('container_requests', 'completed')
119     visit page_with_token("active", "/container_requests/#{cr['uuid']}")
120     assert page.has_text? 'Provenance'
121     click_link 'Provenance'
122     wait_for_ajax
123     # Check for provenance graph existance
124     page.assert_selector '#provenance_svg'
125     page.assert_selector 'ellipse+text', text: cr['name'], visible: false
126     page.assert_selector 'g.node>title', text: cr['uuid'], visible: false
127   end
128
129   test "index page" do
130     visit page_with_token("active", "/container_requests")
131
132     within(".arv-recent-container-requests") do
133       page.execute_script "window.scrollBy(0,999000)"
134       wait_for_ajax
135     end
136
137     running_owner_active = api_fixture("container_requests", "requester_for_running")
138     anon_accessible_cr = api_fixture("container_requests", "running_anonymous_accessible")
139
140     # both of these CRs should be accessible to the user
141     assert_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
142     assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
143
144     # user can delete the "running" container_request
145     within(".cr-#{running_owner_active['uuid']}") do
146       assert_not_nil first('.glyphicon-trash')
147     end
148
149     # user can not delete the anonymously accessible container_request
150     within(".cr-#{anon_accessible_cr['uuid']}") do
151       assert_nil first('.glyphicon-trash')
152     end
153
154     # verify the search box in the page
155     find('.recent-container-requests-filterable-control').set("anonymous")
156     sleep 0.350 # Wait for 250ms debounce timer (see filterable.js)
157     wait_for_ajax
158     assert_no_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
159     assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
160   end
161 end