Merge branch 'master' into origin-3381-job-progress-bar-bug
[arvados.git] / apps / workbench / test / integration / pipeline_instances_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class PipelineInstancesTest < ActionDispatch::IntegrationTest
6   setup do
7     # Selecting collections requiresLocalStorage
8     headless = Headless.new
9     headless.start
10     Capybara.current_driver = :selenium
11   end
12
13   test 'Create and run a pipeline' do
14     visit page_with_token('active_trustedclient')
15
16     visit '/pipeline_templates'
17     within('tr', text: 'Two Part Pipeline Template') do
18       find('a,button', text: 'Run').click
19     end
20
21     # project chooser
22     within('.modal-dialog') do
23       find('.selectable', text: 'A Project').click
24       find('button', text: 'Choose').click
25     end
26
27     # This pipeline needs input. So, Run should be disabled
28     page.assert_selector 'a.disabled,button.disabled', text: 'Run'
29
30     instance_page = current_path
31
32     # Go over to the collections page and select something
33     visit '/collections'
34     within('tr', text: 'GNU_General_Public_License') do
35       find('input[type=checkbox]').click
36     end
37     find('#persistent-selection-count').click
38
39     # Add this collection to the project
40     visit '/projects'
41     find("#projects-menu").click
42     find('.dropdown-menu a,button', text: 'A Project').click
43     find('.btn', text: 'Add data').click
44     within('.modal-dialog') do
45       wait_for_ajax
46       first('span', text: 'foo_tag').click
47       find('.btn', text: 'Add').click
48     end
49     using_wait_time(Capybara.default_wait_time * 3) do
50       wait_for_ajax
51     end
52
53     click_link 'Jobs and pipelines'
54     find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
55       find('a', text: 'Show').
56       click
57
58     assert find('p', text: 'Provide a value')
59
60     find('div.form-group', text: 'Foo/bar pair').
61       find('.btn', text: 'Choose').
62       click
63
64     within('.modal-dialog') do
65       assert(has_text?("Foo/bar pair"),
66              "pipeline input picker missing name of input")
67       wait_for_ajax
68       first('span', text: 'foo_tag').click
69       find('button', text: 'OK').click
70     end
71     wait_for_ajax
72
73     # "Run" button is now enabled
74     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
75
76     first('a,button', text: 'Run').click
77
78     # Pipeline is running. We have a "Pause" button instead now.
79     page.assert_selector 'a,button', text: 'Pause'
80     find('a,button', text: 'Pause').click
81
82     # Pipeline is stopped. It should now be in paused state and Runnable again.
83     assert page.has_text? 'Paused'
84     page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
85     page.assert_selector 'a,button', text: 'Re-run with latest'
86
87     # Since it is test env, no jobs are created to run. So, graph not visible
88     assert_not page.has_text? 'Graph'
89   end
90
91   # Create a pipeline instance from within a project and run
92   test 'Create pipeline inside a project and run' do
93     visit page_with_token('active_trustedclient')
94
95     # Go over to the collections page and select something
96     visit '/collections'
97     within('tr', text: 'GNU_General_Public_License') do
98       find('input[type=checkbox]').click
99     end
100     find('#persistent-selection-count').click
101
102     # Add this collection to the project using collections menu from top nav
103     visit '/projects'
104     find("#projects-menu").click
105     find('.dropdown-menu a,button', text: 'A Project').click
106     find('.btn', text: 'Add data').click
107     within('.modal-dialog') do
108       wait_for_ajax
109       first('span', text: 'foo_tag').click
110       find('.btn', text: 'Add').click
111     end
112     using_wait_time(Capybara.default_wait_time * 3) do
113       wait_for_ajax
114     end
115
116     # create a pipeline instance
117     find('.btn', text: 'Run a pipeline').click
118     within('.modal-dialog') do
119       find('.selectable', text: 'Two Part Pipeline Template').click
120       find('.btn', text: 'Next: choose inputs').click
121     end
122
123     assert find('p', text: 'Provide a value')
124
125     find('div.form-group', text: 'Foo/bar pair').
126       find('.btn', text: 'Choose').
127       click
128
129     within('.modal-dialog') do
130       assert_selector 'button.dropdown-toggle', text: 'A Project'
131       wait_for_ajax
132       first('span', text: 'foo_tag').click
133       find('button', text: 'OK').click
134     end
135     wait_for_ajax
136
137     # "Run" button present and enabled
138     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
139     first('a,button', text: 'Run').click
140
141     # Pipeline is running. We have a "Pause" button instead now.
142     page.assert_no_selector 'a,button', text: 'Run'
143     page.assert_selector 'a,button', text: 'Pause'
144
145     # Since it is test env, no jobs are created to run. So, graph not visible
146     assert_not page.has_text? 'Graph'
147   end
148
149   # Create a pipeline instance from within a project and run
150   test 'Run a pipeline from dashboard' do
151     visit page_with_token('active_trustedclient')
152
153     # create a pipeline instance
154     find('.btn', text: 'Run a pipeline').click
155     within('.modal-dialog') do
156       find('.selectable', text: 'Two Part Pipeline Template').click
157       find('.btn', text: 'Next: choose inputs').click
158     end
159
160     assert find('p', text: 'Provide a value')
161
162     find('div.form-group', text: 'Foo/bar pair').
163       find('.btn', text: 'Choose').
164       click
165
166     within('.modal-dialog') do
167       assert_selector 'button.dropdown-toggle', text: 'Home'
168       wait_for_ajax
169       click_button "Home"
170       click_link "A Project"
171       wait_for_ajax
172       first('span', text: 'foo_tag').click
173       find('button', text: 'OK').click
174     end
175     wait_for_ajax
176
177     # "Run" button present and enabled
178     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
179     first('a,button', text: 'Run').click
180
181     # Pipeline is running. We have a "Pause" button instead now.
182     page.assert_no_selector 'a,button', text: 'Run'
183     page.assert_selector 'a,button', text: 'Pause'
184
185     # Since it is test env, no jobs are created to run. So, graph not visible
186     assert_not page.has_text? 'Graph'
187   end
188
189
190   test 'view pipeline with job and see graph' do
191     visit page_with_token('active_trustedclient')
192
193     visit '/pipeline_instances'
194     assert page.has_text? 'pipeline_with_job'
195
196     find('a', text: 'pipeline_with_job').click
197
198     # since the pipeline component has a job, expect to see the graph
199     assert page.has_text? 'Graph'
200     click_link 'Graph'
201     assert page.has_text? 'script_version'
202   end
203
204   test 'pipeline description' do
205     visit page_with_token('active_trustedclient')
206
207     visit '/pipeline_instances'
208     assert page.has_text? 'pipeline_with_job'
209
210     find('a', text: 'pipeline_with_job').click
211
212     within('.arv-description-as-subtitle') do
213       find('.fa-pencil').click
214       find('.editable-input textarea').set('*Textile description for pipeline instance*')
215       find('.editable-submit').click
216     end
217     wait_for_ajax
218
219     # verify description
220     assert page.has_no_text? '*Textile description for pipeline instance*'
221     assert page.has_text? 'Textile description for pipeline instance'
222   end
223
224   test "JSON popup available for strange components" do
225     uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
226     visit page_with_token("active", "/pipeline_instances/#{uuid}")
227     click_on "Components"
228     assert(page.has_no_text?("script_parameters"),
229            "components JSON visible without popup")
230     click_on "Show components JSON"
231     assert(page.has_text?("script_parameters"),
232            "components JSON not found")
233   end
234
235   PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
236   def check_parameter_search(proj_name)
237     template = api_fixture("pipeline_templates")["parameter_with_search"]
238     search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
239     visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
240     click_on "Run this pipeline"
241     within(".modal-dialog") do  # Set project for the new pipeline instance
242       find(".selectable", text: proj_name).click
243       click_on "Choose"
244     end
245     assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
246     first("a.btn,button", text: "Choose").click
247     within(".modal-body") do
248       if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
249         # Switch finder modal to Subproject to find the Collection.
250         click_on proj_name
251         click_on PROJECT_WITH_SEARCH_COLLECTION
252       end
253       assert_equal(search_text, first("input").value,
254                    "parameter search not preseeded")
255       assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
256              "baz Collection not in preseeded search results")
257     end
258   end
259
260   test "Workbench respects search_for parameter in templates" do
261     check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
262   end
263
264   test "Workbench preserves search_for parameter after project switch" do
265     check_parameter_search("A Project")
266   end
267 end