3781: Merge branch 'master' into 3781-browser-upload
[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       assert_text :visible, 'error'
65     else
66       assert_text :visible, 'Done!'
67       visit sandbox_path+'.json'
68       assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
69     end
70   end
71
72   protected
73
74   def aproject_path
75     '/projects/' + api_fixture('groups')['aproject']['uuid']
76   end
77
78   def sandbox_uuid
79     api_fixture('collections')['upload_sandbox']['uuid']
80   end
81
82   def sandbox_path
83     '/collections/' + sandbox_uuid
84   end
85
86   def testfiles
87     {
88       'empty.txt' => '',
89       'a' => 'a',
90       'foo.txt' => 'foo'
91     }
92   end
93
94   def testfile_path filename
95     # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
96     File.join Dir.getwd, 'tmp', filename
97   end
98 end