+ # Close the dropdown by clicking outside it.
+ find('.dropdown-toggle', text: 'Selection').find(:xpath, '..').click
+
+ # Go back to Data collections tab
+ find('.nav-tabs a', text: 'Data collections').click
+ click_button 'Selection'
+ within('.selection-action-container') do
+ assert_no_selector 'li.disabled', text: 'Create new collection with selected collections'
+ assert_selector 'li', text: 'Create new collection with selected collections'
+ assert_selector 'li.disabled', text: 'Compare selected'
+ assert_no_selector 'li.disabled', text: 'Copy selected'
+ assert_selector 'li', text: 'Copy selected'
+ assert_no_selector 'li.disabled', text: 'Move selected'
+ assert_selector 'li', text: 'Move selected'
+ assert_no_selector 'li.disabled', text: 'Remove selected'
+ assert_selector 'li', text: 'Remove selected'
+ end
+ end
+
+ # "Move selected" and "Remove selected" options should not be available when current user cannot write to the project
+ test "move selected and remove selected actions not available when current user cannot write to project" do
+ my_project = api_fixture('groups')['anonymously_accessible_project']
+ visit page_with_token 'active', "/projects/#{my_project['uuid']}"
+
+ click_button 'Selection'
+ within('.selection-action-container') do
+ assert_selector 'li', text: 'Create new collection with selected collections'
+ assert_selector 'li', text: 'Compare selected'
+ assert_selector 'li', text: 'Copy selected'
+ assert_no_selector 'li', text: 'Move selected'
+ assert_no_selector 'li', text: 'Remove selected'
+ end
+ end
+
+ [
+ ['active', true],
+ ['project_viewer', false],
+ ].each do |user, expect_collection_in_aproject|
+ test "combine selected collections into new collection #{user} #{expect_collection_in_aproject}" do
+ my_project = api_fixture('groups')['aproject']
+ my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
+
+ visit page_with_token user, '/'
+ find("#projects-menu").click
+ find(".dropdown-menu a", text: my_project['name']).click
+ assert page.has_text?(my_collection['name']), 'Collection not found in project'
+
+ within('tr', text: my_collection['name']) do
+ find('input[type=checkbox]').click
+ end
+
+ click_button 'Selection'
+ within('.selection-action-container') do
+ click_link 'Create new collection with selected collections'
+ end
+
+ # now in the new collection page
+ if expect_collection_in_aproject
+ assert page.has_text?("Created new collection in the project #{my_project['name']}"),
+ 'Not found flash message that new collection is created in aproject'
+ else
+ assert page.has_text?("Created new collection in your Home project"),
+ 'Not found flash message that new collection is created in Home project'
+ end
+ assert page.has_text?('Content hash'), 'Not found content hash in collection page'
+ end
+ end
+
+ [
+ ["jobs", "/jobs"],
+ ["pipelines", "/pipeline_instances"],
+ ["collections", "/collections"]
+ ].each do |target,path|
+ test "Test dashboard button all #{target}" do
+ visit page_with_token 'active', '/'
+ click_link "All #{target}"
+ assert_equal path, current_path
+ end
+ end
+
+ def scroll_setup(project_name,
+ total_nbr_items,
+ item_list_parameter,
+ sorted = false,
+ sort_parameters = nil)
+ project_uuid = api_fixture('groups')[project_name]['uuid']
+ visit page_with_token 'user1_with_load', '/projects/' + project_uuid
+
+ assert(page.has_text?("#{item_list_parameter.humanize} (#{total_nbr_items})"), "Number of #{item_list_parameter.humanize} did not match the input amount")
+
+ click_link item_list_parameter.humanize
+ wait_for_ajax
+
+ if sorted
+ find("th[data-sort-order='#{sort_parameters.gsub(/\s/,'')}']").click
+ wait_for_ajax
+ end
+ end
+
+ def scroll_items_check(nbr_items,
+ fixture_prefix,
+ item_list_parameter,
+ item_selector,
+ sorted = false)
+ items = []
+ for i in 1..nbr_items
+ items << "#{fixture_prefix}#{i}"
+ end
+
+ verify_items = items.dup
+ unexpected_items = []
+ item_count = 0
+ within(".arv-project-#{item_list_parameter}") do
+ page.execute_script "window.scrollBy(0,999000)"
+ begin
+ wait_for_ajax
+ rescue
+ end
+
+ # Visit all rows. If not all expected items are found, retry
+ found_items = page.all(item_selector)
+ item_count = found_items.count
+
+ previous = nil
+ (0..item_count-1).each do |i|
+ # Found row text using the fixture string e.g. "Show Collection_#{n} "
+ item_name = found_items[i].text.split[1]
+ if !items.include? item_name
+ unexpected_items << item_name
+ else
+ verify_items.delete item_name
+ end
+ if sorted
+ # check sort order
+ assert_operator( previous.downcase, :<=, item_name.downcase) if previous
+ previous = item_name
+ end
+ end
+
+ assert_equal true, unexpected_items.empty?, "Found unexpected #{item_list_parameter.humanize} #{unexpected_items.inspect}"
+ assert_equal nbr_items, item_count, "Found different number of #{item_list_parameter.humanize}"
+ assert_equal true, verify_items.empty?, "Did not find all the #{item_list_parameter.humanize}"
+ end
+ end
+
+ [
+ ['project_with_10_collections', 10],
+ ['project_with_201_collections', 201], # two pages of data
+ ].each do |project_name, nbr_items|
+ test "scroll collections tab for #{project_name} with #{nbr_items} objects" do
+ item_list_parameter = "Data_collections"
+ scroll_setup project_name,
+ nbr_items,
+ item_list_parameter
+ scroll_items_check nbr_items,
+ "Collection_",
+ item_list_parameter,
+ 'tr[data-kind="arvados#collection"]'
+ end