Merge branch 'master' into 2934-limit-crunch-logs
[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', '/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'
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_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")
50   end
51
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}/"
56     visit url_head
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? '/'
69         nil
70       else
71         link
72       end
73     end
74     assert_equal(['foo'], hrefs.compact.sort,
75                  "download page did provide strictly file links")
76   end
77 end