1 require 'integration_helper'
3 class CollectionUploadTest < ActionDispatch::IntegrationTest
5 testfiles.each do |filename, content|
6 open(testfile_path(filename), 'w') do |io|
10 # Database reset doesn't restore KeepServices; we have to
11 # save/restore manually.
13 @keep_services = KeepService.all.to_a
19 @keep_services.each do |ks|
20 KeepService.find(ks.uuid).update_attributes(ks.attributes)
23 testfiles.each do |filename, _|
24 File.unlink(testfile_path filename)
28 test "Create new collection using upload button" do
30 visit page_with_token 'active', aproject_path
31 find('.btn', text: 'Add data').click
32 click_link 'Upload files from my computer'
33 # Should be looking at a new empty collection.
34 assert_text 'New collection'
35 assert_text ' 0 files'
36 assert_text ' 0 bytes'
37 # The "Upload" tab should be active and loaded.
38 assert_selector 'div#Upload.active div.panel'
41 test "Upload two empty files with the same name" do
42 need_selenium "to make file uploads work"
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" do
56 need_selenium "to make file uploads work"
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 assert_text :visible, 'Done!'
64 visit sandbox_path+'.json'
65 assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
68 test "Report mixed-content error" do
69 skip 'Test suite does not use TLS'
70 need_selenium "to make file uploads work"
72 KeepService.where(service_type: 'proxy').first.
73 update_attributes(service_ssl_flag: false)
75 visit page_with_token 'active', sandbox_path
76 find('.nav-tabs a', text: 'Upload').click
77 attach_file 'file_selector', testfile_path('foo.txt')
78 assert_selector 'button:not([disabled])', text: 'Start'
81 assert_text :visible, 'server setup problem'
82 assert_text :visible, 'cannot be used from origin'
86 test "Report network error" do
87 need_selenium "to make file uploads work"
89 # Even if you somehow do port>2^16, surely nx.example.net won't
91 KeepService.where(service_type: 'proxy').first.
92 update_attributes(service_host: 'nx.example.net',
95 visit page_with_token 'active', sandbox_path
96 find('.nav-tabs a', text: 'Upload').click
97 attach_file 'file_selector', testfile_path('foo.txt')
98 assert_selector 'button:not([disabled])', text: 'Start'
101 assert_text :visible, 'network error'
108 '/projects/' + api_fixture('groups')['aproject']['uuid']
112 api_fixture('collections')['upload_sandbox']['uuid']
116 '/collections/' + sandbox_uuid
127 def testfile_path filename
128 # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
129 File.join Dir.getwd, 'tmp', filename