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 "Upload two empty files with the same name" do
32 need_selenium "to make file uploads work"
33 visit page_with_token 'active', sandbox_path
34 find('.nav-tabs a', text: 'Upload').click
35 attach_file 'file_selector', testfile_path('empty.txt')
36 assert_selector 'div', text: 'empty.txt'
37 attach_file 'file_selector', testfile_path('empty.txt')
38 assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
40 assert_text :visible, 'Done!'
41 visit sandbox_path+'.json'
42 assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
45 test "Upload non-empty files, report errors" do
46 need_selenium "to make file uploads work"
47 visit page_with_token 'active', sandbox_path
48 find('.nav-tabs a', text: 'Upload').click
49 attach_file 'file_selector', testfile_path('a')
50 attach_file 'file_selector', testfile_path('foo.txt')
51 assert_selector 'button:not([disabled])', text: 'Start'
53 if "test environment does not have a keepproxy yet, see #4534" != "fixed"
55 assert_text :visible, 'error'
58 assert_text :visible, 'Done!'
59 visit sandbox_path+'.json'
60 assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
64 test "Report mixed-content error" do
65 skip 'Test suite does not use TLS'
66 need_selenium "to make file uploads work"
69 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
70 proxy.update_attributes service_ssl_flag: false
72 visit page_with_token 'active', sandbox_path
73 find('.nav-tabs a', text: 'Upload').click
74 attach_file 'file_selector', testfile_path('foo.txt')
75 assert_selector 'button:not([disabled])', text: 'Start'
78 assert_text :visible, 'server setup problem'
79 assert_text :visible, 'cannot be used from origin'
83 test "Report network error" do
84 need_selenium "to make file uploads work"
87 proxy = KeepService.find(api_fixture('keep_services')['proxy']['uuid'])
88 # Even if you somehow do port>2^16, surely nx.example.net won't respond
89 proxy.update_attributes service_host: 'nx.example.net', service_port: 99999
91 visit page_with_token 'active', sandbox_path
92 find('.nav-tabs a', text: 'Upload').click
93 attach_file 'file_selector', testfile_path('foo.txt')
94 assert_selector 'button:not([disabled])', text: 'Start'
97 assert_text :visible, 'network error'
104 '/projects/' + api_fixture('groups')['aproject']['uuid']
108 api_fixture('collections')['upload_sandbox']['uuid']
112 '/collections/' + sandbox_uuid
123 def testfile_path filename
124 # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
125 File.join Dir.getwd, 'tmp', filename