Merge branch 'master' into 3654-combine-selections
[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     foo_collection = api_fixture('collections')['foo_file']
56     bar_collection = api_fixture('collections')['bar_file']
57
58     visit page_with_token('active', "/collections")
59
60     assert(page.has_text?(foo_collection['uuid']), "Collection page did not include foo file")
61     assert(page.has_text?(bar_collection['uuid']), "Collection page did not include bar file")
62
63     within('tr', text: foo_collection['uuid']) do
64       find('input[type=checkbox]').click
65     end
66
67     within('tr', text: bar_collection['uuid']) do
68       find('input[type=checkbox]').click
69     end
70
71     click_button 'Selection...'
72     within('.selection-action-container') do
73       click_link 'Combine selections into a new collection'
74     end
75
76     # now in the newly created collection page
77     assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
78     assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
79     assert(page.has_text?('foo'), "Collection page did not include foo file")
80     assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
81     assert(page.has_text?('bar'), "Collection page did not include bar file")
82   end
83
84   test "combine selected collection contents into new collection" do
85     foo_collection = api_fixture('collections')['foo_file']
86
87     visit page_with_token('active', "/collections")
88
89     # choose file from foo collection
90     within('tr', text: foo_collection['uuid']) do
91       click_link 'Show'
92     end
93
94     # now in collection page
95     find('input[type=checkbox]').click
96
97     click_button 'Selection...'
98     within('.selection-action-container') do
99       click_link 'Combine selections into a new collection'
100     end
101
102     # now in the newly created collection page
103     assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
104     assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
105     assert(page.has_text?('foo'), "Collection page did not include foo file")
106   end
107 end