1 require 'integration_helper'
3 class CollectionUploadTest < ActionDispatch::IntegrationTest
9 testfiles.each do |filename, content|
10 open(testfile_path(filename), 'w') do |io|
17 testfiles.each do |filename, _|
18 File.unlink(testfile_path filename)
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'
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'
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
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
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'
63 if "test environment does not have a keepproxy yet, see #4534"
65 assert_text :visible, 'error'
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
77 '/projects/' + api_fixture('groups')['aproject']['uuid']
81 api_fixture('collections')['upload_sandbox']['uuid']
85 '/collections/' + sandbox_uuid
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