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