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