mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Back button navigation fix 31238 (#32372)
* initial fix for navigation issue + Spencer * added navigation test for issue #31238 * added more validations to the navigate back test
This commit is contained in:
parent
062376368e
commit
ace80d1b59
3 changed files with 90 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import $ from 'jquery';
|
||||
import url from 'url';
|
||||
|
||||
import { uiModules } from '../../modules';
|
||||
import {
|
||||
|
@ -57,7 +58,7 @@ export function kbnChromeProvider(chrome, internals) {
|
|||
},
|
||||
|
||||
controllerAs: 'chrome',
|
||||
controller($scope, $rootScope, Private) {
|
||||
controller($scope, $rootScope, Private, $location) {
|
||||
const getUnhashableStates = Private(getUnhashableStatesProvider);
|
||||
const subUrlRouteFilter = Private(SubUrlRouteFilterProvider);
|
||||
|
||||
|
@ -73,6 +74,19 @@ export function kbnChromeProvider(chrome, internals) {
|
|||
}
|
||||
}
|
||||
|
||||
$rootScope.$on('$locationChangeStart', (e, newUrl) => {
|
||||
// This handler fixes issue #31238 where browser back navigation
|
||||
// fails due to angular 1.6 parsing url encoded params wrong.
|
||||
const absUrlHash = url.parse($location.absUrl()).hash;
|
||||
const decodedAbsUrlHash = decodeURIComponent(absUrlHash);
|
||||
const hash = url.parse(newUrl).hash;
|
||||
const decodedHash = decodeURIComponent(hash);
|
||||
if (absUrlHash !== hash && decodedHash === decodedAbsUrlHash) {
|
||||
// replace the urlencoded hash with the version that angular sees.
|
||||
$location.url(absUrlHash).replace();
|
||||
}
|
||||
|
||||
});
|
||||
$rootScope.$on('$routeChangeSuccess', onRouteChange);
|
||||
$rootScope.$on('$routeUpdate', onRouteChange);
|
||||
updateSubUrls(); // initialize sub urls
|
||||
|
|
74
test/functional/apps/home/_navigation.js
Normal file
74
test/functional/apps/home/_navigation.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from 'expect.js';
|
||||
|
||||
|
||||
export default function ({ getService, getPageObjects }) {
|
||||
const browser = getService('browser');
|
||||
const PageObjects = getPageObjects(['dashboard', 'common', 'home', 'timePicker']);
|
||||
const appsMenu = getService('appsMenu');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const fromTime = '2015-09-19 06:31:44.000';
|
||||
const toTime = '2015-09-23 18:31:44.000';
|
||||
|
||||
describe('Kibana browser back navigation should work', function describeIndexTests() {
|
||||
|
||||
before(async () => {
|
||||
await PageObjects.dashboard.initTests();
|
||||
await kibanaServer.uiSettings.disableToastAutohide();
|
||||
await browser.refresh();
|
||||
});
|
||||
|
||||
it('detect navigate back issues', async ()=> {
|
||||
let currUrl;
|
||||
// Detects bug described in issue #31238 - where back navigation would get stuck to URL encoding handling in Angular.
|
||||
// Navigate to home app
|
||||
await PageObjects.common.navigateToApp('home');
|
||||
const homeUrl = await browser.getCurrentUrl();
|
||||
|
||||
// Navigate to discover app
|
||||
await appsMenu.clickLink('Discover');
|
||||
const discoverUrl = await browser.getCurrentUrl();
|
||||
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
|
||||
const modifiedTimeDiscoverUrl = await browser.getCurrentUrl();
|
||||
|
||||
// Navigate to dashboard app
|
||||
await appsMenu.clickLink('Dashboard');
|
||||
|
||||
// Navigating back to discover
|
||||
await browser.goBack();
|
||||
currUrl = await browser.getCurrentUrl();
|
||||
expect(currUrl).to.be(modifiedTimeDiscoverUrl);
|
||||
|
||||
// Navigating back from time settings
|
||||
await browser.goBack(); // undo time settings
|
||||
await browser.goBack(); // undo automatically set config, should it be in the history stack? (separate issue!)
|
||||
currUrl = await browser.getCurrentUrl();
|
||||
// Discover view also keeps adds some default arguments into the _a URL parameter, so we can only check that the url starts the same.
|
||||
expect(currUrl.startsWith(discoverUrl)).to.be(true);
|
||||
|
||||
// Navigate back home
|
||||
await browser.goBack();
|
||||
currUrl = await browser.getCurrentUrl();
|
||||
expect(currUrl).to.be(homeUrl);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ export default function ({ getService, loadTestFile }) {
|
|||
return browser.setWindowSize(1200, 800);
|
||||
});
|
||||
|
||||
loadTestFile(require.resolve('./_navigation'));
|
||||
loadTestFile(require.resolve('./_home'));
|
||||
loadTestFile(require.resolve('./_add_data'));
|
||||
loadTestFile(require.resolve('./_sample_data'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue