1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class ProjectsTest < ActionDispatch::IntegrationTest
6 reset_api_fixtures :after_suite
9 Capybara.current_driver = Capybara.javascript_driver
12 test 'Check collection count for A Project in the tab pane titles' do
13 project_uuid = api_fixture('groups')['aproject']['uuid']
14 visit page_with_token 'active', '/projects/' + project_uuid
15 collection_count = page.all("[data-pk*='collection']").count
16 assert_selector '#Data_collections-tab span', text: "(#{collection_count})"
19 test 'Find a project and edit its description' do
20 visit page_with_token 'active', '/'
21 find("#projects-menu").click
22 find(".dropdown-menu a", text: "A Project").click
23 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
24 find('span', text: api_fixture('groups')['aproject']['name']).click
25 within('.arv-description-as-subtitle') do
26 find('.fa-pencil').click
27 find('.editable-input textarea').set('I just edited this.')
28 find('.editable-submit').click
33 assert(find?('.container-fluid', text: 'I just edited this.'),
34 "Description update did not survive page refresh")
37 test 'Find a project and edit description to textile description' do
38 visit page_with_token 'active', '/'
39 find("#projects-menu").click
40 find(".dropdown-menu a", text: "A Project").click
41 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
42 find('span', text: api_fixture('groups')['aproject']['name']).click
43 within('.arv-description-as-subtitle') do
44 find('.fa-pencil').click
45 find('.editable-input textarea').set('<p>*Textile description for A project* - "take me home":/ </p><p>And a new paragraph in description.</p>')
46 find('.editable-submit').click
53 assert_no_text '*Textile description for A project*'
54 assert(find?('.container-fluid', text: 'Textile description for A project'),
55 "Description update did not survive page refresh")
56 assert(find?('.container-fluid', text: 'And a new paragraph in description'),
57 "Description did not contain the expected new paragraph")
58 assert(page.has_link?("take me home"), "link not found in description")
60 click_link 'take me home'
63 assert(page.has_text?('Active pipelines'), 'Active pipelines - not found on dashboard')
66 test 'Find a project and edit description to html description' do
67 visit page_with_token 'active', '/'
68 find("#projects-menu").click
69 find(".dropdown-menu a", text: "A Project").click
70 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
71 find('span', text: api_fixture('groups')['aproject']['name']).click
72 within('.arv-description-as-subtitle') do
73 find('.fa-pencil').click
74 find('.editable-input textarea').set('<br>Textile description for A project</br> - <a href="/">take me home</a>')
75 find('.editable-submit').click
80 assert(find?('.container-fluid', text: 'Textile description for A project'),
81 "Description update did not survive page refresh")
82 assert(!find?('.container-fluid', text: '<br>Textile description for A project</br>'),
83 "Textile description is displayed with uninterpreted formatting characters")
84 assert(page.has_link?("take me home"),"link not found in description")
85 click_link 'take me home'
86 assert page.has_text?('Active pipelines')
89 test 'Find a project and edit description to textile description with link to object' do
90 visit page_with_token 'active', '/'
91 find("#projects-menu").click
92 find(".dropdown-menu a", text: "A Project").click
93 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
94 find('span', text: api_fixture('groups')['aproject']['name']).click
95 within('.arv-description-as-subtitle') do
96 find('.fa-pencil').click
97 find('.editable-input textarea').set('*Textile description for A project* - "go to sub-project":' + api_fixture('groups')['asubproject']['uuid'] + "'")
98 find('.editable-submit').click
103 assert(find?('.container-fluid', text: 'Textile description for A project'),
104 "Description update did not survive page refresh")
105 assert(!find?('.container-fluid', text: '*Textile description for A project*'),
106 "Textile description is displayed with uninterpreted formatting characters")
107 assert(page.has_link?("go to sub-project"), "link not found in description")
108 click_link 'go to sub-project'
109 assert(page.has_text?(api_fixture('groups')['asubproject']['name']), 'sub-project name not found after clicking link')
112 test 'Add a new name, then edit it, without creating a duplicate' do
113 project_uuid = api_fixture('groups')['aproject']['uuid']
114 specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
115 visit page_with_token 'active', '/projects/' + project_uuid
116 click_link 'Other objects'
117 within '.selection-action-container' do
118 # Wait for the tab to load:
119 assert_selector 'tr[data-kind="arvados#trait"]'
120 within first('tr', text: 'Trait') do
121 find(".fa-pencil").click
122 find('.editable-input input').set('Now I have a name.')
123 find('.glyphicon-ok').click
124 assert_selector '.editable', text: 'Now I have a name.'
125 find(".fa-pencil").click
126 find('.editable-input input').set('Now I have a new name.')
127 find('.glyphicon-ok').click
130 assert_selector '.editable', text: 'Now I have a new name.'
133 click_link 'Other objects'
134 within '.selection-action-container' do
135 find '.editable', text: 'Now I have a new name.'
136 page.assert_no_selector '.editable', text: 'Now I have a name.'
140 test 'Create a project and move it into a different project' do
141 visit page_with_token 'active', '/projects'
142 find("#projects-menu").click
143 find(".dropdown-menu a", text: "Home").click
144 find('.btn', text: "Add a subproject").click
146 # within('.editable', text: 'New project') do
148 find('.fa-pencil').click
149 find('.editable-input input').set('Project 1234')
150 find('.glyphicon-ok').click
155 find("#projects-menu").click
156 find(".dropdown-menu a", text: "Home").click
157 find('.btn', text: "Add a subproject").click
159 find('.fa-pencil').click
160 find('.editable-input input').set('Project 5678')
161 find('.glyphicon-ok').click
165 click_link 'Move project...'
166 find('.selectable', text: 'Project 1234').click
167 find('.modal-footer a,button', text: 'Move').click
170 # Wait for the page to refresh and show the new parent in Sharing panel
172 assert(page.has_link?("Project 1234"),
173 "Project 5678 should now be inside project 1234")
176 def show_project_using(auth_key, proj_key='aproject')
177 project_uuid = api_fixture('groups')[proj_key]['uuid']
178 visit(page_with_token(auth_key, "/projects/#{project_uuid}"))
179 assert(page.has_text?("A Project"), "not on expected project page")
183 find('#project_sharing').all('tr')
186 def add_share_and_check(share_type, name, obj=nil)
187 assert(page.has_no_text?(name), "project is already shared with #{name}")
188 start_share_count = share_rows.size
189 click_on("Share with #{share_type}")
190 within(".modal-container") do
191 # Order is important here: we should find something that appears in the
192 # modal before we make any assertions about what's not in the modal.
193 # Otherwise, the not-included assertions might falsely pass because
194 # the modal hasn't loaded yet.
195 find(".selectable", text: name).click
196 assert(has_no_selector?(".modal-dialog-preview-pane"),
197 "preview pane available in sharing dialog")
198 if share_type == 'users' and obj and obj['email']
199 assert(page.has_text?(obj['email']), "Did not find user's email")
201 assert_raises(Capybara::ElementNotFound,
202 "Projects pulldown available from sharing dialog") do
203 click_on "All projects"
207 using_wait_time(Capybara.default_wait_time * 3) do
208 assert(page.has_link?(name),
209 "new share was not added to sharing table")
210 assert_equal(start_share_count + 1, share_rows.size,
211 "new share did not add row to sharing table")
215 def modify_share_and_check(name)
216 start_rows = share_rows
217 link_row = start_rows.select { |row| row.has_text?(name) }
218 assert_equal(1, link_row.size, "row with new permission not found")
219 within(link_row.first) do
221 select("Write", from: "share_change_level")
222 click_on("editable-submit")
223 assert(has_link?("Write"),
224 "failed to change access level on new share")
227 using_wait_time(Capybara.default_wait_time * 3) do
228 assert(page.has_no_text?(name),
229 "new share row still exists after being revoked")
230 assert_equal(start_rows.size - 1, share_rows.size,
231 "revoking share did not remove row from sharing table")
235 test "project viewer can't see project sharing tab" do
236 show_project_using("project_viewer")
237 assert(page.has_no_link?("Sharing"),
238 "read-only project user sees sharing tab")
241 test "project owner can manage sharing for another user" do
242 add_user = api_fixture('users')['future_project_user']
243 new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
245 show_project_using("active")
247 add_share_and_check("users", new_name, add_user)
248 modify_share_and_check(new_name)
251 test "project owner can manage sharing for another group" do
252 new_name = api_fixture('groups')['future_project_viewing_group']['name']
254 show_project_using("active")
256 add_share_and_check("groups", new_name)
257 modify_share_and_check(new_name)
260 test "'share with group' listing does not offer projects" do
261 show_project_using("active")
263 click_on "Share with groups"
264 good_uuid = api_fixture("groups")["private"]["uuid"]
265 assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
266 "'share with groups' listing missing owned user group")
267 bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
268 assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
269 "'share with groups' listing includes project")
273 ['Move',api_fixture('collections')['collection_to_move_around_in_aproject'],
274 api_fixture('groups')['aproject'],api_fixture('groups')['asubproject']],
275 ['Remove',api_fixture('collections')['collection_to_move_around_in_aproject'],
276 api_fixture('groups')['aproject']],
277 ['Copy',api_fixture('collections')['collection_to_move_around_in_aproject'],
278 api_fixture('groups')['aproject'],api_fixture('groups')['asubproject']],
279 ['Remove',api_fixture('collections')['collection_in_aproject_with_same_name_as_in_home_project'],
280 api_fixture('groups')['aproject'],nil,true],
281 ].each do |action, my_collection, src, dest=nil, expect_name_change=nil|
282 test "selection #{action} #{expect_name_change} for project" do
283 perform_selection_action src, dest, my_collection, action
287 assert page.has_text?(my_collection['name']), 'Collection not found in src project after copy'
288 visit page_with_token 'active', '/'
289 find("#projects-menu").click
290 find(".dropdown-menu a", text: dest['name']).click
291 assert page.has_text?(my_collection['name']), 'Collection not found in dest project after copy'
293 # now remove it from destination project to restore to original state
294 perform_selection_action dest, nil, my_collection, 'Remove'
296 assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after move'
297 visit page_with_token 'active', '/'
298 find("#projects-menu").click
299 find(".dropdown-menu a", text: dest['name']).click
300 assert page.has_text?(my_collection['name']), 'Collection not found in dest project after move'
302 # move it back to src project to restore to original state
303 perform_selection_action dest, src, my_collection, action
305 assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after remove'
306 visit page_with_token 'active', '/'
307 find("#projects-menu").click
308 find(".dropdown-menu a", text: "Home").click
309 assert page.has_text?(my_collection['name']), 'Collection not found in home project after remove'
310 if expect_name_change
311 assert page.has_text?(my_collection['name']+' removed from ' + src['name']),
312 'Collection with update name is not found in home project after remove'
318 def perform_selection_action src, dest, item, action
319 visit page_with_token 'active', '/'
320 find("#projects-menu").click
321 find(".dropdown-menu a", text: src['name']).click
322 assert page.has_text?(item['name']), 'Collection not found in src project'
324 within('tr', text: item['name']) do
325 find('input[type=checkbox]').click
328 click_button 'Selection...'
330 within('.selection-action-container') do
331 assert page.has_text?("Compare selected"), "Compare selected link text not found"
332 assert page.has_link?("Copy selected"), "Copy selected link not found"
333 assert page.has_link?("Move selected"), "Move selected link not found"
334 assert page.has_link?("Remove selected"), "Remove selected link not found"
336 click_link "#{action} selected"
339 # select the destination project if a Copy or Move action is being performed
340 if action == 'Copy' || action == 'Move'
341 within(".modal-container") do
342 find('.selectable', text: dest['name']).click
343 find('.modal-footer a,button', text: action).click
349 # Test copy action state. It should not be available when a subproject is selected.
350 test "copy action is disabled when a subproject is selected" do
351 my_project = api_fixture('groups')['aproject']
352 my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
353 my_subproject = api_fixture('groups')['asubproject']
355 # verify that selection options are disabled on the project until an item is selected
356 visit page_with_token 'active', '/'
357 find("#projects-menu").click
358 find(".dropdown-menu a", text: my_project['name']).click
360 click_button 'Selection...'
361 within('.selection-action-container') do
362 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
363 page.assert_selector 'li.disabled', text: 'Compare selected'
364 page.assert_selector 'li.disabled', text: 'Copy selected'
365 page.assert_selector 'li.disabled', text: 'Move selected'
366 page.assert_selector 'li.disabled', text: 'Remove selected'
369 # select collection and verify links are enabled
370 visit page_with_token 'active', '/'
371 find("#projects-menu").click
372 find(".dropdown-menu a", text: my_project['name']).click
373 assert page.has_text?(my_collection['name']), 'Collection not found in project'
375 within('tr', text: my_collection['name']) do
376 find('input[type=checkbox]').click
379 click_button 'Selection...'
380 within('.selection-action-container') do
381 page.assert_no_selector 'li.disabled', text: 'Create new collection with selected collections'
382 page.assert_selector 'li', text: 'Create new collection with selected collections'
383 page.assert_selector 'li.disabled', text: 'Compare selected'
384 page.assert_no_selector 'li.disabled', text: 'Copy selected'
385 page.assert_selector 'li', text: 'Copy selected'
386 page.assert_no_selector 'li.disabled', text: 'Move selected'
387 page.assert_selector 'li', text: 'Move selected'
388 page.assert_no_selector 'li.disabled', text: 'Remove selected'
389 page.assert_selector 'li', text: 'Remove selected'
392 # select subproject and verify that copy action is disabled
393 visit page_with_token 'active', '/'
394 find("#projects-menu").click
395 find(".dropdown-menu a", text: my_project['name']).click
397 click_link 'Subprojects'
398 assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
400 within('tr', text: my_subproject['name']) do
401 find('input[type=checkbox]').click
404 click_button 'Selection...'
405 within('.selection-action-container') do
406 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
407 page.assert_selector 'li.disabled', text: 'Compare selected'
408 page.assert_selector 'li.disabled', text: 'Copy selected'
409 page.assert_no_selector 'li.disabled', text: 'Move selected'
410 page.assert_selector 'li', text: 'Move selected'
411 page.assert_no_selector 'li.disabled', text: 'Remove selected'
412 page.assert_selector 'li', text: 'Remove selected'
415 # select subproject and a collection and verify that copy action is still disabled
416 visit page_with_token 'active', '/'
417 find("#projects-menu").click
418 find(".dropdown-menu a", text: my_project['name']).click
420 click_link 'Subprojects'
421 assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
423 within('tr', text: my_subproject['name']) do
424 find('input[type=checkbox]').click
427 click_link 'Data collections'
428 assert page.has_text?(my_collection['name']), 'Collection not found in project'
430 within('tr', text: my_collection['name']) do
431 find('input[type=checkbox]').click
434 click_button 'Selection...'
435 within('.selection-action-container') do
436 page.assert_selector 'li.disabled', text: 'Create new collection with selected collections'
437 page.assert_selector 'li.disabled', text: 'Compare selected'
438 page.assert_selector 'li.disabled', text: 'Copy selected'
439 page.assert_no_selector 'li.disabled', text: 'Move selected'
440 page.assert_selector 'li', text: 'Move selected'
441 page.assert_no_selector 'li.disabled', text: 'Remove selected'
442 page.assert_selector 'li', text: 'Remove selected'
448 ['project_viewer', false],
449 ].each do |user, expect_collection_in_aproject|
450 test "combine selected collections into new collection #{user} #{expect_collection_in_aproject}" do
451 my_project = api_fixture('groups')['aproject']
452 my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
454 visit page_with_token user, '/'
455 find("#projects-menu").click
456 find(".dropdown-menu a", text: my_project['name']).click
457 assert page.has_text?(my_collection['name']), 'Collection not found in project'
459 within('tr', text: my_collection['name']) do
460 find('input[type=checkbox]').click
463 click_button 'Selection...'
464 within('.selection-action-container') do
465 click_link 'Create new collection with selected collections'
468 # now in the new collection page
469 if expect_collection_in_aproject
470 assert page.has_text?("Created new collection in the project #{my_project['name']}"),
471 'Not found flash message that new collection is created in aproject'
473 assert page.has_text?("Created new collection in your Home project"),
474 'Not found flash message that new collection is created in Home project'
476 assert page.has_text?('Content hash'), 'Not found content hash in collection page'
482 ["pipelines", "/pipeline_instances"],
483 ["collections", "/collections"]
484 ].each do |target,path|
485 test "Test dashboard button all #{target}" do
486 visit page_with_token 'active', '/'
487 click_link "All #{target}"
488 assert_equal path, current_path
492 def scroll_setup(project_name,
496 sort_parameters = nil)
497 headless = Headless.new
499 Capybara.current_driver = :selenium
501 project_uuid = api_fixture('groups')[project_name]['uuid']
502 visit page_with_token 'user1_with_load', '/projects/' + project_uuid
504 assert(page.has_text?("#{item_list_parameter.humanize} (#{total_nbr_items})"), "Number of #{item_list_parameter.humanize} did not match the input amount")
506 click_link item_list_parameter.humanize
510 find("th[data-sort-order='#{sort_parameters.gsub(/\s/,'')}']").click
515 def scroll_items_check(nbr_items,
521 for i in 1..nbr_items
522 items << "#{fixture_prefix}#{i}"
525 verify_items = items.dup
526 unexpected_items = []
528 within(".arv-project-#{item_list_parameter}") do
529 page.execute_script "window.scrollBy(0,999000)"
535 # Visit all rows. If not all expected items are found, retry
536 found_items = page.all(item_selector)
537 item_count = found_items.count
540 (0..item_count-1).each do |i|
541 # Found row text using the fixture string e.g. "Show Collection_#{n} "
542 item_name = found_items[i].text.split[1]
543 if !items.include? item_name
544 unexpected_items << item_name
546 verify_items.delete item_name
550 assert_operator( previous.downcase, :<=, item_name.downcase) if previous
555 assert_equal true, unexpected_items.empty?, "Found unexpected #{item_list_parameter.humanize} #{unexpected_items.inspect}"
556 assert_equal nbr_items, item_count, "Found different number of #{item_list_parameter.humanize}"
557 assert_equal true, verify_items.empty?, "Did not find all the #{item_list_parameter.humanize}"
562 ['project_with_10_collections', 10],
563 ['project_with_201_collections', 201], # two pages of data
564 ].each do |project_name, nbr_items|
565 test "scroll collections tab for #{project_name} with #{nbr_items} objects" do
566 item_list_parameter = "Data_collections"
567 scroll_setup project_name,
570 scroll_items_check nbr_items,
573 'tr[data-kind="arvados#collection"]'
578 ['project_with_10_collections', 10],
579 ['project_with_201_collections', 201], # two pages of data
580 ].each do |project_name, nbr_items|
581 test "scroll collections tab for #{project_name} with #{nbr_items} objects with ascending sort (case insensitive)" do
582 item_list_parameter = "Data_collections"
583 scroll_setup project_name,
588 scroll_items_check nbr_items,
591 'tr[data-kind="arvados#collection"]',
597 ['project_with_10_pipelines', 10, 0],
598 ['project_with_2_pipelines_and_60_jobs', 2, 60],
599 ['project_with_25_pipelines', 25, 0],
600 ].each do |project_name, num_pipelines, num_jobs|
601 test "scroll pipeline instances tab for #{project_name} with #{num_pipelines} pipelines and #{num_jobs} jobs" do
602 item_list_parameter = "Jobs_and_pipelines"
603 scroll_setup project_name,
604 num_pipelines + num_jobs,
606 # check the general scrolling and the pipelines
607 scroll_items_check num_pipelines,
610 'tr[data-kind="arvados#pipelineInstance"]'
611 # Check job count separately
612 jobs_found = page.all('tr[data-kind="arvados#job"]')
613 found_job_count = jobs_found.count
614 assert_equal num_jobs, found_job_count, 'Did not find expected number of jobs'
618 # Move button accessibility
621 ['active', true], # project owner
622 ['project_viewer', false],
623 ].each do |user, can_move|
624 test "#{user} can move subproject under another user's Home #{can_move}" do
625 project = api_fixture('groups')['aproject']
626 collection = api_fixture('collections')['collection_to_move_around_in_aproject']
628 # verify the project move button
629 visit page_with_token user, "/projects/#{project['uuid']}"
631 assert page.has_link? 'Move project...'
633 assert page.has_no_link? 'Move project...'