1 require 'integration_helper'
3 class CollectionUploadTest < ActionDispatch::IntegrationTest
5 testfiles.each do |filename, content|
6 open(testfile_path(filename), 'w') do |io|
13 testfiles.each do |filename, _|
14 File.unlink(testfile_path filename)
18 test "Create new collection using upload button" do
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'
30 test "No Upload tab on non-writable collection" do
32 visit(page_with_token 'active',
33 '/collections/'+api_fixture('collections')['user_agreement']['uuid'])
34 assert_no_selector '.nav-tabs Upload'
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
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
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'
59 if "test environment does not have a keepproxy yet, see #4534" != "fixed"
61 assert_text :visible, 'error'
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
73 '/projects/' + api_fixture('groups')['aproject']['uuid']
77 api_fixture('collections')['upload_sandbox']['uuid']
81 '/collections/' + sandbox_uuid
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