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