1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class CollectionsTest < ActionDispatch::IntegrationTest
6 def change_persist oldstate, newstate
7 find "div[data-persistent-state='#{oldstate}']"
8 page.assert_no_selector "div[data-persistent-state='#{newstate}']"
9 find('.btn', text: oldstate.capitalize).click
10 find '.btn', text: newstate.capitalize
11 page.assert_no_selector '.btn', text: oldstate.capitalize
12 find "div[data-persistent-state='#{newstate}']"
13 page.assert_no_selector "div[data-persistent-state='#{oldstate}']"
16 ['/collections', '/users/welcome'].each do |path|
17 test "Flip persistent switch at #{path}" do
18 Capybara.current_driver = Capybara.javascript_driver
19 uuid = api_fixture('collections')['foo_file']['uuid']
20 visit page_with_token('active', path)
21 within "tr[data-object-uuid='#{uuid}']" do
22 change_persist 'cache', 'persistent'
24 # Refresh page and make sure the change was committed.
26 within "tr[data-object-uuid='#{uuid}']" do
27 change_persist 'persistent', 'cache'
32 test 'Flip persistent switch on collection#show' do
33 Capybara.current_driver = Capybara.javascript_driver
34 uuid = api_fixture('collections')['foo_file']['uuid']
35 visit page_with_token('active', "/collections/#{uuid}")
36 change_persist 'cache', 'persistent'
38 change_persist 'persistent', 'cache'
41 test "Collection page renders default name links" do
42 uuid = api_fixture('collections')['foo_file']['uuid']
43 coll_name = api_fixture('links')['foo_collection_name_in_aproject']['name']
44 name_uuid = api_fixture('links')['foo_collection_name_in_aproject']['uuid']
45 visit page_with_token('active', "/collections/#{name_uuid}")
46 assert(page.has_text?(coll_name), "Collection page did not include name")
47 # Now check that the page is otherwise normal, and the collection name
48 # isn't only showing up in an error message.
49 assert(page.has_link?('foo'), "Collection page did not include file link")
52 test "can download an entire collection with a reader token" do
53 uuid = api_fixture('collections')['foo_file']['uuid']
54 token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
55 url_head = "/collections/download/#{uuid}/#{token}/"
57 # It seems that Capybara can't inspect tags outside the body, so this is
58 # a very blunt approach.
59 assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
60 "wget prohibited from recursing the collection page")
61 # TODO: When we can test against a Keep server, actually follow links
62 # and check their contents, rather than testing the href directly
63 # (this is too closely tied to implementation details).
64 hrefs = page.all('a').map do |anchor|
65 link = anchor[:href] || ''
66 if link.start_with? url_head
67 link[url_head.size .. -1]
68 elsif link.start_with? '/'
74 assert_equal(['foo'], hrefs.compact.sort,
75 "download page did provide strictly file links")
78 test "can view empty collection" do
79 uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
80 visit page_with_token('active', "/collections/#{uuid}")
81 assert page.has_text?('This collection is empty')