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', '/'].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_afolder']['name']
44 visit page_with_token('active', "/collections/#{uuid}")
45 assert(page.has_text?(coll_name), "Collection page did not include name")
46 # Now check that the page is otherwise normal, and the collection name
47 # isn't only showing up in an error message.
48 assert(page.has_link?('foo'), "Collection page did not include file link")
51 test "can download an entire collection with a reader token" do
52 uuid = api_fixture('collections')['foo_file']['uuid']
53 token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
54 url_head = "/collections/download/#{uuid}/#{token}/"
56 # It seems that Capybara can't inspect tags outside the body, so this is
57 # a very blunt approach.
58 assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
59 "wget prohibited from recursing the collection page")
60 # TODO: When we can test against a Keep server, actually follow links
61 # and check their contents, rather than testing the href directly
62 # (this is too closely tied to implementation details).
63 hrefs = page.all('a').map do |anchor|
64 link = anchor[:href] || ''
65 if link.start_with? url_head
66 link[url_head.size .. -1]
67 elsif link.start_with? '/'
73 assert_equal(['foo'], hrefs.compact.sort,
74 "download page did provide strictly file links")