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 headless = Headless.new
57 Capybara.current_driver = :selenium
59 foo_collection = api_fixture('collections')['foo_file']
60 bar_collection = api_fixture('collections')['bar_file']
62 visit page_with_token('active', "/collections")
64 assert(page.has_text?(foo_collection['uuid']), "Collection page did not include foo file")
65 assert(page.has_text?(bar_collection['uuid']), "Collection page did not include bar file")
67 within('tr', text: foo_collection['uuid']) do
68 find('input[type=checkbox]').click
71 within('tr', text: bar_collection['uuid']) do
72 find('input[type=checkbox]').click
75 click_button 'Selection...'
76 within('.selection-action-container') do
77 click_link 'Create new collection with selected collections'
80 # now in the newly created collection page
81 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
82 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
83 assert(page.has_text?('foo'), "Collection page did not include foo file")
84 assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
85 assert(page.has_text?('bar'), "Collection page did not include bar file")
90 test "combine selected collection files into new collection" do
91 headless = Headless.new
93 Capybara.current_driver = :selenium
95 foo_collection = api_fixture('collections')['foo_file']
97 visit page_with_token('active', "/collections")
99 # choose file from foo collection
100 within('tr', text: foo_collection['uuid']) do
104 # now in collection page
105 find('input[type=checkbox]').click
107 click_button 'Selection...'
108 within('.selection-action-container') do
109 click_link 'Create new collection with selected files'
112 # now in the newly created collection page
113 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
114 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
115 assert(page.has_text?('foo'), "Collection page did not include foo file")