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
70 test "Report mixed-content error" do
71 skip 'Test suite does not use TLS'
72 need_selenium "to make file uploads work"
75 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
76 proxy.update_attributes service_ssl_flag: false
78 visit page_with_token 'active', sandbox_path
79 find('.nav-tabs a', text: 'Upload').click
80 attach_file 'file_selector', testfile_path('foo.txt')
81 assert_selector 'button:not([disabled])', text: 'Start'
84 assert_text :visible, 'server setup problem'
85 assert_text :visible, 'cannot be used from origin'
89 test "Report CORS problem or network error" do
90 need_selenium "to make file uploads work"
93 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
94 # Even if you somehow do port>2^16, surely nx.example.net won't respond
95 proxy.update_attributes service_host: 'nx.example.net', service_port: 99999
97 visit page_with_token 'active', sandbox_path
98 find('.nav-tabs a', text: 'Upload').click
99 attach_file 'file_selector', testfile_path('foo.txt')
100 assert_selector 'button:not([disabled])', text: 'Start'
103 assert_text :visible, 'CORS'
104 assert_text :visible, 'network error'
111 '/projects/' + api_fixture('groups')['aproject']['uuid']
115 api_fixture('collections')['upload_sandbox']['uuid']
119 '/collections/' + sandbox_uuid
130 def testfile_path filename
131 # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
132 File.join Dir.getwd, 'tmp', filename