1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class CollectionUploadTest < ActionDispatch::IntegrationTest
9 testfiles.each do |filename, content|
10 open(testfile_path(filename), 'w') do |io|
14 # Database reset doesn't restore KeepServices; we have to
15 # save/restore manually.
17 @keep_services = KeepService.all.to_a
23 @keep_services.each do |ks|
24 KeepService.find(ks.uuid).update_attributes(ks.attributes)
27 testfiles.each do |filename, _|
28 File.unlink(testfile_path filename)
32 test "Create new collection using upload button" do
34 visit page_with_token 'active', aproject_path
35 find('.btn', text: 'Add data').click
36 click_link 'Upload files from my computer'
37 # Should be looking at a new empty collection.
38 assert_text 'New collection'
39 assert_text ' 0 files'
40 assert_text ' 0 bytes'
41 # The "Upload" tab should be active and loaded.
42 assert_selector 'div#Upload.active div.panel'
45 test "Upload two empty files with the same name" do
46 need_selenium "to make file uploads work"
47 visit page_with_token 'active', sandbox_path
51 find('.nav-tabs a', text: 'Upload').click
52 attach_file 'file_selector', testfile_path('empty.txt')
53 assert_selector 'div', text: 'empty.txt'
54 attach_file 'file_selector', testfile_path('empty.txt')
55 assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
57 assert_text :visible, 'Done!'
58 visit sandbox_path+'.json'
59 assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
62 test "Upload non-empty files" do
63 need_selenium "to make file uploads work"
64 visit page_with_token 'active', sandbox_path
68 find('.nav-tabs a', text: 'Upload').click
69 attach_file 'file_selector', testfile_path('a')
70 attach_file 'file_selector', testfile_path('foo.txt')
71 assert_selector 'button:not([disabled])', text: 'Start'
73 assert_text :visible, 'Done!'
74 visit sandbox_path+'.json'
75 assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
78 test "Report mixed-content error" do
79 skip 'Test suite does not use TLS'
80 need_selenium "to make file uploads work"
82 KeepService.where(service_type: 'proxy').first.
83 update_attributes(service_ssl_flag: false)
85 visit page_with_token 'active', sandbox_path
86 find('.nav-tabs a', text: 'Upload').click
87 attach_file 'file_selector', testfile_path('foo.txt')
88 assert_selector 'button:not([disabled])', text: 'Start'
91 assert_text :visible, 'server setup problem'
92 assert_text :visible, 'cannot be used from origin'
96 test "Report network error" do
97 need_selenium "to make file uploads work"
99 # Even if port 0 is a thing, surely nx.example.net won't
101 KeepService.where(service_type: 'proxy').first.
102 update_attributes(service_host: 'nx.example.net',
105 visit page_with_token 'active', sandbox_path
109 find('.nav-tabs a', text: 'Upload').click
110 attach_file 'file_selector', testfile_path('foo.txt')
111 assert_selector 'button:not([disabled])', text: 'Start'
114 assert_text :visible, 'network error'
121 '/projects/' + api_fixture('groups')['aproject']['uuid']
125 api_fixture('collections')['upload_sandbox']['uuid']
129 '/collections/' + sandbox_uuid
140 def testfile_path filename
141 # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
142 File.join Dir.getwd, 'tmp', filename
145 def unlock_collection
146 first('.lock-collection-btn').click