Merge branch 'master' into 9998-no-count-items-available
[arvados.git] / apps / workbench / test / integration / work_units_test.rb
1 require 'helpers/fake_websocket_helper'
2 require 'integration_helper'
3
4 class WorkUnitsTest < ActionDispatch::IntegrationTest
5   include FakeWebsocketHelper
6
7   setup do
8     need_javascript
9   end
10
11   test "scroll all_processes page" do
12       expected_min, expected_max, expected, not_expected = [
13         25, 100,
14         ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk3',
15          '/pipeline_instances/zzzzz-d1hrv-jobspeccomponts',
16          '/jobs/zzzzz-8i9sb-grx15v5mjnsyxk7',
17          '/jobs/zzzzz-8i9sb-n7omg50bvt0m1nf',
18          '/container_requests/zzzzz-xvhdp-cr4completedcr2',
19          '/container_requests/zzzzz-xvhdp-cr4requestercn2'],
20         ['/pipeline_instances/zzzzz-d1hrv-scarxiyajtshq3l',
21          '/container_requests/zzzzz-xvhdp-oneof60crs00001']
22       ]
23
24       visit page_with_token('active', "/all_processes")
25
26       page_scrolls = expected_max/20 + 2
27       within('.arv-recent-all-processes') do
28         (0..page_scrolls).each do |i|
29           page.driver.scroll_to 0, 999000
30           begin
31             wait_for_ajax
32           rescue
33           end
34         end
35       end
36
37       # Verify that expected number of processes are found
38       found_items = page.all('tr[data-object-uuid]')
39       found_count = found_items.count
40       if expected_min == expected_max
41         assert_equal(true, found_count == expected_min,
42           "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
43         assert page.has_no_text? 'request failed'
44       else
45         assert_equal(true, found_count>=expected_min,
46           "Found too few items. Expected at least #{expected_min} and found #{found_count}")
47         assert_equal(true, found_count<=expected_max,
48           "Found too many items. Expected at most #{expected_max} and found #{found_count}")
49       end
50
51       # verify that all expected uuid links are found
52       expected.each do |link|
53         assert_selector "a[href=\"#{link}\"]"
54       end
55
56       # verify that none of the not_expected uuid links are found
57       not_expected.each do |link|
58         assert_no_selector "a[href=\"#{link}\"]"
59       end
60   end
61
62   [
63     ['jobs', 'running_job_with_components', true],
64     ['pipeline_instances', 'components_is_jobspec', false],
65     ['containers', 'running', false],
66     ['container_requests', 'running', true],
67   ].each do |type, fixture, cancelable|
68     test "cancel button for #{type}/#{fixture}" do
69       if cancelable
70         need_selenium 'to cancel'
71       end
72
73       obj = api_fixture(type)[fixture]
74       visit page_with_token "active", "/#{type}/#{obj['uuid']}"
75
76       assert_text 'created_at'
77
78       if cancelable
79         assert_text 'priority: 1' if type.include?('container')
80         assert_selector 'button', text: 'Cancel'
81         first('a,button', text: 'Cancel').click
82         wait_for_ajax
83       end
84       assert_text 'priority: 0' if cancelable and type.include?('container')
85     end
86   end
87
88   [
89     ['jobs', 'running_job_with_components'],
90     ['pipeline_instances', 'has_component_with_completed_jobs'],
91     ['container_requests', 'running'],
92     ['container_requests', 'completed'],
93   ].each do |type, fixture|
94     test "edit description for #{type}/#{fixture}" do
95       obj = api_fixture(type)[fixture]
96       visit page_with_token "active", "/#{type}/#{obj['uuid']}"
97
98       within('.arv-description-as-subtitle') do
99         find('.fa-pencil').click
100         find('.editable-input textarea').set('*Textile description for object*')
101         find('.editable-submit').click
102       end
103       wait_for_ajax
104
105       # verify description
106       assert page.has_no_text? '*Textile description for object*'
107       assert page.has_text? 'Textile description for object'
108     end
109   end
110
111   [
112     ['Pipeline with default input specifications', 'part-one', 'Provide values for the following'],
113     ['Workflow with default input specifications', 'this workflow has inputs specified', 'Provide a value for the following'],
114   ].each do |template_name, preview_txt, process_txt|
115     test "run a process using template #{template_name} from dashboard" do
116       visit page_with_token('admin')
117       assert_text 'Recent pipelines and processes' # seeing dashboard now
118
119       within('.recent-processes-actions') do
120         assert page.has_link?('All processes')
121         find('a', text: 'Run a process').click
122       end
123
124       # in the chooser, verify preview and click Next button
125       within('.modal-dialog') do
126         find('.selectable', text: template_name).click
127         assert_text preview_txt
128         find('.btn', text: 'Next: choose inputs').click
129       end
130
131       # in the process page now
132       assert_text process_txt
133       assert_selector 'a', text: template_name
134
135       assert_equal "Set value for ex_string_def", find('div.form-group > div > p.form-control-static > a', text: "hello-testing-123")[:"data-title"]
136
137       page.assert_selector 'a.disabled,button.disabled', text: 'Run'
138     end
139   end
140
141   test 'display container state changes in Container Request live log' do
142     use_fake_websocket_driver
143     c = api_fixture('containers')['queued']
144     cr = api_fixture('container_requests')['queued']
145     visit page_with_token('active', '/container_requests/'+cr['uuid'])
146     click_link('Log')
147
148     # The attrs of the "terminal window" text div in the log tab
149     # indicates which objects' events are worth displaying. Events
150     # that arrive too early (before that div exists) are not
151     # shown. For the user's sake, these early logs should also be
152     # retrieved and shown one way or another -- but in this particular
153     # test, we are only interested in logs that arrive by
154     # websocket. Therefore, to avoid races, we wait for the log tab to
155     # display before sending any events.
156     assert_text 'Recent logs'
157
158     [[{
159         event_type: 'dispatch',
160         properties: {
161           text: "dispatch logged a fake message\n",
162         },
163       }, "dispatch logged"],
164      [{
165         event_type: 'update',
166         properties: {
167           old_attributes: {state: 'Locked'},
168           new_attributes: {state: 'Queued'},
169         },
170       }, "Container #{c['uuid']} was returned to the queue"],
171      [{
172         event_type: 'update',
173         properties: {
174           old_attributes: {state: 'Queued'},
175           new_attributes: {state: 'Locked'},
176         },
177       }, "Container #{c['uuid']} was taken from the queue by a dispatch process"],
178      [{
179         event_type: 'crunch-run',
180         properties: {
181           text: "according to fake crunch-run,\nsome setup stuff happened on the compute node\n",
182         },
183       }, "setup stuff happened"],
184      [{
185         event_type: 'update',
186         properties: {
187           old_attributes: {state: 'Locked'},
188           new_attributes: {state: 'Running'},
189         },
190       }, "Container #{c['uuid']} started"],
191      [{
192         event_type: 'update',
193         properties: {
194           old_attributes: {state: 'Running'},
195           new_attributes: {state: 'Complete', exit_code: 1},
196         },
197       }, "Container #{c['uuid']} finished with exit code 1 (failure)"],
198      # It's unrealistic for state to change again once it's Complete,
199      # but the logging code doesn't care, so we do it to keep the test
200      # simple.
201      [{
202         event_type: 'update',
203         properties: {
204           old_attributes: {state: 'Running'},
205           new_attributes: {state: 'Cancelled'},
206         },
207       }, "Container #{c['uuid']} was cancelled"],
208     ].each do |send_event, expect_log_text|
209       assert_no_text(expect_log_text)
210       fake_websocket_event(send_event.merge(object_uuid: c['uuid']))
211       assert_text(expect_log_text)
212     end
213   end
214
215   [
216     ['jobs', 'active', 'running_job_with_components', 'component1', '/jobs/zzzzz-8i9sb-jyq01m7in1jlofj#Log'],
217     ['pipeline_instances', 'active', 'pipeline_in_running_state', 'foo', '/jobs/zzzzz-8i9sb-pshmckwoma9plh7#Log'],
218     ['pipeline_instances', nil, 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', 'foo', 'Log unavailable'],
219   ].each do |type, token, fixture, child, log_link|
220     test "link_to_log for #{fixture} for #{token}" do
221       obj = api_fixture(type)[fixture]
222       if token
223         visit page_with_token token, "/#{type}/#{obj['uuid']}"
224       else
225         Rails.configuration.anonymous_user_token =
226           api_fixture("api_client_authorizations", "anonymous", "api_token")
227         visit "/#{type}/#{obj['uuid']}"
228       end
229
230       click_link(child)
231
232       if token
233         assert_selector "a[href=\"#{log_link}\"]"
234       else
235         assert_text log_link
236       end
237     end
238   end
239 end