1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class CollectionsTest < ActionDispatch::IntegrationTest
7 Capybara.current_driver = :rack_test
10 test "Can copy a collection to a project" do
11 Capybara.current_driver = Capybara.javascript_driver
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
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}"))
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")
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}/"
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? '/'
59 assert_equal(['foo'], hrefs.compact.sort,
60 "download page did provide strictly file links")
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')
69 test "combine selected collections into new collection" do
70 headless = Headless.new
72 Capybara.current_driver = :selenium
74 foo_collection = api_fixture('collections')['foo_file']
75 bar_collection = api_fixture('collections')['bar_file']
77 visit page_with_token('active', "/collections")
79 assert(page.has_text?(foo_collection['uuid']), "Collection page did not include foo file")
80 assert(page.has_text?(bar_collection['uuid']), "Collection page did not include bar file")
82 within('tr', text: foo_collection['uuid']) do
83 find('input[type=checkbox]').click
86 within('tr', text: bar_collection['uuid']) do
87 find('input[type=checkbox]').click
90 click_button 'Selection...'
91 within('.selection-action-container') do
92 click_link 'Create new collection with selected collections'
95 # now in the newly created collection page
96 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
97 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
98 assert(page.has_text?('foo'), "Collection page did not include foo file")
99 assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
100 assert(page.has_text?('bar'), "Collection page did not include bar file")
101 assert(page.has_text?('Created new collection in your Home project'),
102 'Not found flash message that new collection is created in Home project')
106 test "combine selected collection files into new collection" do
107 headless = Headless.new
109 Capybara.current_driver = :selenium
111 foo_collection = api_fixture('collections')['foo_file']
113 visit page_with_token('active', "/collections")
115 # choose file from foo collection
116 within('tr', text: foo_collection['uuid']) do
120 # now in collection page
121 find('input[type=checkbox]').click
123 click_button 'Selection...'
124 within('.selection-action-container') do
125 click_link 'Create new collection with selected files'
128 # now in the newly created collection page
129 assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
130 assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
131 assert(page.has_text?('foo'), "Collection page did not include foo file")
132 assert(page.has_text?('Created new collection in your Home project'),
133 'Not found flash message that new collection is created in Home project')