Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / test / integration / errors_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6
7 class ErrorsTest < ActionDispatch::IntegrationTest
8   setup do
9     need_javascript
10   end
11
12   BAD_UUID = "ffffffffffffffffffffffffffffffff+0"
13
14   test "error page renders user navigation" do
15     visit(page_with_token("active", "/collections/#{BAD_UUID}"))
16     assert(page.has_link?("notifications-menu"),
17            "User information missing from error page")
18     assert(page.has_no_text?(/log ?in/i),
19            "Logged in user prompted to log in on error page")
20   end
21
22   test "no user navigation with expired token" do
23     visit(page_with_token("expired", "/collections/#{BAD_UUID}"))
24     assert(page.has_no_link?("notifications-menu"),
25            "Page visited with expired token included user information")
26     assert(page.has_selector?("a", text: /log ?in/i),
27            "Login prompt missing on expired token error page")
28   end
29
30   test "error page renders without login" do
31     visit "/collections/download/#{BAD_UUID}/#{@@API_AUTHS['active']['api_token']}"
32     assert(page.has_no_text?(/\b500\b/),
33            "Error page without login returned 500")
34   end
35
36   test "'object not found' page includes search link" do
37     visit(page_with_token("active", "/collections/#{BAD_UUID}"))
38     assert(all("a").any? { |a| a[:href] =~ %r{/collections/?(\?|$)} },
39            "no search link found on 404 page")
40   end
41
42   def now_timestamp
43     Time.now.utc.to_i
44   end
45
46   def page_has_error_token?(start_stamp)
47     matching_stamps = (start_stamp .. now_timestamp).to_a.join("|")
48     # Check the page HTML because we really don't care how it's presented.
49     # I think it would even be reasonable to put it in a comment.
50     page.html =~ /\b(#{matching_stamps})\+[0-9A-Fa-f]{8}\b/
51   end
52
53   test "showing a bad UUID returns 404" do
54     visit(page_with_token("active", "/pipeline_templates/zzz"))
55     assert(page.has_no_text?(/fiddlesticks/i),
56            "trying to show a bad UUID rendered a fiddlesticks page, not 404")
57   end
58
59   test "404 page includes information about missing object" do
60     visit(page_with_token("active", "/groups/zazazaz"))
61     assert(page.has_text?(/group with UUID zazazaz/i),
62            "name of searched group missing from 404 page")
63   end
64
65   test "unrouted 404 page works" do
66     visit(page_with_token("active", "/__asdf/ghjk/zxcv"))
67     assert(page.has_text?(/not found/i),
68            "unrouted page missing 404 text")
69     assert(page.has_no_text?(/fiddlesticks/i),
70            "unrouted request returned a generic error page, not 404")
71   end
72
73   test "API error page has Report problem button" do
74     # point to a bad api server url to generate fiddlesticks error
75     original_arvados_v1_base = Rails.configuration.Services.Controller.ExternalURL
76     Rails.configuration.Services.Controller.ExternalURL = URI("https://[::1]:1/")
77
78     visit page_with_token("active")
79
80     assert_text 'fiddlesticks'
81
82     # reset api server base config to let the popup rendering to work
83     Rails.configuration.Services.Controller.ExternalURL = original_arvados_v1_base
84
85     click_link 'Report problem'
86
87     within '.modal-content' do
88       assert_text 'Report a problem'
89       assert_no_text 'Version / debugging info'
90       assert_text 'Describe the problem'
91       assert_text 'Send problem report'
92       # "Send" button should be disabled until text is entered
93       assert_no_selector 'a,button:not([disabled])', text: 'Send problem report'
94       assert_selector 'a,button', text: 'Cancel'
95
96       report = mock
97       report.expects(:deliver).returns true
98       IssueReporter.expects(:send_report).returns report
99
100       # enter a report text and click on report
101       find_field('report_issue_text').set 'my test report text'
102       click_button 'Send problem report'
103
104       # ajax success updated button texts and added footer message
105       assert_no_selector 'a,button', text: 'Send problem report'
106       assert_no_selector 'a,button', text: 'Cancel'
107       assert_text 'Report sent'
108       assert_text 'Thanks for reporting this issue'
109       click_button 'Close'
110     end
111
112     # out of the popup now and should be back in the error page
113     assert_text 'fiddlesticks'
114   end
115
116   test "showing a trashed collection UUID gives untrash button" do
117     visit(page_with_token("active", "/collections/zzzzz-4zz18-trashedproj2col"))
118     assert(page.has_text?(/You must untrash the owner project to access this/i),
119            "missing untrash instructions")
120   end
121
122   test "showing a trashed container request gives untrash button" do
123     visit(page_with_token("active", "/container_requests/zzzzz-xvhdp-cr5trashedcontr"))
124     assert(page.has_text?(/You must untrash the owner project to access this/i),
125            "missing untrash instructions")
126   end
127
128 end