Merge branch 'master' into 2761-diagnostic-suite
[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('.arv-project-list a,button', text: 'A Project').click
42     find('.btn', text: 'Add data').click
43     within('.modal-dialog') do
44       wait_for_ajax
45       first('span', text: 'foo_tag').click
46       find('.btn', text: 'Add').click
47     end
48     using_wait_time(Capybara.default_wait_time * 3) do
49       wait_for_ajax
50     end
51
52     click_link 'Jobs and pipelines'
53     find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
54       find('a', text: 'Show').
55       click
56
57     assert find('p', text: 'Provide a value')
58
59     find('div.form-group', text: 'Foo/bar pair').
60       find('.btn', text: 'Choose').
61       click
62
63     within('.modal-dialog') do
64       assert(has_text?("Foo/bar pair"),
65              "pipeline input picker missing name of input")
66       wait_for_ajax
67       first('span', text: 'foo_tag').click
68       find('button', text: 'OK').click
69     end
70     wait_for_ajax
71
72     # "Run" button is now enabled
73     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
74
75     first('a,button', text: 'Run').click
76
77     # Pipeline is running. We have a "Stop" button instead now.
78     page.assert_selector 'a,button', text: 'Stop'
79     find('a,button', text: 'Stop').click
80
81     # Pipeline is stopped. It should now be in paused state and Runnable again.
82     assert page.has_text? 'Paused'
83     page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
84     page.assert_selector 'a,button', text: 'Clone and edit'
85
86     # Since it is test env, no jobs are created to run. So, graph not visible
87     assert_not page.has_text? 'Graph'
88   end
89
90   # Create a pipeline instance from within a project and run
91   test 'Create pipeline inside a project and run' do
92     visit page_with_token('active_trustedclient')
93
94     # Go over to the collections page and select something
95     visit '/collections'
96     within('tr', text: 'GNU_General_Public_License') do
97       find('input[type=checkbox]').click
98     end
99     find('#persistent-selection-count').click
100
101     # Add this collection to the project using collections menu from top nav
102     visit '/projects'
103     find('.arv-project-list a,button', text: 'A Project').click
104     find('.btn', text: 'Add data').click
105     within('.modal-dialog') do
106       wait_for_ajax
107       first('span', text: 'foo_tag').click
108       find('.btn', text: 'Add').click
109     end
110     using_wait_time(Capybara.default_wait_time * 3) do
111       wait_for_ajax
112     end
113
114     # create a pipeline instance
115     find('.btn', text: 'Run a pipeline').click
116     within('.modal-dialog') do
117       find('.selectable', text: 'Two Part Pipeline Template').click
118       find('.btn', text: 'Next: choose inputs').click
119     end
120
121     assert find('p', text: 'Provide a value')
122
123     find('div.form-group', text: 'Foo/bar pair').
124       find('.btn', text: 'Choose').
125       click
126
127     within('.modal-dialog') do
128       assert_selector 'button.dropdown-toggle', text: 'A Project'
129       wait_for_ajax
130       first('span', text: 'foo_tag').click
131       find('button', text: 'OK').click
132     end
133     wait_for_ajax
134
135     # "Run" button present and enabled
136     page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
137     first('a,button', text: 'Run').click
138
139     # Pipeline is running. We have a "Stop" button instead now.
140     page.assert_no_selector 'a,button', text: 'Run'
141     page.assert_selector 'a,button', text: 'Stop'
142
143     # Since it is test env, no jobs are created to run. So, graph not visible
144     assert_not page.has_text? 'Graph'
145   end
146
147   test 'view pipeline with job and see graph' do
148     visit page_with_token('active_trustedclient')
149
150     visit '/pipeline_instances'
151     assert page.has_text? 'pipeline_with_job'
152
153     find('a', text: 'pipeline_with_job').click
154
155     # since the pipeline component has a job, expect to see the graph
156     assert page.has_text? 'Graph'
157     click_link 'Graph'
158     assert page.has_text? 'script_version'
159   end
160
161   test 'pipeline description' do
162     visit page_with_token('active_trustedclient')
163
164     visit '/pipeline_instances'
165     assert page.has_text? 'pipeline_with_template'
166
167     find('a', text: 'pipeline_with_job').click
168
169     within('.arv-description-as-subtitle') do
170       find('.fa-pencil').click
171       find('.editable-input textarea').set('*Textile description for pipeline instance* - "link to template":' + api_fixture('pipeline_templates')['two_part']['uuid'])
172       find('.editable-submit').click
173     end
174     wait_for_ajax
175
176     # verify description
177     assert page.has_no_text? '*Textile description for pipeline instance*'
178     assert page.has_text? 'Textile description for pipeline instance'
179     assert page.has_link? 'link to template'
180     click_link 'link to template'
181
182     # in template page
183     assert page.has_text? 'Two Part Pipeline Template'
184   end
185
186   test "JSON popup available for strange components" do
187     uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
188     visit page_with_token("active", "/pipeline_instances/#{uuid}")
189     click_on "Components"
190     assert(page.has_no_text?("script_parameters"),
191            "components JSON visible without popup")
192     click_on "Show components JSON"
193     assert(page.has_text?("script_parameters"),
194            "components JSON not found")
195   end
196
197   PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
198   def check_parameter_search(proj_name)
199     template = api_fixture("pipeline_templates")["parameter_with_search"]
200     search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
201     visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
202     click_on "Run this pipeline"
203     within(".modal-dialog") do  # Set project for the new pipeline instance
204       find(".selectable", text: proj_name).click
205       click_on "Choose"
206     end
207     assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
208     first("a.btn,button", text: "Choose").click
209     within(".modal-body") do
210       if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
211         # Switch finder modal to Subproject to find the Collection.
212         click_on proj_name
213         click_on PROJECT_WITH_SEARCH_COLLECTION
214       end
215       assert_equal(search_text, first("input").value,
216                    "parameter search not preseeded")
217       assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
218              "baz Collection not in preseeded search results")
219     end
220   end
221
222   test "Workbench respects search_for parameter in templates" do
223     check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
224   end
225
226   test "Workbench preserves search_for parameter after project switch" do
227     check_parameter_search("A Project")
228   end
229 end