9799: Merge branch 'master' into 9799-nonadmin-logs
[arvados.git] / apps / workbench / test / integration / work_units_test.rb
1 require 'integration_helper'
2
3 class WorkUnitsTest < ActionDispatch::IntegrationTest
4   setup do
5     need_javascript
6   end
7
8   test "scroll all_processes page" do
9       expected_min, expected_max, expected, not_expected = [
10         25, 100,
11         ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk3',
12          '/pipeline_instances/zzzzz-d1hrv-jobspeccomponts',
13          '/jobs/zzzzz-8i9sb-grx15v5mjnsyxk7',
14          '/jobs/zzzzz-8i9sb-n7omg50bvt0m1nf',
15          '/container_requests/zzzzz-xvhdp-cr4completedcr2',
16          '/container_requests/zzzzz-xvhdp-cr4requestercn2'],
17         ['/pipeline_instances/zzzzz-d1hrv-scarxiyajtshq3l',
18          '/container_requests/zzzzz-xvhdp-oneof60crs00001']
19       ]
20
21       visit page_with_token('active', "/all_processes")
22
23       page_scrolls = expected_max/20 + 2
24       within('.arv-recent-all-processes') do
25         (0..page_scrolls).each do |i|
26           page.driver.scroll_to 0, 999000
27           begin
28             wait_for_ajax
29           rescue
30           end
31         end
32       end
33
34       # Verify that expected number of processes are found
35       found_items = page.all('tr[data-object-uuid]')
36       found_count = found_items.count
37       if expected_min == expected_max
38         assert_equal(true, found_count == expected_min,
39           "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
40         assert page.has_no_text? 'request failed'
41       else
42         assert_equal(true, found_count>=expected_min,
43           "Found too few items. Expected at least #{expected_min} and found #{found_count}")
44         assert_equal(true, found_count<=expected_max,
45           "Found too many items. Expected at most #{expected_max} and found #{found_count}")
46       end
47
48       # verify that all expected uuid links are found
49       expected.each do |link|
50         assert_selector "a[href=\"#{link}\"]"
51       end
52
53       # verify that none of the not_expected uuid links are found
54       not_expected.each do |link|
55         assert_no_selector "a[href=\"#{link}\"]"
56       end
57   end
58
59   [
60     ['jobs', 'running_job_with_components', true],
61     ['pipeline_instances', 'components_is_jobspec', false],
62     ['containers', 'running', false],
63     ['container_requests', 'running', true],
64   ].each do |type, fixture, cancelable|
65     test "cancel button for #{type}/#{fixture}" do
66       if cancelable
67         need_selenium 'to cancel'
68       end
69
70       obj = api_fixture(type)[fixture]
71       visit page_with_token "active", "/#{type}/#{obj['uuid']}"
72
73       assert_text 'created_at'
74       if cancelable
75         assert_selector 'button', text: 'Cancel'
76         click_button 'Cancel'
77         wait_for_ajax
78       end
79       assert_no_selector 'button', text: 'Cancel'
80     end
81   end
82
83   [
84     ['jobs', 'running_job_with_components'],
85     ['pipeline_instances', 'has_component_with_completed_jobs'],
86     ['container_requests', 'running'],
87     ['container_requests', 'completed'],
88   ].each do |type, fixture|
89     test "edit description for #{type}/#{fixture}" do
90       obj = api_fixture(type)[fixture]
91       visit page_with_token "active", "/#{type}/#{obj['uuid']}"
92
93       within('.arv-description-as-subtitle') do
94         find('.fa-pencil').click
95         find('.editable-input textarea').set('*Textile description for object*')
96         find('.editable-submit').click
97       end
98       wait_for_ajax
99
100       # verify description
101       assert page.has_no_text? '*Textile description for object*'
102       assert page.has_text? 'Textile description for object'
103     end
104   end
105
106   [
107     ['Two Part Pipeline Template', 'part-one', 'Provide a value for the following'],
108     ['Workflow with input specifications', 'this workflow has inputs specified', 'Provide a value for the following'],
109   ].each do |template_name, preview_txt, process_txt|
110     test "run a process using template #{template_name} from dashboard" do
111       visit page_with_token('admin')
112       assert_text 'Recent pipelines and processes' # seeing dashboard now
113
114       within('.recent-processes-actions') do
115         assert page.has_link?('All processes')
116         find('a', text: 'Run a pipeline').click
117       end
118
119       # in the chooser, verify preview and click Next button
120       within('.modal-dialog') do
121         find('.selectable', text: template_name).click
122         assert_text preview_txt
123         find('.btn', text: 'Next: choose inputs').click
124       end
125
126       # in the process page now
127       assert_text process_txt
128       assert_selector 'a', text: template_name
129     end
130   end
131 end