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