Merge branch 'master' into 3354-render-textile
[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   test "Flip persistent switch at /collections" do
17     Capybara.current_driver = Capybara.javascript_driver
18     uuid = api_fixture('collections')['foo_file']['uuid']
19     visit page_with_token('active', '/collections')
20     within "tr[data-object-uuid='#{uuid}']" do
21       change_persist 'cache', 'persistent'
22     end
23     # Refresh page and make sure the change was committed.
24     visit current_path
25     within "tr[data-object-uuid='#{uuid}']" do
26       change_persist 'persistent', 'cache'
27     end
28   end
29
30   test 'Flip persistent switch on collection#show' do
31     Capybara.current_driver = Capybara.javascript_driver
32     uuid = api_fixture('collections')['foo_file']['uuid']
33     visit page_with_token('active', "/collections/#{uuid}")
34     change_persist 'cache', 'persistent'
35     visit current_path
36     change_persist 'persistent', 'cache'
37   end
38
39   test "Collection page renders default name links" do
40     uuid = api_fixture('collections')['foo_file']['uuid']
41     coll_name = api_fixture('links')['foo_collection_name_in_aproject']['name']
42     name_uuid = api_fixture('links')['foo_collection_name_in_aproject']['uuid']
43     visit page_with_token('active', "/collections/#{name_uuid}")
44     assert(page.has_text?(coll_name), "Collection page did not include name")
45     # Now check that the page is otherwise normal, and the collection name
46     # isn't only showing up in an error message.
47     assert(page.has_link?('foo'), "Collection page did not include file link")
48   end
49
50   test "can download an entire collection with a reader token" do
51     uuid = api_fixture('collections')['foo_file']['uuid']
52     token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
53     url_head = "/collections/download/#{uuid}/#{token}/"
54     visit url_head
55     # It seems that Capybara can't inspect tags outside the body, so this is
56     # a very blunt approach.
57     assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
58                     "wget prohibited from recursing the collection page")
59     # TODO: When we can test against a Keep server, actually follow links
60     # and check their contents, rather than testing the href directly
61     # (this is too closely tied to implementation details).
62     hrefs = page.all('a').map do |anchor|
63       link = anchor[:href] || ''
64       if link.start_with? url_head
65         link[url_head.size .. -1]
66       elsif link.start_with? '/'
67         nil
68       else
69         link
70       end
71     end
72     assert_equal(['foo'], hrefs.compact.sort,
73                  "download page did provide strictly file links")
74   end
75
76   test "can view empty collection" do
77     uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
78     visit page_with_token('active', "/collections/#{uuid}")
79     assert page.has_text?('This collection is empty')
80   end
81 end