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 ' 0 files'
26 assert_text ' 0 bytes'
27 # The "Upload" tab should be active and loaded.
28 assert_selector 'div#Upload.active div.panel'
31 test "No Upload tab on non-writable collection" do
33 visit(page_with_token 'active',
34 '/collections/'+api_fixture('collections')['user_agreement']['uuid'])
35 assert_no_selector '.nav-tabs Upload'
38 test "Upload two empty files with the same name" do
39 need_selenium "to make file uploads work"
40 visit page_with_token 'active', sandbox_path
41 find('.nav-tabs a', text: 'Upload').click
42 attach_file 'file_selector', testfile_path('empty.txt')
43 assert_selector 'div', text: 'empty.txt'
44 attach_file 'file_selector', testfile_path('empty.txt')
45 assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
47 assert_text :visible, 'Done!'
48 visit sandbox_path+'.json'
49 assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
52 test "Upload non-empty files, report errors" do
53 need_selenium "to make file uploads work"
54 visit page_with_token 'active', sandbox_path
55 find('.nav-tabs a', text: 'Upload').click
56 attach_file 'file_selector', testfile_path('a')
57 attach_file 'file_selector', testfile_path('foo.txt')
58 assert_selector 'button:not([disabled])', text: 'Start'
60 if "test environment does not have a keepproxy yet, see #4534" != "fixed"
62 assert_text :visible, 'error'
65 assert_text :visible, 'Done!'
66 visit sandbox_path+'.json'
67 assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
71 test "Report mixed-content error" do
72 skip 'Test suite does not use TLS'
73 need_selenium "to make file uploads work"
76 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
77 proxy.update_attributes service_ssl_flag: false
79 visit page_with_token 'active', sandbox_path
80 find('.nav-tabs a', text: 'Upload').click
81 attach_file 'file_selector', testfile_path('foo.txt')
82 assert_selector 'button:not([disabled])', text: 'Start'
85 assert_text :visible, 'server setup problem'
86 assert_text :visible, 'cannot be used from origin'
90 test "Report network error" do
91 need_selenium "to make file uploads work"
94 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
95 # Even if you somehow do port>2^16, surely nx.example.net won't respond
96 proxy.update_attributes service_host: 'nx.example.net', service_port: 99999
98 visit page_with_token 'active', sandbox_path
99 find('.nav-tabs a', text: 'Upload').click
100 attach_file 'file_selector', testfile_path('foo.txt')
101 assert_selector 'button:not([disabled])', text: 'Start'
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