Merge branch '3877-log-memory-leak' closes #3877
[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   setup do
7     Capybara.current_driver = Capybara.javascript_driver
8   end
9
10   test "Collection page renders name" do
11     uuid = api_fixture('collections')['foo_file']['uuid']
12     coll_name = api_fixture('collections')['foo_file']['name']
13     visit page_with_token('active', "/collections/#{uuid}")
14     assert(page.has_text?(coll_name), "Collection page did not include name")
15     # Now check that the page is otherwise normal, and the collection name
16     # isn't only showing up in an error message.
17     assert(page.has_link?('foo'), "Collection page did not include file link")
18   end
19
20   test "can download an entire collection with a reader token" do
21     Capybara.current_driver = :rack_test
22
23     uuid = api_fixture('collections')['foo_file']['uuid']
24     token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
25     url_head = "/collections/download/#{uuid}/#{token}/"
26     visit url_head
27     # It seems that Capybara can't inspect tags outside the body, so this is
28     # a very blunt approach.
29     assert_no_match(/<\s*meta[^>]+\bnofollow\b/i, page.html,
30                     "wget prohibited from recursing the collection page")
31     # TODO: When we can test against a Keep server, actually follow links
32     # and check their contents, rather than testing the href directly
33     # (this is too closely tied to implementation details).
34     hrefs = page.all('a').map do |anchor|
35       link = anchor[:href] || ''
36       if link.start_with? url_head
37         link[url_head.size .. -1]
38       elsif link.start_with? '/'
39         nil
40       else
41         link
42       end
43     end
44     assert_equal(['foo'], hrefs.compact.sort,
45                  "download page did provide strictly file links")
46   end
47
48   test "can view empty collection" do
49     uuid = 'd41d8cd98f00b204e9800998ecf8427e+0'
50     visit page_with_token('active', "/collections/#{uuid}")
51     assert page.has_text?('This collection is empty')
52   end
53
54   test "combine selected collections into new collection" do
55     headless = Headless.new
56     headless.start
57     Capybara.current_driver = :selenium
58
59     foo_collection = api_fixture('collections')['foo_file']
60     bar_collection = api_fixture('collections')['bar_file']
61
62     visit page_with_token('active', "/collections")
63
64     assert(page.has_text?(foo_collection['uuid']), "Collection page did not include foo file")
65     assert(page.has_text?(bar_collection['uuid']), "Collection page did not include bar file")
66
67     within('tr', text: foo_collection['uuid']) do
68       find('input[type=checkbox]').click
69     end
70
71     within('tr', text: bar_collection['uuid']) do
72       find('input[type=checkbox]').click
73     end
74
75     click_button 'Selection...'
76     within('.selection-action-container') do
77       click_link 'Create new collection with selected collections'
78     end
79
80     # now in the newly created collection page
81     assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
82     assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
83     assert(page.has_text?('foo'), "Collection page did not include foo file")
84     assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
85     assert(page.has_text?('bar'), "Collection page did not include bar file")
86
87     headless.stop
88   end
89
90   test "combine selected collection files into new collection" do
91     headless = Headless.new
92     headless.start
93     Capybara.current_driver = :selenium
94
95     foo_collection = api_fixture('collections')['foo_file']
96
97     visit page_with_token('active', "/collections")
98
99     # choose file from foo collection
100     within('tr', text: foo_collection['uuid']) do
101       click_link 'Show'
102     end
103
104     # now in collection page
105     find('input[type=checkbox]').click
106
107     click_button 'Selection...'
108     within('.selection-action-container') do
109       click_link 'Create new collection with selected files'
110     end
111
112     # now in the newly created collection page
113     assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
114     assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
115     assert(page.has_text?('foo'), "Collection page did not include foo file")
116
117     headless.stop
118   end
119 end