1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class CollectionsTest < ActionDispatch::IntegrationTest
7 Capybara.current_driver = Capybara.javascript_driver
10 test "Collection page renders name" do
11 uuid = api_fixture('collections')['foo_file']['uuid']
12 coll_name = api_fixture('collections')['foo_file']['name']
13 visit page_with_token('active', "/collections/#{uuid}")
14 assert(page.has_text?(coll_name), "Collection page did not include name")
15 # Now check that the page is otherwise normal, and the collection name
16 # isn't only showing up in an error message.
17 assert(page.has_link?('foo'), "Collection page did not include file link")
20 test "can download an entire collection with a reader token" do
21 Capybara.current_driver = :rack_test
23 uuid = api_fixture('collections')['foo_file']['uuid']
24 token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
25 url_head = "/collections/download/#{uuid}/#{token}/"
27 # It seems that Capybara can't inspect tags outside the body, so this is
28 # a very blunt approach.
29 assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
30 "wget prohibited from recursing the collection page")
31 # TODO: When we can test against a Keep server, actually follow links
32 # and check their contents, rather than testing the href directly
33 # (this is too closely tied to implementation details).
34 hrefs = page.all('a').map do |anchor|
35 link = anchor[:href] || ''
36 if link.start_with? url_head
37 link[url_head.size .. -1]
38 elsif link.start_with? '/'
44 assert_equal(['foo'], hrefs.compact.sort,
45 "download page did provide strictly file links")
48 test "can view empty collection" do
49 uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
50 visit page_with_token('active', "/collections/#{uuid}")
51 assert page.has_text?('This collection is empty')
54 test "combine selected collections into new collection" do
55 foo_collection = api_fixture('collections')['foo_file']
56 bar_collection = api_fixture('collections')['bar_file']
58 visit page_with_token('active', "/collections")
60 assert(page.has_text?(foo_collection['uuid']), "Collection page did not include foo file")
61 assert(page.has_text?(bar_collection['uuid']), "Collection page did not include bar file")
63 within('tr', text: foo_collection['uuid']) do
64 find('input[type=checkbox]').click
67 within('tr', text: bar_collection['uuid']) do
68 find('input[type=checkbox]').click
71 click_button 'Selection...'
72 within('.selection-action-container') do
73 click_link 'Combine selections into a new collection'
76 # now in the newly created collection page
77 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
78 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
79 assert(page.has_text?('foo'), "Collection page did not include foo file")
80 assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
81 assert(page.has_text?('bar'), "Collection page did not include bar file")
84 test "combine selected collection contents into new collection" do
85 foo_collection = api_fixture('collections')['foo_file']
87 visit page_with_token('active', "/collections")
89 # choose file from foo collection
90 within('tr', text: foo_collection['uuid']) do
94 # now in collection page
95 find('input[type=checkbox]').click
97 click_button 'Selection...'
98 within('.selection-action-container') do
99 click_link 'Combine selections into a new collection'
102 # now in the newly created collection page
103 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
104 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
105 assert(page.has_text?('foo'), "Collection page did not include foo file")