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
47 find('.nav-tabs a', text: 'Upload').click
48 attach_file 'file_selector', testfile_path('empty.txt')
49 assert_selector 'div', text: 'empty.txt'
50 attach_file 'file_selector', testfile_path('empty.txt')
51 assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
53 assert_text :visible, 'Done!'
54 visit sandbox_path+'.json'
55 assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
58 test "Upload non-empty files" do
59 need_selenium "to make file uploads work"
60 visit page_with_token 'active', sandbox_path
64 find('.nav-tabs a', text: 'Upload').click
65 attach_file 'file_selector', testfile_path('a')
66 attach_file 'file_selector', testfile_path('foo.txt')
67 assert_selector 'button:not([disabled])', text: 'Start'
69 assert_text :visible, 'Done!'
70 visit sandbox_path+'.json'
71 assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
74 test "Report mixed-content error" do
75 skip 'Test suite does not use TLS'
76 need_selenium "to make file uploads work"
78 KeepService.where(service_type: 'proxy').first.
79 update_attributes(service_ssl_flag: false)
81 visit page_with_token 'active', sandbox_path
82 find('.nav-tabs a', text: 'Upload').click
83 attach_file 'file_selector', testfile_path('foo.txt')
84 assert_selector 'button:not([disabled])', text: 'Start'
87 assert_text :visible, 'server setup problem'
88 assert_text :visible, 'cannot be used from origin'
92 test "Report network error" do
93 need_selenium "to make file uploads work"
95 # Even if you somehow do port>2^16, surely nx.example.net won't
97 KeepService.where(service_type: 'proxy').first.
98 update_attributes(service_host: 'nx.example.net',
101 visit page_with_token 'active', sandbox_path
105 find('.nav-tabs a', text: 'Upload').click
106 attach_file 'file_selector', testfile_path('foo.txt')
107 assert_selector 'button:not([disabled])', text: 'Start'
110 assert_text :visible, 'network error'
117 '/projects/' + api_fixture('groups')['aproject']['uuid']
121 api_fixture('collections')['upload_sandbox']['uuid']
125 '/collections/' + sandbox_uuid
136 def testfile_path filename
137 # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
138 File.join Dir.getwd, 'tmp', filename
141 def unlock_collection
142 first('.lock-collection-btn').click