Merge branch '5105-ajax-redirect' closes #5105
[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_double_layout
18     assert_selector 'a,button', text: 'Reload tab'
19     assert_selector '.pane-error-display'
20     page.driver.browser.switch_to.frame 0
21     assert_text 'You are not logged in.'
22   end
23
24   test 'load pane with expired token' do
25     # Similar to 'deleted session'. Here, the session cookie is still
26     # alive, but it contains a token which has expired. This uses a
27     # different code path because Workbench cannot detect that
28     # anything is amiss until it actually uses the token in an API
29     # request.
30     visit page_with_token('active', '/projects/' + api_fixture('groups')['aproject']['uuid'])
31     use_token :active_trustedclient do
32       # Go behind Workbench's back to expire the "active" token.
33       token = api_fixture('api_client_authorizations')['active']['api_token']
34       auth = ApiClientAuthorization.find(token)
35       auth.update_attributes(expires_at: '1999-12-31T23:59:59Z')
36     end
37     click_link "Subprojects"
38     wait_for_ajax
39     assert_no_double_layout
40     assert_selector 'a,button', text: 'Reload tab'
41     assert_selector '.pane-error-display'
42     page.driver.browser.switch_to.frame 0
43     assert_text 'You are not logged in.'
44   end
45
46   protected
47
48   def assert_no_double_layout
49     # Check we're not rendering a full page layout within a tab
50     # pane. Bootstrap responsive layouts require exactly one
51     # div.container-fluid. Checking "body body" would be more generic,
52     # but doesn't work when the browser/driver automatically collapses
53     # syntatically invalid tags.
54     assert_no_selector '.container-fluid .container-fluid'
55   end
56 end