Merge branch 'master' into 6465-optimize-workbench-integration-tests
[arvados.git] / apps / workbench / test / integration / projects_test.rb
1 require 'integration_helper'
2 require 'helpers/share_object_helper'
3 require_relative 'integration_test_utils'
4
5 class ProjectsTest < ActionDispatch::IntegrationTest
6   include ShareObjectHelper
7
8   setup do
9     need_javascript
10   end
11
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     click_link 'Data collections'
16     wait_for_ajax
17     collection_count = page.all("[data-pk*='collection']").count
18     assert_selector '#Data_collections-tab span', text: "(#{collection_count})"
19   end
20
21   test 'Find a project and edit its description' do
22     visit page_with_token 'active', '/'
23     find("#projects-menu").click
24     find(".dropdown-menu a", text: "A Project").click
25     within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
26       find('span', text: api_fixture('groups')['aproject']['name']).click
27       within('.arv-description-as-subtitle') do
28         find('.fa-pencil').click
29         find('.editable-input textarea').set('I just edited this.')
30         find('.editable-submit').click
31       end
32       wait_for_ajax
33     end
34     visit current_path
35     assert(find?('.container-fluid', text: 'I just edited this.'),
36            "Description update did not survive page refresh")
37   end
38
39   test 'Add a new name, then edit it, without creating a duplicate' do
40     project_uuid = api_fixture('groups')['aproject']['uuid']
41     specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
42     visit page_with_token 'active', '/projects/' + project_uuid
43     click_link 'Other objects'
44     within '.selection-action-container' do
45       # Wait for the tab to load:
46       assert_selector 'tr[data-kind="arvados#trait"]'
47       within first('tr', text: 'Trait') do
48         find(".fa-pencil").click
49         find('.editable-input input').set('Now I have a name.')
50         find('.glyphicon-ok').click
51         assert_selector '.editable', text: 'Now I have a name.'
52         find(".fa-pencil").click
53         find('.editable-input input').set('Now I have a new name.')
54         find('.glyphicon-ok').click
55       end
56       wait_for_ajax
57       assert_selector '.editable', text: 'Now I have a new name.'
58     end
59     visit current_path
60     click_link 'Other objects'
61     within '.selection-action-container' do
62       find '.editable', text: 'Now I have a new name.'
63       assert_no_selector '.editable', text: 'Now I have a name.'
64     end
65   end
66
67   test 'Create a project and move it into a different project' do
68     visit page_with_token 'active', '/projects'
69     find("#projects-menu").click
70     find(".dropdown-menu a", text: "Home").click
71     find('.btn', text: "Add a subproject").click
72
73     within('h2') do
74       find('.fa-pencil').click
75       find('.editable-input input').set('Project 1234')
76       find('.glyphicon-ok').click
77     end
78     wait_for_ajax
79
80     visit '/projects'
81     find("#projects-menu").click
82     find(".dropdown-menu a", text: "Home").click
83     find('.btn', text: "Add a subproject").click
84     within('h2') do
85       find('.fa-pencil').click
86       find('.editable-input input').set('Project 5678')
87       find('.glyphicon-ok').click
88     end
89     wait_for_ajax
90
91     click_link 'Move project...'
92     find('.selectable', text: 'Project 1234').click
93     find('.modal-footer a,button', text: 'Move').click
94     wait_for_ajax
95
96     # Wait for the page to refresh and show the new parent in Sharing panel
97     click_link 'Sharing'
98     assert(page.has_link?("Project 1234"),
99            "Project 5678 should now be inside project 1234")
100   end
101
102   def open_groups_sharing(project_name="aproject", token_name="active")
103     project = api_fixture("groups", project_name)
104     visit(page_with_token(token_name, "/projects/#{project['uuid']}"))
105     click_on "Sharing"
106     click_on "Share with groups"
107   end
108
109   def group_name(group_key)
110     api_fixture("groups", group_key, "name")
111   end
112
113   test "projects not publicly sharable when anonymous browsing disabled" do
114     Rails.configuration.anonymous_user_token = false
115     open_groups_sharing
116     # Check for a group we do expect first, to make sure the modal's loaded.
117     assert_selector(".modal-container .selectable",
118                     text: group_name("all_users"))
119     assert_no_selector(".modal-container .selectable",
120                        text: group_name("anonymous_group"))
121   end
122
123   test "projects publicly sharable when anonymous browsing enabled" do
124     Rails.configuration.anonymous_user_token = "testonlytoken"
125     open_groups_sharing
126     assert_selector(".modal-container .selectable",
127                     text: group_name("anonymous_group"))
128   end
129
130   test "project owner can manage sharing for another user" do
131     add_user = api_fixture('users')['future_project_user']
132     new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
133
134     show_object_using('active', 'groups', 'aproject', 'A Project')
135     click_on "Sharing"
136     add_share_and_check("users", new_name, add_user)
137     modify_share_and_check(new_name)
138   end
139
140   test "project owner can manage sharing for another group" do
141     new_name = api_fixture('groups')['future_project_viewing_group']['name']
142
143     show_object_using('active', 'groups', 'aproject', 'A Project')
144     click_on "Sharing"
145     add_share_and_check("groups", new_name)
146     modify_share_and_check(new_name)
147   end
148
149   test "'share with group' listing does not offer projects" do
150     show_object_using('active', 'groups', 'aproject', 'A Project')
151     click_on "Sharing"
152     click_on "Share with groups"
153     good_uuid = api_fixture("groups")["private"]["uuid"]
154     assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
155            "'share with groups' listing missing owned user group")
156     bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
157     assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
158            "'share with groups' listing includes project")
159   end
160
161   [
162     ['Move',api_fixture('collections')['collection_to_move_around_in_aproject'],
163       api_fixture('groups')['aproject'],api_fixture('groups')['asubproject']],
164     ['Remove',api_fixture('collections')['collection_to_move_around_in_aproject'],
165       api_fixture('groups')['aproject']],
166     ['Copy',api_fixture('collections')['collection_to_move_around_in_aproject'],
167       api_fixture('groups')['aproject'],api_fixture('groups')['asubproject']],
168     ['Remove',api_fixture('collections')['collection_in_aproject_with_same_name_as_in_home_project'],
169       api_fixture('groups')['aproject'],nil,true],
170   ].each do |action, my_collection, src, dest=nil, expect_name_change=nil|
171     test "selection #{action} -> #{expect_name_change.inspect} for project" do
172       perform_selection_action src, dest, my_collection, action
173
174       case action
175       when 'Copy'
176         assert page.has_text?(my_collection['name']), 'Collection not found in src project after copy'
177         visit page_with_token 'active', '/'
178         find("#projects-menu").click
179         find(".dropdown-menu a", text: dest['name']).click
180         click_link 'Data collections'
181         assert page.has_text?(my_collection['name']), 'Collection not found in dest project after copy'
182
183       when 'Move'
184         assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after move'
185         visit page_with_token 'active', '/'
186         find("#projects-menu").click
187         find(".dropdown-menu a", text: dest['name']).click
188         click_link 'Data collections'
189         assert page.has_text?(my_collection['name']), 'Collection not found in dest project after move'
190
191       when 'Remove'
192         assert page.has_no_text?(my_collection['name']), 'Collection still found in src project after remove'
193       end
194     end
195   end
196
197   def perform_selection_action src, dest, item, action
198     visit page_with_token 'active', '/'
199     find("#projects-menu").click
200     find(".dropdown-menu a", text: src['name']).click
201     click_link 'Data collections'
202     assert page.has_text?(item['name']), 'Collection not found in src project'
203
204     within('tr', text: item['name']) do
205       find('input[type=checkbox]').click
206     end
207
208     click_button 'Selection'
209
210     within('.selection-action-container') do
211       assert page.has_text?("Compare selected"), "Compare selected link text not found"
212       assert page.has_link?("Copy selected"), "Copy selected link not found"
213       assert page.has_link?("Move selected"), "Move selected link not found"
214       assert page.has_link?("Remove selected"), "Remove selected link not found"
215
216       click_link "#{action} selected"
217     end
218
219     # select the destination project if a Copy or Move action is being performed
220     if action == 'Copy' || action == 'Move'
221       within(".modal-container") do
222         find('.selectable', text: dest['name']).click
223         find('.modal-footer a,button', text: action).click
224         wait_for_ajax
225       end
226     end
227   end
228
229   # Test copy action state. It should not be available when a subproject is selected.
230   test "copy action is disabled when a subproject is selected" do
231     my_project = api_fixture('groups')['aproject']
232     my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
233     my_subproject = api_fixture('groups')['asubproject']
234
235     # verify that selection options are disabled on the project until an item is selected
236     visit page_with_token 'active', '/'
237     find("#projects-menu").click
238     find(".dropdown-menu a", text: my_project['name']).click
239
240     click_link 'Data collections'
241     click_button 'Selection'
242     within('.selection-action-container') do
243       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
244       assert_selector 'li.disabled', text: 'Compare selected'
245       assert_selector 'li.disabled', text: 'Copy selected'
246       assert_selector 'li.disabled', text: 'Move selected'
247       assert_selector 'li.disabled', text: 'Remove selected'
248     end
249
250     # select collection and verify links are enabled
251     visit page_with_token 'active', '/'
252     find("#projects-menu").click
253     find(".dropdown-menu a", text: my_project['name']).click
254     click_link 'Data collections'
255     assert page.has_text?(my_collection['name']), 'Collection not found in project'
256
257     within('tr', text: my_collection['name']) do
258       find('input[type=checkbox]').click
259     end
260
261     click_button 'Selection'
262     within('.selection-action-container') do
263       assert_no_selector 'li.disabled', text: 'Create new collection with selected collections'
264       assert_selector 'li', text: 'Create new collection with selected collections'
265       assert_selector 'li.disabled', text: 'Compare selected'
266       assert_no_selector 'li.disabled', text: 'Copy selected'
267       assert_selector 'li', text: 'Copy selected'
268       assert_no_selector 'li.disabled', text: 'Move selected'
269       assert_selector 'li', text: 'Move selected'
270       assert_no_selector 'li.disabled', text: 'Remove selected'
271       assert_selector 'li', text: 'Remove selected'
272     end
273
274     # select subproject and verify that copy action is disabled
275     visit page_with_token 'active', '/'
276     find("#projects-menu").click
277     find(".dropdown-menu a", text: my_project['name']).click
278
279     click_link 'Subprojects'
280     assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
281
282     within('tr', text: my_subproject['name']) do
283       find('input[type=checkbox]').click
284     end
285
286     click_button 'Selection'
287     within('.selection-action-container') do
288       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
289       assert_selector 'li.disabled', text: 'Compare selected'
290       assert_selector 'li.disabled', text: 'Copy selected'
291       assert_no_selector 'li.disabled', text: 'Move selected'
292       assert_selector 'li', text: 'Move selected'
293       assert_no_selector 'li.disabled', text: 'Remove selected'
294       assert_selector 'li', text: 'Remove selected'
295     end
296
297     # select subproject and a collection and verify that copy action is still disabled
298     visit page_with_token 'active', '/'
299     find("#projects-menu").click
300     find(".dropdown-menu a", text: my_project['name']).click
301
302     click_link 'Subprojects'
303     assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
304
305     within('tr', text: my_subproject['name']) do
306       find('input[type=checkbox]').click
307     end
308
309     click_link 'Data collections'
310     assert page.has_text?(my_collection['name']), 'Collection not found in project'
311
312     within('tr', text: my_collection['name']) do
313       find('input[type=checkbox]').click
314     end
315
316     click_link 'Subprojects'
317     click_button 'Selection'
318     within('.selection-action-container') do
319       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
320       assert_selector 'li.disabled', text: 'Compare selected'
321       assert_selector 'li.disabled', text: 'Copy selected'
322       assert_no_selector 'li.disabled', text: 'Move selected'
323       assert_selector 'li', text: 'Move selected'
324       assert_no_selector 'li.disabled', text: 'Remove selected'
325       assert_selector 'li', text: 'Remove selected'
326     end
327   end
328
329   # When project tabs are switched, only options applicable to the current tab's selections are enabled.
330   test "verify selection options when tabs are switched" do
331     my_project = api_fixture('groups')['aproject']
332     my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
333     my_subproject = api_fixture('groups')['asubproject']
334
335     # select subproject and a collection and verify that copy action is still disabled
336     visit page_with_token 'active', '/'
337     find("#projects-menu").click
338     find(".dropdown-menu a", text: my_project['name']).click
339
340     # Select a sub-project
341     click_link 'Subprojects'
342     assert page.has_text?(my_subproject['name']), 'Subproject not found in project'
343
344     within('tr', text: my_subproject['name']) do
345       find('input[type=checkbox]').click
346     end
347
348     # Select a collection
349     click_link 'Data collections'
350     assert page.has_text?(my_collection['name']), 'Collection not found in project'
351
352     within('tr', text: my_collection['name']) do
353       find('input[type=checkbox]').click
354     end
355
356     # Go back to Subprojects tab
357     click_link 'Subprojects'
358     click_button 'Selection'
359     within('.selection-action-container') do
360       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
361       assert_selector 'li.disabled', text: 'Compare selected'
362       assert_selector 'li.disabled', text: 'Copy selected'
363       assert_no_selector 'li.disabled', text: 'Move selected'
364       assert_selector 'li', text: 'Move selected'
365       assert_no_selector 'li.disabled', text: 'Remove selected'
366       assert_selector 'li', text: 'Remove selected'
367     end
368
369     # Close the dropdown by clicking outside it.
370     find('.dropdown-toggle', text: 'Selection').find(:xpath, '..').click
371
372     # Go back to Data collections tab
373     find('.nav-tabs a', text: 'Data collections').click
374     click_button 'Selection'
375     within('.selection-action-container') do
376       assert_no_selector 'li.disabled', text: 'Create new collection with selected collections'
377       assert_selector 'li', text: 'Create new collection with selected collections'
378       assert_selector 'li.disabled', text: 'Compare selected'
379       assert_no_selector 'li.disabled', text: 'Copy selected'
380       assert_selector 'li', text: 'Copy selected'
381       assert_no_selector 'li.disabled', text: 'Move selected'
382       assert_selector 'li', text: 'Move selected'
383       assert_no_selector 'li.disabled', text: 'Remove selected'
384       assert_selector 'li', text: 'Remove selected'
385     end
386   end
387
388   # "Move selected" and "Remove selected" options should not be
389   # available when current user cannot write to the project
390   test "move selected and remove selected actions not available when current user cannot write to project" do
391     my_project = api_fixture('groups')['anonymously_accessible_project']
392     visit page_with_token 'active', "/projects/#{my_project['uuid']}"
393
394     click_link 'Data collections'
395     click_button 'Selection'
396     within('.selection-action-container') do
397       assert_selector 'li', text: 'Create new collection with selected collections'
398       assert_selector 'li', text: 'Compare selected'
399       assert_selector 'li', text: 'Copy selected'
400       assert_no_selector 'li', text: 'Move selected'
401       assert_no_selector 'li', text: 'Remove selected'
402     end
403   end
404
405   [
406     ['active', true],
407     ['project_viewer', false],
408   ].each do |user, expect_collection_in_aproject|
409     test "combine selected collections into new collection #{user} #{expect_collection_in_aproject}" do
410       my_project = api_fixture('groups')['aproject']
411       my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
412
413       visit page_with_token user, '/'
414       find("#projects-menu").click
415       find(".dropdown-menu a", text: my_project['name']).click
416       click_link 'Data collections'
417       assert page.has_text?(my_collection['name']), 'Collection not found in project'
418
419       within('tr', text: my_collection['name']) do
420         find('input[type=checkbox]').click
421       end
422
423       click_button 'Selection'
424       within('.selection-action-container') do
425         click_link 'Create new collection with selected collections'
426       end
427
428       # now in the new collection page
429       if expect_collection_in_aproject
430         assert page.has_text?("Created new collection in the project #{my_project['name']}"),
431                               'Not found flash message that new collection is created in aproject'
432       else
433         assert page.has_text?("Created new collection in your Home project"),
434                               'Not found flash message that new collection is created in Home project'
435       end
436     end
437   end
438
439   [
440     ["jobs", "/jobs"],
441     ["pipelines", "/pipeline_instances"],
442     ["collections", "/collections"]
443   ].each do |target,path|
444     test "Test dashboard button all #{target}" do
445       visit page_with_token 'active', '/'
446       click_link "All #{target}"
447       assert_equal path, current_path
448     end
449   end
450
451   def scroll_setup(project_name,
452                    total_nbr_items,
453                    item_list_parameter,
454                    sorted = false,
455                    sort_parameters = nil)
456     project_uuid = api_fixture('groups')[project_name]['uuid']
457     visit page_with_token 'user1_with_load', '/projects/' + project_uuid
458
459     assert(page.has_text?("#{item_list_parameter.humanize} (#{total_nbr_items})"), "Number of #{item_list_parameter.humanize} did not match the input amount")
460
461     click_link item_list_parameter.humanize
462     wait_for_ajax
463
464     if sorted
465       find("th[data-sort-order='#{sort_parameters.gsub(/\s/,'')}']").click
466       wait_for_ajax
467     end
468   end
469
470   def scroll_items_check(nbr_items,
471                          fixture_prefix,
472                          item_list_parameter,
473                          item_selector,
474                          sorted = false)
475     items = []
476     for i in 1..nbr_items
477       items << "#{fixture_prefix}#{i}"
478     end
479
480     verify_items = items.dup
481     unexpected_items = []
482     item_count = 0
483     within(".arv-project-#{item_list_parameter}") do
484       page.execute_script "window.scrollBy(0,999000)"
485       begin
486         wait_for_ajax
487       rescue
488       end
489
490       # Visit all rows. If not all expected items are found, retry
491       found_items = page.all(item_selector)
492       item_count = found_items.count
493
494       previous = nil
495       (0..item_count-1).each do |i|
496         # Found row text using the fixture string e.g. "Show Collection_#{n} "
497         item_name = found_items[i].text.split[1]
498         if !items.include? item_name
499           unexpected_items << item_name
500         else
501           verify_items.delete item_name
502         end
503         if sorted
504           # check sort order
505           assert_operator( previous.downcase, :<=, item_name.downcase) if previous
506           previous = item_name
507         end
508       end
509
510       assert_equal true, unexpected_items.empty?, "Found unexpected #{item_list_parameter.humanize} #{unexpected_items.inspect}"
511       assert_equal nbr_items, item_count, "Found different number of #{item_list_parameter.humanize}"
512       assert_equal true, verify_items.empty?, "Did not find all the #{item_list_parameter.humanize}"
513     end
514   end
515
516   [
517     ['project_with_10_collections', 10],
518     ['project_with_201_collections', 201], # two pages of data
519   ].each do |project_name, nbr_items|
520     test "scroll collections tab for #{project_name} with #{nbr_items} objects" do
521       item_list_parameter = "Data_collections"
522       scroll_setup project_name,
523                    nbr_items,
524                    item_list_parameter
525       scroll_items_check nbr_items,
526                          "Collection_",
527                          item_list_parameter,
528                          'tr[data-kind="arvados#collection"]'
529     end
530   end
531
532   [
533     ['project_with_10_collections', 10],
534     ['project_with_201_collections', 201], # two pages of data
535   ].each do |project_name, nbr_items|
536     test "scroll collections tab for #{project_name} with #{nbr_items} objects with ascending sort (case insensitive)" do
537       item_list_parameter = "Data_collections"
538       scroll_setup project_name,
539                    nbr_items,
540                    item_list_parameter,
541                    true,
542                    "collections.name"
543       scroll_items_check nbr_items,
544                          "Collection_",
545                          item_list_parameter,
546                          'tr[data-kind="arvados#collection"]',
547                          true
548     end
549   end
550
551   [
552     ['project_with_10_pipelines', 10, 0],
553     ['project_with_2_pipelines_and_60_jobs', 2, 60],
554     ['project_with_25_pipelines', 25, 0],
555   ].each do |project_name, num_pipelines, num_jobs|
556     test "scroll pipeline instances tab for #{project_name} with #{num_pipelines} pipelines and #{num_jobs} jobs" do
557       item_list_parameter = "Jobs_and_pipelines"
558       scroll_setup project_name,
559                    num_pipelines + num_jobs,
560                    item_list_parameter
561       # check the general scrolling and the pipelines
562       scroll_items_check num_pipelines,
563                          "pipeline_",
564                          item_list_parameter,
565                          'tr[data-kind="arvados#pipelineInstance"]'
566       # Check job count separately
567       jobs_found = page.all('tr[data-kind="arvados#job"]')
568       found_job_count = jobs_found.count
569       assert_equal num_jobs, found_job_count, 'Did not find expected number of jobs'
570     end
571   end
572
573   # Move button accessibility
574   [
575     ['admin', true],
576     ['active', true],  # project owner
577     ['project_viewer', false],
578     ].each do |user, can_move|
579     test "#{user} can move subproject under another user's Home #{can_move}" do
580       project = api_fixture('groups')['aproject']
581       collection = api_fixture('collections')['collection_to_move_around_in_aproject']
582
583       # verify the project move button
584       visit page_with_token user, "/projects/#{project['uuid']}"
585       if can_move
586         assert page.has_link? 'Move project...'
587       else
588         assert page.has_no_link? 'Move project...'
589       end
590     end
591   end
592
593   test "error while loading tab" do
594     original_arvados_v1_base = Rails.configuration.arvados_v1_base
595
596     visit page_with_token 'active', '/projects/' + api_fixture('groups')['aproject']['uuid']
597
598     # Point to a bad api server url to generate error
599     Rails.configuration.arvados_v1_base = "https://[::1]:1/"
600     click_link 'Other objects'
601     within '#Other_objects' do
602       # Error
603       assert_selector('a', text: 'Reload tab')
604
605       # Now point back to the orig api server and reload tab
606       Rails.configuration.arvados_v1_base = original_arvados_v1_base
607       click_link 'Reload tab'
608       assert_no_selector('a', text: 'Reload tab')
609       assert_selector('button', text: 'Selection')
610       within '.selection-action-container' do
611         assert_selector 'tr[data-kind="arvados#trait"]'
612       end
613     end
614   end
615
616   test "add new project using projects dropdown" do
617     # verify that selection options are disabled on the project until an item is selected
618     visit page_with_token 'active', '/'
619
620     # Add a new project
621     find("#projects-menu").click
622     click_link 'Add a new project'
623     assert_text 'New project'
624     assert_text 'No description provided'
625
626     # Add one more new project
627     find("#projects-menu").click
628     click_link 'Add a new project'
629     match = /New project \(\d\)/.match page.text
630     assert match, 'Expected project name not found'
631     assert_text 'No description provided'
632   end
633
634   test "first tab loads data when visiting other tab directly" do
635     # As of 2014-12-19, the first tab of project#show uses infinite scrolling.
636     # Make sure that it loads data even if we visit another tab directly.
637     need_selenium 'to land on specified tab using {url}#Advanced'
638     user = api_fixture("users", "active")
639     visit(page_with_token("active_trustedclient",
640                           "/projects/#{user['uuid']}#Advanced"))
641     assert_text("API response")
642     find("#page-wrapper .nav-tabs :first-child a").click
643     assert_text("Collection modified at")
644   end
645
646   # "Select all" and "Unselect all" options
647   test "select all and unselect all actions" do
648     need_selenium 'to check and uncheck checkboxes'
649
650     visit page_with_token 'active', '/projects/' + api_fixture('groups')['aproject']['uuid']
651
652     # Go to "Data collections" tab and click on "Select all"
653     click_link 'Data collections'
654     wait_for_ajax
655
656     # Initially, all selection options for this tab should be disabled
657     click_button 'Selection'
658     within('.selection-action-container') do
659       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
660       assert_selector 'li.disabled', text: 'Copy selected'
661     end
662
663     # Select all
664     click_button 'Select all'
665
666     assert_checkboxes_state('input[type=checkbox]', true, '"select all" should check all checkboxes')
667
668     # Now the selection options should be enabled
669     click_button 'Selection'
670     within('.selection-action-container') do
671       assert_selector 'li', text: 'Create new collection with selected collections'
672       assert_no_selector 'li.disabled', text: 'Copy selected'
673       assert_selector 'li', text: 'Create new collection with selected collections'
674       assert_no_selector 'li.disabled', text: 'Copy selected'
675     end
676
677     # Go to Jobs and pipelines tab and assert none selected
678     click_link 'Jobs and pipelines'
679     wait_for_ajax
680
681     # Since this is the first visit to this tab, all selection options should be disabled
682     click_button 'Selection'
683     within('.selection-action-container') do
684       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
685       assert_selector 'li.disabled', text: 'Copy selected'
686     end
687
688     assert_checkboxes_state('input[type=checkbox]', false, '"select all" should check all checkboxes')
689
690     # Select all
691     click_button 'Select all'
692     assert_checkboxes_state('input[type=checkbox]', true, '"select all" should check all checkboxes')
693
694     # Applicable selection options should be enabled
695     click_button 'Selection'
696     within('.selection-action-container') do
697       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
698       assert_selector 'li', text: 'Copy selected'
699       assert_no_selector 'li.disabled', text: 'Copy selected'
700     end
701
702     # Unselect all
703     click_button 'Unselect all'
704     assert_checkboxes_state('input[type=checkbox]', false, '"select all" should check all checkboxes')
705
706     # All selection options should be disabled again
707     click_button 'Selection'
708     within('.selection-action-container') do
709       assert_selector 'li.disabled', text: 'Create new collection with selected collections'
710       assert_selector 'li.disabled', text: 'Copy selected'
711     end
712
713     # Go back to Data collections tab and verify all are still selected
714     click_link 'Data collections'
715     wait_for_ajax
716
717     # Selection options should be enabled based on the fact that all collections are still selected in this tab
718     click_button 'Selection'
719     within('.selection-action-container') do
720       assert_selector 'li', text: 'Create new collection with selected collections'
721       assert_no_selector 'li.disabled', text: 'Copy selected'
722       assert_selector 'li', text: 'Create new collection with selected collections'
723       assert_no_selector 'li.disabled', text: 'Copy selected'
724     end
725
726     assert_checkboxes_state('input[type=checkbox]', true, '"select all" should check all checkboxes')
727
728     # Unselect all
729     find('button#unselect-all').click
730     assert_checkboxes_state('input[type=checkbox]', false, '"unselect all" should clear all checkboxes')
731
732     # Now all selection options should be disabled because none of the collections are checked
733     click_button 'Selection'
734     within('.selection-action-container') do
735       assert_selector 'li.disabled', text: 'Copy selected'
736       assert_selector 'li.disabled', text: 'Copy selected'
737     end
738
739     # Verify checking just one checkbox still works as expected
740     within('tr', text: api_fixture('collections')['collection_to_move_around_in_aproject']['name']) do
741       find('input[type=checkbox]').click
742     end
743
744     click_button 'Selection'
745     within('.selection-action-container') do
746       assert_selector 'li', text: 'Create new collection with selected collections'
747       assert_no_selector 'li.disabled', text: 'Copy selected'
748       assert_selector 'li', text: 'Create new collection with selected collections'
749       assert_no_selector 'li.disabled', text: 'Copy selected'
750     end
751   end
752 end