3661: Add a new test that ensures that the new "Copy to project" button works for...
[arvados.git] / apps / workbench / test / integration / collections_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class CollectionsTest < ActionDispatch::IntegrationTest
6   setup do
7     Capybara.current_driver = :rack_test
8   end
9
10   test "Can copy a collection to a project" do
11     Capybara.current_driver = Capybara.javascript_driver
12
13     collection_uuid = api_fixture('collections')['foo_file']['uuid']
14     collection_name = api_fixture('collections')['foo_file']['name']
15     project_uuid = api_fixture('groups')['aproject']['uuid']
16     project_name = api_fixture('groups')['aproject']['name']
17     visit page_with_token('active', "/collections/#{collection_uuid}")
18     click_link 'Copy to project...'
19     find('.selectable', text: project_name).click
20     find('.modal-footer a,button', text: 'Copy').click
21     wait_for_ajax
22     # It should navigate to the project after copying...
23     assert(page.has_text?(project_name))
24     assert(page.has_text?("Copy of #{collection_name}"))
25   end
26
27   test "Collection page renders name" do
28     uuid = api_fixture('collections')['foo_file']['uuid']
29     coll_name = api_fixture('collections')['foo_file']['name']
30     visit page_with_token('active', "/collections/#{uuid}")
31     assert(page.has_text?(coll_name), "Collection page did not include name")
32     # Now check that the page is otherwise normal, and the collection name
33     # isn't only showing up in an error message.
34     assert(page.has_link?('foo'), "Collection page did not include file link")
35   end
36
37   test "can download an entire collection with a reader token" do
38     uuid = api_fixture('collections')['foo_file']['uuid']
39     token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
40     url_head = "/collections/download/#{uuid}/#{token}/"
41     visit url_head
42     # It seems that Capybara can't inspect tags outside the body, so this is
43     # a very blunt approach.
44     assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
45                     "wget prohibited from recursing the collection page")
46     # TODO: When we can test against a Keep server, actually follow links
47     # and check their contents, rather than testing the href directly
48     # (this is too closely tied to implementation details).
49     hrefs = page.all('a').map do |anchor|
50       link = anchor[:href] || ''
51       if link.start_with? url_head
52         link[url_head.size .. -1]
53       elsif link.start_with? '/'
54         nil
55       else
56         link
57       end
58     end
59     assert_equal(['foo'], hrefs.compact.sort,
60                  "download page did provide strictly file links")
61   end
62
63   test "can view empty collection" do
64     uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
65     visit page_with_token('active', "/collections/#{uuid}")
66     assert page.has_text?('This collection is empty')
67   end
68 end