Merge branch 'master' into 3699-arv-copy
[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   test 'view pipeline with job and see graph' do
150     visit page_with_token('active_trustedclient')
151
152     visit '/pipeline_instances'
153     assert page.has_text? 'pipeline_with_job'
154
155     find('a', text: 'pipeline_with_job').click
156
157     # since the pipeline component has a job, expect to see the graph
158     assert page.has_text? 'Graph'
159     click_link 'Graph'
160     assert page.has_text? 'script_version'
161   end
162
163   test 'pipeline description' do
164     visit page_with_token('active_trustedclient')
165
166     visit '/pipeline_instances'
167     assert page.has_text? 'pipeline_with_job'
168
169     find('a', text: 'pipeline_with_job').click
170
171     within('.arv-description-as-subtitle') do
172       find('.fa-pencil').click
173       find('.editable-input textarea').set('*Textile description for pipeline instance*')
174       find('.editable-submit').click
175     end
176     wait_for_ajax
177
178     # verify description
179     assert page.has_no_text? '*Textile description for pipeline instance*'
180     assert page.has_text? 'Textile description for pipeline instance'
181   end
182
183   test "JSON popup available for strange components" do
184     uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
185     visit page_with_token("active", "/pipeline_instances/#{uuid}")
186     click_on "Components"
187     assert(page.has_no_text?("script_parameters"),
188            "components JSON visible without popup")
189     click_on "Show components JSON"
190     assert(page.has_text?("script_parameters"),
191            "components JSON not found")
192   end
193
194   PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
195   def check_parameter_search(proj_name)
196     template = api_fixture("pipeline_templates")["parameter_with_search"]
197     search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
198     visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
199     click_on "Run this pipeline"
200     within(".modal-dialog") do  # Set project for the new pipeline instance
201       find(".selectable", text: proj_name).click
202       click_on "Choose"
203     end
204     assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
205     first("a.btn,button", text: "Choose").click
206     within(".modal-body") do
207       if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
208         # Switch finder modal to Subproject to find the Collection.
209         click_on proj_name
210         click_on PROJECT_WITH_SEARCH_COLLECTION
211       end
212       assert_equal(search_text, first("input").value,
213                    "parameter search not preseeded")
214       assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
215              "baz Collection not in preseeded search results")
216     end
217   end
218
219   test "Workbench respects search_for parameter in templates" do
220     check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
221   end
222
223   test "Workbench preserves search_for parameter after project switch" do
224     check_parameter_search("A Project")
225   end
226 end