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