Merge branch '2798-go-keep-client' into 1885-keep-proxy
[arvados.git] / apps / workbench / test / integration / collections_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
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}']"
14   end
15
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'
23       end
24       # Refresh page and make sure the change was committed.
25       visit current_path
26       within "tr[data-object-uuid='#{uuid}']" do
27         change_persist 'persistent', 'cache'
28       end
29     end
30   end
31
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'
37     visit current_path
38     change_persist 'persistent', 'cache'
39   end
40
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")
49   end
50
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}/"
55     visit url_head
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? '/'
68         nil
69       else
70         link
71       end
72     end
73     assert_equal(['foo'], hrefs.compact.sort,
74                  "download page did provide strictly file links")
75   end
76 end