5105: Better assertion for tab-loading error display.
[arvados.git] / apps / workbench / test / integration / ajax_errors_test.rb
1 require 'integration_helper'
2
3 class AjaxErrorsTest < ActionDispatch::IntegrationTest
4   setup do
5     # Regrettably...
6     need_selenium 'to assert_text in iframe'
7   end
8
9   test 'load pane with deleted session' do
10     # Simulate loading a page in browser-tab A, hitting "Log out" in
11     # browser-tab B, then returning to browser-tab A and choosing a
12     # different tab. (Automatic tab refreshes will behave similarly.)
13     visit page_with_token('active', '/projects/' + api_fixture('groups')['aproject']['uuid'])
14     ActionDispatch::Request::Session.any_instance.stubs(:[]).returns(nil)
15     click_link "Subprojects"
16     wait_for_ajax
17     assert_no_selector '.container-fluid .container-fluid'
18     assert_no_text 'If you have never used'
19     assert_text 'Reload tab'
20     assert_selector '.pane-error-display'
21     page.driver.browser.switch_to.frame 0
22     assert_text 'You are not logged in.'
23   end
24
25   test 'load pane with expired token' do
26     # Similar to 'deleted session'. Here, the session cookie is still
27     # alive, but it contains a token which has expired. This uses a
28     # different code path because Workbench cannot detect that
29     # anything is amiss until it actually uses the token in an API
30     # request.
31     visit page_with_token('active', '/projects/' + api_fixture('groups')['aproject']['uuid'])
32     use_token :active_trustedclient do
33       # Go behind Workbench's back to expire the "active" token.
34       token = api_fixture('api_client_authorizations')['active']['api_token']
35       auth = ApiClientAuthorization.find(token)
36       auth.update_attributes(expires_at: '1999-12-31T23:59:59Z')
37     end
38     click_link "Subprojects"
39     wait_for_ajax
40     assert_no_selector '.container-fluid .container-fluid'
41     assert_no_text 'If you have never used'
42     assert_text 'Reload tab'
43     assert_selector '.pane-error-display'
44     page.driver.browser.switch_to.frame 0
45     assert_text 'You are not logged in.'
46   end
47 end