Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / test / integration / ajax_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 AjaxErrorsTest < ActionDispatch::IntegrationTest
8   setup do
9     # Regrettably...
10     need_selenium 'to assert_text in iframe'
11   end
12
13   test 'load pane with deleted session' do
14     skip 'unreliable test'
15     # Simulate loading a page in browser-tab A, hitting "Log out" in
16     # browser-tab B, then returning to browser-tab A and choosing a
17     # different tab. (Automatic tab refreshes will behave similarly.)
18     visit page_with_token('active', '/projects/' + api_fixture('groups')['aproject']['uuid'])
19     ActionDispatch::Request::Session.any_instance.stubs(:[]).returns(nil)
20     click_link "Subprojects"
21     wait_for_ajax
22     assert_no_double_layout
23     assert_selector 'a,button', text: 'Reload tab'
24     assert_selector '.pane-error-display'
25     page.driver.browser.switch_to.frame 0
26     assert_text 'You are not logged in.'
27   end
28
29   test 'load pane with expired token' do
30     skip 'unreliable test'
31     # Similar to 'deleted session'. Here, the session cookie is still
32     # alive, but it contains a token which has expired. This uses a
33     # different code path because Workbench cannot detect that
34     # anything is amiss until it actually uses the token in an API
35     # request.
36     visit page_with_token('active', '/projects/' + api_fixture('groups')['aproject']['uuid'])
37     use_token :active_trustedclient do
38       # Go behind Workbench's back to expire the "active" token.
39       token = api_fixture('api_client_authorizations')['active']['api_token']
40       auth = ApiClientAuthorization.find(token)
41       auth.update_attributes(expires_at: '1999-12-31T23:59:59Z')
42     end
43     click_link "Subprojects"
44     wait_for_ajax
45     assert_no_double_layout
46     assert_selector 'a,button', text: 'Reload tab'
47     assert_selector '.pane-error-display'
48     page.driver.browser.switch_to.frame 0
49     assert_text 'You are not logged in.'
50   end
51
52   protected
53
54   def assert_no_double_layout
55     # Check we're not rendering a full page layout within a tab
56     # pane. Bootstrap responsive layouts require exactly one
57     # div.container-fluid. Checking "body body" would be more generic,
58     # but doesn't work when the browser/driver automatically collapses
59     # syntatically invalid tags.
60     assert_no_selector '.container-fluid .container-fluid'
61   end
62 end