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