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