1 require 'integration_helper'
3 class AjaxErrorsTest < ActionDispatch::IntegrationTest
6 need_selenium 'to assert_text in iframe'
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"
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.'
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
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')
37 click_link "Subprojects"
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.'
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'