3021: 4399: Convert some tests from selenium to phantomjs. Restart Headless less.
[arvados.git] / apps / workbench / test / integration / collection_upload_test.rb
1 require 'integration_helper'
2
3 class CollectionUploadTest < ActionDispatch::IntegrationTest
4   setup do
5     Headless.new.start
6   end
7
8   setup do
9     testfiles.each do |filename, content|
10       open(testfile_path(filename), 'w') do |io|
11         io.write content
12       end
13     end
14   end
15
16   teardown do
17     testfiles.each do |filename, _|
18       File.unlink(testfile_path filename)
19     end
20   end
21
22   test "Create new collection using upload button" do
23     Capybara.current_driver = Capybara.javascript_driver
24     visit page_with_token 'active', aproject_path
25     find('.btn', text: 'Add data').click
26     click_link 'Upload files from my computer'
27     # Should be looking at a new empty collection.
28     assert_text 'New collection'
29     assert_text 'd41d8cd98f00b204e9800998ecf8427e+0'
30     # The "Upload" tab should be active and loaded.
31     assert_selector 'div#Upload.active div.panel'
32   end
33
34   test "No Upload tab on non-writable collection" do
35     Capybara.current_driver = Capybara.javascript_driver
36     visit(page_with_token 'active',
37           '/collections/'+api_fixture('collections')['user_agreement']['uuid'])
38     assert_no_selector '.nav-tabs Upload'
39   end
40
41   test "Upload two empty files with the same name" do
42     # Selenium is needed because poltergeist/phantomjs can't do file uploads.
43     Capybara.current_driver = :selenium
44     visit page_with_token 'active', sandbox_path
45     find('.nav-tabs a', text: 'Upload').click
46     attach_file 'file_selector', testfile_path('empty.txt')
47     assert_selector 'div', text: 'empty.txt'
48     attach_file 'file_selector', testfile_path('empty.txt')
49     assert_selector 'div.row div span[title]', text: 'empty.txt', count: 2
50     click_button 'Start'
51     assert_text :visible, 'Done!'
52     visit sandbox_path+'.json'
53     assert_match /_text":"\. d41d8\S+ 0:0:empty.txt\\n\. d41d8\S+ 0:0:empty\\\\040\(1\).txt\\n"/, body
54   end
55
56   test "Upload non-empty files, report errors" do
57     # Selenium is needed because poltergeist/phantomjs can't do file uploads.
58     Capybara.current_driver = :selenium
59     visit page_with_token 'active', sandbox_path
60     find('.nav-tabs a', text: 'Upload').click
61     attach_file 'file_selector', testfile_path('a')
62     attach_file 'file_selector', testfile_path('foo.txt')
63     assert_selector 'button:not([disabled])', text: 'Start'
64     click_button 'Start'
65     if "test environment does not have a keepproxy yet, see #4534" != "fixed"
66       using_wait_time 20 do
67         assert_text :visible, 'error'
68       end
69     else
70       assert_text :visible, 'Done!'
71       visit sandbox_path+'.json'
72       assert_match /_text":"\. 0cc1\S+ 0:1:a\\n\. acbd\S+ 0:3:foo.txt\\n"/, body
73     end
74   end
75
76   protected
77
78   def aproject_path
79     '/projects/' + api_fixture('groups')['aproject']['uuid']
80   end
81
82   def sandbox_uuid
83     api_fixture('collections')['upload_sandbox']['uuid']
84   end
85
86   def sandbox_path
87     '/collections/' + sandbox_uuid
88   end
89
90   def testfiles
91     {
92       'empty.txt' => '',
93       'a' => 'a',
94       'foo.txt' => 'foo'
95     }
96   end
97
98   def testfile_path filename
99     # Must be an absolute path. https://github.com/jnicklas/capybara/issues/621
100     File.join Dir.getwd, 'tmp', filename
101   end
102 end