1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class ProjectsTest < ActionDispatch::IntegrationTest
7 Capybara.current_driver = Capybara.javascript_driver
10 test 'Check collection count for A Project in the tab pane titles' do
11 project_uuid = api_fixture('groups')['aproject']['uuid']
12 visit page_with_token 'active', '/projects/' + project_uuid
13 collection_count = page.all("[data-pk*='collection']").count
14 assert_selector '#Data_collections-tab span', text: "(#{collection_count})"
17 test 'Find a project and edit its description' do
18 visit page_with_token 'active', '/'
19 find("#projects-menu").click
20 find(".dropdown-menu a", text: "A Project").click
21 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
22 find('span', text: api_fixture('groups')['aproject']['name']).click
23 within('.arv-description-as-subtitle') do
24 find('.fa-pencil').click
25 find('.editable-input textarea').set('I just edited this.')
26 find('.editable-submit').click
31 assert(find?('.container-fluid', text: 'I just edited this.'),
32 "Description update did not survive page refresh")
35 test 'Find a project and edit description to textile description' do
36 visit page_with_token 'active', '/'
37 find("#projects-menu").click
38 find(".dropdown-menu a", text: "A Project").click
39 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
40 find('span', text: api_fixture('groups')['aproject']['name']).click
41 within('.arv-description-as-subtitle') do
42 find('.fa-pencil').click
43 find('.editable-input textarea').set('<p>*Textile description for A project* - "take me home":/ </p><p>And a new paragraph in description.</p>')
44 find('.editable-submit').click
51 assert(has_no_text?('.container-fluid', text: '*Textile description for A project*'),
52 "Description is not rendered properly")
53 assert(find?('.container-fluid', text: 'Textile description for A project'),
54 "Description update did not survive page refresh")
55 assert(find?('.container-fluid', text: 'And a new paragraph in description'),
56 "Description did not contain the expected new paragraph")
57 assert(page.has_link?("take me home"), "link not found in description")
59 click_link 'take me home'
62 assert(page.has_text?('Active pipelines'), 'Active pipelines - not found on dashboard')
65 test 'Find a project and edit description to html description' do
66 visit page_with_token 'active', '/'
67 find("#projects-menu").click
68 find(".dropdown-menu a", text: "A Project").click
69 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
70 find('span', text: api_fixture('groups')['aproject']['name']).click
71 within('.arv-description-as-subtitle') do
72 find('.fa-pencil').click
73 find('.editable-input textarea').set('<br>Textile description for A project</br> - <a href="/">take me home</a>')
74 find('.editable-submit').click
79 assert(find?('.container-fluid', text: 'Textile description for A project'),
80 "Description update did not survive page refresh")
81 assert(!find?('.container-fluid', text: '<br>Textile description for A project</br>'),
82 "Textile description is displayed with uninterpreted formatting characters")
83 assert(page.has_link?("take me home"),"link not found in description")
84 click_link 'take me home'
85 assert page.has_text?('Active pipelines')
88 test 'Find a project and edit description to textile description with link to object' do
89 visit page_with_token 'active', '/'
90 find("#projects-menu").click
91 find(".dropdown-menu a", text: "A Project").click
92 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
93 find('span', text: api_fixture('groups')['aproject']['name']).click
94 within('.arv-description-as-subtitle') do
95 find('.fa-pencil').click
96 find('.editable-input textarea').set('*Textile description for A project* - "go to sub-project":' + api_fixture('groups')['asubproject']['uuid'] + "'")
97 find('.editable-submit').click
102 assert(find?('.container-fluid', text: 'Textile description for A project'),
103 "Description update did not survive page refresh")
104 assert(!find?('.container-fluid', text: '*Textile description for A project*'),
105 "Textile description is displayed with uninterpreted formatting characters")
106 assert(page.has_link?("go to sub-project"), "link not found in description")
107 click_link 'go to sub-project'
108 assert(page.has_text?(api_fixture('groups')['asubproject']['name']), 'sub-project name not found after clicking link')
111 test 'Add a new name, then edit it, without creating a duplicate' do
112 project_uuid = api_fixture('groups')['aproject']['uuid']
113 specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
114 visit page_with_token 'active', '/projects/' + project_uuid
115 click_link 'Other objects'
116 within '.selection-action-container' do
117 # Wait for the tab to load:
118 assert_selector 'tr[data-kind="arvados#trait"]'
119 within first('tr', text: 'Trait') do
120 find(".fa-pencil").click
121 find('.editable-input input').set('Now I have a name.')
122 find('.glyphicon-ok').click
123 assert_selector '.editable', text: 'Now I have a name.'
124 find(".fa-pencil").click
125 find('.editable-input input').set('Now I have a new name.')
126 find('.glyphicon-ok').click
129 assert_selector '.editable', text: 'Now I have a new name.'
132 click_link 'Other objects'
133 within '.selection-action-container' do
134 find '.editable', text: 'Now I have a new name.'
135 page.assert_no_selector '.editable', text: 'Now I have a name.'
139 test 'Create a project and move it into a different project' do
140 visit page_with_token 'active', '/projects'
141 find("#projects-menu").click
142 find(".dropdown-menu a", text: "Home").click
143 find('.btn', text: "Add a subproject").click
145 # within('.editable', text: 'New project') do
147 find('.fa-pencil').click
148 find('.editable-input input').set('Project 1234')
149 find('.glyphicon-ok').click
154 find("#projects-menu").click
155 find(".dropdown-menu a", text: "Home").click
156 find('.btn', text: "Add a subproject").click
158 find('.fa-pencil').click
159 find('.editable-input input').set('Project 5678')
160 find('.glyphicon-ok').click
164 click_link 'Move to project...'
165 find('.selectable', text: 'Project 1234').click
166 find('.modal-footer a,button', text: 'Move').click
169 # Wait for the page to refresh and show the new parent in Sharing panel
171 assert(page.has_link?("Project 1234"),
172 "Project 5678 should now be inside project 1234")
175 def show_project_using(auth_key, proj_key='aproject')
176 project_uuid = api_fixture('groups')[proj_key]['uuid']
177 visit(page_with_token(auth_key, "/projects/#{project_uuid}"))
178 assert(page.has_text?("A Project"), "not on expected project page")
182 find('#project_sharing').all('tr')
185 def add_share_and_check(share_type, name)
186 assert(page.has_no_text?(name), "project is already shared with #{name}")
187 start_share_count = share_rows.size
188 click_on("Share with #{share_type}")
189 within(".modal-container") do
190 # Order is important here: we should find something that appears in the
191 # modal before we make any assertions about what's not in the modal.
192 # Otherwise, the not-included assertions might falsely pass because
193 # the modal hasn't loaded yet.
194 find(".selectable", text: name).click
195 assert(has_no_selector?(".modal-dialog-preview-pane"),
196 "preview pane available in sharing dialog")
197 assert_raises(Capybara::ElementNotFound,
198 "Projects pulldown available from sharing dialog") do
199 click_on "All projects"
203 using_wait_time(Capybara.default_wait_time * 3) do
204 assert(page.has_link?(name),
205 "new share was not added to sharing table")
206 assert_equal(start_share_count + 1, share_rows.size,
207 "new share did not add row to sharing table")
211 def modify_share_and_check(name)
212 start_rows = share_rows
213 link_row = start_rows.select { |row| row.has_text?(name) }
214 assert_equal(1, link_row.size, "row with new permission not found")
215 within(link_row.first) do
217 select("Write", from: "share_change_level")
218 click_on("editable-submit")
219 assert(has_link?("Write"),
220 "failed to change access level on new share")
223 using_wait_time(Capybara.default_wait_time * 3) do
224 assert(page.has_no_text?(name),
225 "new share row still exists after being revoked")
226 assert_equal(start_rows.size - 1, share_rows.size,
227 "revoking share did not remove row from sharing table")
231 test "project viewer can't see project sharing tab" do
232 show_project_using("project_viewer")
233 assert(page.has_no_link?("Sharing"),
234 "read-only project user sees sharing tab")
237 test "project owner can manage sharing for another user" do
238 add_user = api_fixture('users')['future_project_user']
239 new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
241 show_project_using("active")
243 add_share_and_check("users", new_name)
244 modify_share_and_check(new_name)
247 test "project owner can manage sharing for another group" do
248 new_name = api_fixture('groups')['future_project_viewing_group']['name']
250 show_project_using("active")
252 add_share_and_check("groups", new_name)
253 modify_share_and_check(new_name)
256 test "'share with group' listing does not offer projects" do
257 show_project_using("active")
259 click_on "Share with groups"
260 good_uuid = api_fixture("groups")["private"]["uuid"]
261 assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
262 "'share with groups' listing missing owned user group")
263 bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
264 assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
265 "'share with groups' listing includes project")
273 test "selection #{action} for project" do
274 src = api_fixture('groups')['aproject']
275 dest = api_fixture('groups')['asubproject']
276 my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
278 perform_selection_action src, dest, my_collection, action
282 assert page.has_text?(my_collection['name']), 'Collection not found in src project after copy'
283 visit page_with_token 'active', '/'
284 find("#projects-menu").click
285 find(".dropdown-menu a", text: dest['name']).click
286 assert page.has_text?(my_collection['name']), 'Collection not found in dest project after copy'
288 # now remove it from destination project to restore to original state
289 perform_selection_action dest, nil, my_collection, 'Remove'
291 assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after move'
292 visit page_with_token 'active', '/'
293 find("#projects-menu").click
294 find(".dropdown-menu a", text: dest['name']).click
295 assert page.has_text?(my_collection['name']), 'Collection not found in dest project after move'
297 # move it back to src project to restore to original state
298 perform_selection_action dest, src, my_collection, action
300 assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after remove'
301 visit page_with_token 'active', '/'
302 find("#projects-menu").click
303 find(".dropdown-menu a", text: "Home").click
304 assert page.has_text?(my_collection['name']), 'Collection not found in home project after remove'
309 def perform_selection_action src, dest, item, action
310 visit page_with_token 'active', '/'
311 find("#projects-menu").click
312 find(".dropdown-menu a", text: src['name']).click
313 assert page.has_text?(item['name']), 'Collection not found in src project'
315 within('tr', text: item['name']) do
316 find('input[type=checkbox]').click
319 click_button 'Selection...'
321 within('.selection-action-container') do
322 assert page.has_text?("Compare selected"), "Compare selected link text not found"
323 assert page.has_link?("Copy selected"), "Copy selected link not found"
324 assert page.has_link?("Move selected"), "Move selected link not found"
325 assert page.has_link?("Remove selected"), "Remove selected link not found"
327 click_link "#{action} selected"
330 # select the destination project if a Copy or Move action is being performed
331 if action == 'Copy' || action == 'Move'
332 within(".modal-container") do
333 find('.selectable', text: dest['name']).click
334 find('.modal-footer a,button', text: action).click
340 # Test copy action state. It should not be available when a subproject is selected.
341 test "copy action is disabled when a subproject is selected" do
342 my_project = api_fixture('groups')['aproject']
343 my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
344 my_subproject = api_fixture('groups')['asubproject']
346 # verify that selection options are disabled on the project until an item is selected
347 visit page_with_token 'active', '/'
348 find("#projects-menu").click
349 find(".dropdown-menu a", text: my_project['name']).click
351 click_button 'Selection...'
352 within('.selection-action-container') do
353 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
354 page.assert_selector 'li.disabled', text: 'Compare selected'
355 page.assert_selector 'li.disabled', text: 'Copy selected'
356 page.assert_selector 'li.disabled', text: 'Move selected'
357 page.assert_selector 'li.disabled', text: 'Remove selected'
360 # select collection and verify links are enabled
361 visit page_with_token 'active', '/'
362 find("#projects-menu").click
363 find(".dropdown-menu a", text: my_project['name']).click
364 assert page.has_text?(my_collection['name']), 'Collection not found in project'
366 within('tr', text: my_collection['name']) do
367 find('input[type=checkbox]').click
370 click_button 'Selection...'
371 within('.selection-action-container') do
372 page.assert_no_selector 'li.disabled', text: 'Create new collection with selected collections'
373 page.assert_selector 'li', text: 'Create new collection with selected collections'
374 page.assert_selector 'li.disabled', text: 'Compare selected'
375 page.assert_no_selector 'li.disabled', text: 'Copy selected'
376 page.assert_selector 'li', text: 'Copy selected'
377 page.assert_no_selector 'li.disabled', text: 'Move selected'
378 page.assert_selector 'li', text: 'Move selected'
379 page.assert_no_selector 'li.disabled', text: 'Remove selected'
380 page.assert_selector 'li', text: 'Remove selected'
383 # select subproject and verify that copy action is disabled
384 visit page_with_token 'active', '/'
385 find("#projects-menu").click
386 find(".dropdown-menu a", text: my_project['name']).click
388 click_link 'Subprojects'
389 assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
391 within('tr', text: my_subproject['name']) do
392 find('input[type=checkbox]').click
395 click_button 'Selection...'
396 within('.selection-action-container') do
397 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
398 page.assert_selector 'li.disabled', text: 'Compare selected'
399 page.assert_selector 'li.disabled', text: 'Copy selected'
400 page.assert_no_selector 'li.disabled', text: 'Move selected'
401 page.assert_selector 'li', text: 'Move selected'
402 page.assert_no_selector 'li.disabled', text: 'Remove selected'
403 page.assert_selector 'li', text: 'Remove selected'
406 # select subproject and a collection and verify that copy action is still disabled
407 visit page_with_token 'active', '/'
408 find("#projects-menu").click
409 find(".dropdown-menu a", text: my_project['name']).click
411 click_link 'Subprojects'
412 assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
414 within('tr', text: my_subproject['name']) do
415 find('input[type=checkbox]').click
418 click_link 'Data collections'
419 assert page.has_text?(my_collection['name']), 'Collection not found in project'
421 within('tr', text: my_collection['name']) do
422 find('input[type=checkbox]').click
425 click_button 'Selection...'
426 within('.selection-action-container') do
427 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
428 page.assert_selector 'li.disabled', text: 'Compare selected'
429 page.assert_selector 'li.disabled', text: 'Copy selected'
430 page.assert_no_selector 'li.disabled', text: 'Move selected'
431 page.assert_selector 'li', text: 'Move selected'
432 page.assert_no_selector 'li.disabled', text: 'Remove selected'
433 page.assert_selector 'li', text: 'Remove selected'
437 test "combine selected collections into new collection" do
438 my_project = api_fixture('groups')['aproject']
439 my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
441 visit page_with_token 'active', '/'
442 find("#projects-menu").click
443 find(".dropdown-menu a", text: my_project['name']).click
444 assert page.has_text?(my_collection['name']), 'Collection not found in project'
446 within('tr', text: my_collection['name']) do
447 find('input[type=checkbox]').click
450 click_button 'Selection...'
451 within('.selection-action-container') do
452 click_link 'Create new collection with selected collections'
455 # back in project page
456 assert page.has_text?(my_collection['name']), 'Collection not found in project'
457 assert page.has_link?('Jobs and pipelines'), 'Jobs and pipelines link not found in project'
460 [["jobs", "/jobs"], ["pipelines", "/pipeline_instances"], ["collections", "/collections"]].each do |target,path|
461 test "Test dashboard button all #{target}" do
462 visit page_with_token 'active', '/'
463 click_link "All #{target}"
464 assert_equal path, current_path