Merge branch '3627-selectable-projects' closes #3627
[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   test "Collection page renders name" do
7     uuid = api_fixture('collections')['foo_file']['uuid']
8     coll_name = api_fixture('collections')['foo_file']['name']
9     visit page_with_token('active', "/collections/#{uuid}")
10     assert(page.has_text?(coll_name), "Collection page did not include name")
11     # Now check that the page is otherwise normal, and the collection name
12     # isn't only showing up in an error message.
13     assert(page.has_link?('foo'), "Collection page did not include file link")
14   end
15
16   test "can download an entire collection with a reader token" do
17     Capybara.current_driver = :rack_test
18
19     uuid = api_fixture('collections')['foo_file']['uuid']
20     token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
21     url_head = "/collections/download/#{uuid}/#{token}/"
22     visit url_head
23     # It seems that Capybara can't inspect tags outside the body, so this is
24     # a very blunt approach.
25     assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
26                     "wget prohibited from recursing the collection page")
27     # TODO: When we can test against a Keep server, actually follow links
28     # and check their contents, rather than testing the href directly
29     # (this is too closely tied to implementation details).
30     hrefs = page.all('a').map do |anchor|
31       link = anchor[:href] || ''
32       if link.start_with? url_head
33         link[url_head.size .. -1]
34       elsif link.start_with? '/'
35         nil
36       else
37         link
38       end
39     end
40     assert_equal(['foo'], hrefs.compact.sort,
41                  "download page did provide strictly file links")
42   end
43
44   test "can view empty collection" do
45     uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
46     visit page_with_token('active', "/collections/#{uuid}")
47     assert page.has_text?('This collection is empty')
48   end
49 end