10078: Since we are not fetching components for pipeline instances (at least until...
[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       if cancelable
78         assert_selector 'button', text: 'Cancel'
79         click_button 'Cancel'
80         wait_for_ajax
81       end
82       assert_no_selector 'button', text: 'Cancel'
83     end
84   end
85
86   [
87     ['jobs', 'running_job_with_components'],
88     ['pipeline_instances', 'has_component_with_completed_jobs'],
89     ['container_requests', 'running'],
90     ['container_requests', 'completed'],
91   ].each do |type, fixture|
92     test "edit description for #{type}/#{fixture}" do
93       obj = api_fixture(type)[fixture]
94       visit page_with_token "active", "/#{type}/#{obj['uuid']}"
95
96       within('.arv-description-as-subtitle') do
97         find('.fa-pencil').click
98         find('.editable-input textarea').set('*Textile description for object*')
99         find('.editable-submit').click
100       end
101       wait_for_ajax
102
103       # verify description
104       assert page.has_no_text? '*Textile description for object*'
105       assert page.has_text? 'Textile description for object'
106     end
107   end
108
109   [
110     ['Two Part Pipeline Template', 'part-one', 'Provide a value for the following'],
111     ['Workflow with input specifications', 'this workflow has inputs specified', 'Provide a value for the following'],
112   ].each do |template_name, preview_txt, process_txt|
113     test "run a process using template #{template_name} from dashboard" do
114       visit page_with_token('admin')
115       assert_text 'Recent pipelines and processes' # seeing dashboard now
116
117       within('.recent-processes-actions') do
118         assert page.has_link?('All processes')
119         find('a', text: 'Run a pipeline').click
120       end
121
122       # in the chooser, verify preview and click Next button
123       within('.modal-dialog') do
124         find('.selectable', text: template_name).click
125         assert_text preview_txt
126         find('.btn', text: 'Next: choose inputs').click
127       end
128
129       # in the process page now
130       assert_text process_txt
131       assert_selector 'a', text: template_name
132     end
133   end
134
135   test 'display container state changes in Container Request live log' do
136     use_fake_websocket_driver
137     c = api_fixture('containers')['queued']
138     cr = api_fixture('container_requests')['queued']
139     visit page_with_token('active', '/container_requests/'+cr['uuid'])
140     click_link('Log')
141
142     # The attrs of the "terminal window" text div in the log tab
143     # indicates which objects' events are worth displaying. Events
144     # that arrive too early (before that div exists) are not
145     # shown. For the user's sake, these early logs should also be
146     # retrieved and shown one way or another -- but in this particular
147     # test, we are only interested in logs that arrive by
148     # websocket. Therefore, to avoid races, we wait for the log tab to
149     # display before sending any events.
150     assert_text 'Recent logs'
151
152     [[{
153         event_type: 'dispatch',
154         properties: {
155           text: "dispatch logged a fake message\n",
156         },
157       }, "dispatch logged"],
158      [{
159         event_type: 'update',
160         properties: {
161           old_attributes: {state: 'Locked'},
162           new_attributes: {state: 'Queued'},
163         },
164       }, "Container #{c['uuid']} was returned to the queue"],
165      [{
166         event_type: 'update',
167         properties: {
168           old_attributes: {state: 'Queued'},
169           new_attributes: {state: 'Locked'},
170         },
171       }, "Container #{c['uuid']} was taken from the queue by a dispatch process"],
172      [{
173         event_type: 'crunch-run',
174         properties: {
175           text: "according to fake crunch-run,\nsome setup stuff happened on the compute node\n",
176         },
177       }, "setup stuff happened"],
178      [{
179         event_type: 'update',
180         properties: {
181           old_attributes: {state: 'Locked'},
182           new_attributes: {state: 'Running'},
183         },
184       }, "Container #{c['uuid']} started"],
185      [{
186         event_type: 'update',
187         properties: {
188           old_attributes: {state: 'Running'},
189           new_attributes: {state: 'Complete', exit_code: 1},
190         },
191       }, "Container #{c['uuid']} finished with exit code 1 (failure)"],
192      # It's unrealistic for state to change again once it's Complete,
193      # but the logging code doesn't care, so we do it to keep the test
194      # simple.
195      [{
196         event_type: 'update',
197         properties: {
198           old_attributes: {state: 'Running'},
199           new_attributes: {state: 'Cancelled'},
200         },
201       }, "Container #{c['uuid']} was cancelled"],
202     ].each do |send_event, expect_log_text|
203       assert_no_text(expect_log_text)
204       fake_websocket_event(send_event.merge(object_uuid: c['uuid']))
205       assert_text(expect_log_text)
206     end
207   end
208 end