1 require 'integration_helper'
3 class ErrorsTest < ActionDispatch::IntegrationTest
8 BAD_UUID = "ffffffffffffffffffffffffffffffff+0"
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")
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")
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")
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")
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/
49 # We use API tokens with limited scopes as the quickest way to get the API
50 # server to return an error. If Workbench gets smarter about coping when
51 # it has a too-limited token, these tests will need to be adjusted.
52 test "API error page includes error token" do
53 start_stamp = now_timestamp
54 visit(page_with_token("active_readonly", "/authorized_keys"))
55 click_on "Add a new authorized key"
56 assert(page.has_text?(/fiddlesticks/i),
57 "Not on an error page after making an SSH key out of scope")
58 assert(page_has_error_token?(start_stamp), "no error token on 404 page")
61 test "showing a bad UUID returns 404" do
62 visit(page_with_token("active", "/pipeline_templates/zzz"))
63 assert(page.has_no_text?(/fiddlesticks/i),
64 "trying to show a bad UUID rendered a fiddlesticks page, not 404")
67 test "404 page includes information about missing object" do
68 visit(page_with_token("active", "/groups/zazazaz"))
69 assert(page.has_text?(/group with UUID zazazaz/i),
70 "name of searched group missing from 404 page")
73 test "unrouted 404 page works" do
74 visit(page_with_token("active", "/__asdf/ghjk/zxcv"))
75 assert(page.has_text?(/not found/i),
76 "unrouted page missing 404 text")
77 assert(page.has_no_text?(/fiddlesticks/i),
78 "unrouted request returned a generic error page, not 404")
81 test "API error page has Report problem button" do
82 # point to a bad api server url to generate fiddlesticks error
83 original_arvados_v1_base = Rails.configuration.arvados_v1_base
84 Rails.configuration.arvados_v1_base = "https://[::1]:1/"
86 visit page_with_token("active")
88 assert_text 'fiddlesticks'
90 # reset api server base config to let the popup rendering to work
91 Rails.configuration.arvados_v1_base = original_arvados_v1_base
93 click_link 'Report problem'
95 within '.modal-content' do
96 assert_text 'Report a problem'
97 assert_no_text 'Version / debugging info'
98 assert_text 'Describe the problem'
99 assert_text 'Send problem report'
100 # "Send" button should be disabled until text is entered
101 assert_no_selector 'a,button:not([disabled])', text: 'Send problem report'
102 assert_selector 'a,button', text: 'Cancel'
105 report.expects(:deliver).returns true
106 IssueReporter.expects(:send_report).returns report
108 # enter a report text and click on report
109 find_field('report_issue_text').set 'my test report text'
110 click_button 'Send problem report'
112 # ajax success updated button texts and added footer message
113 assert_no_selector 'a,button', text: 'Send problem report'
114 assert_no_selector 'a,button', text: 'Cancel'
115 assert_text 'Report sent'
116 assert_text 'Thanks for reporting this issue'
120 # out of the popup now and should be back in the error page
121 assert_text 'fiddlesticks'