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