Merge branch 'master' into 4523-search-index
[arvados.git] / apps / workbench / test / integration / collection_upload_test.rb
1 require 'integration_helper'
2
3 class CollectionUploadTest < ActionDispatch::IntegrationTest
4   setup do
5     Headless.new.start
6   end
7
8   setup do
9     testfiles.each do |filename, content|
10       open(testfile_path(filename), 'w') do |io|
11         io.write content
12       end
13     end
14   end
15
16   teardown do
17     testfiles.each do |filename, _|
18       File.unlink(testfile_path filename)
19     end
20   end
21
22   test "Create new collection using upload button" do
23     Capybara.current_driver = :poltergeist
24     visit page_with_token 'active', aproject_path
25     find('.btn', text: 'Add data').click
26     click_link 'Upload files from my computer'
27     # Should be looking at a new empty collection.
28     assert_text 'New collection'
29     assert_text 'd41d8cd98f00b204e9800998ecf8427e+0'
30     # The "Upload" tab should be active and loaded.
31     assert_selector 'div#Upload.active div.panel'
32   end
33
34   test "No Upload tab on non-writable collection" do
35     Capybara.current_driver = :poltergeist
36     visit(page_with_token 'active',
37           '/collections/'+api_fixture('collections')['user_agreement']['uuid'])
38     assert_no_selector '.nav-tabs Upload'
39   end
40
41   test "Upload two empty files with the same name" do
42     Capybara.current_driver = :selenium
43     visit page_with_token 'active', sandbox_path
44     find('.nav-tabs a', text: 'Upload').click
45     attach_file 'file_selector', testfile_path('empty.txt')
46     assert_selector 'div', text: 'empty.txt'
47     attach_file 'file_selector', testfile_path('empty.txt')
48     assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
49     click_button 'Start'
50     assert_text :visible, 'Done!'
51     visit sandbox_path+'.json'
52     assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
53   end
54
55   test "Upload non-empty files, report errors" do
56     Capybara.current_driver = :selenium
57     visit page_with_token 'active', sandbox_path
58     find('.nav-tabs a', text: 'Upload').click
59     attach_file 'file_selector', testfile_path('a')
60     attach_file 'file_selector', testfile_path('foo.txt')
61     assert_selector 'button:not([disabled])', text: 'Start'
62     click_button 'Start'
63     if "test environment does not have a keepproxy yet, see #4534"
64       using_wait_time 20 do
65         assert_text :visible, 'error'
66       end
67     else
68       assert_text :visible, 'Done!'
69       visit sandbox_path+'.json'
70       assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
71     end
72   end
73
74   protected
75
76   def aproject_path
77     '/projects/' + api_fixture('groups')['aproject']['uuid']
78   end
79
80   def sandbox_uuid
81     api_fixture('collections')['upload_sandbox']['uuid']
82   end
83
84   def sandbox_path
85     '/collections/' + sandbox_uuid
86   end
87
88   def testfiles
89     {
90       'empty.txt' => '',
91       'a' => 'a',
92       'foo.txt' => 'foo'
93     }
94   end
95
96   def testfile_path filename
97     # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
98     File.join Dir.getwd, 'tmp', filename
99   end
100 end