[tests/functional] opt out of getting started on navigation (#11881)
* [tests/functional] automatically opt-out of getting started page on navigation * [test/functional/commonPage] avoid circular reference * [test/functional/commonPage] move check for getting started after url has settled * [gettingStarted] prevent route resolution by returning halt promises * [test/functional/commonPage] wait for kibana to load before checking for getting started * [uiRoutes/setupWork] provide a token that can be thrown to halt setup work * [ui/routes] rename reference to WAIT_FOR_URL_CHANGE_TOKEN * address review feedback
This commit is contained in:
parent
c2ccab8515
commit
c9c8e8d066
|
@ -1,4 +1,4 @@
|
|||
<div class="kuiViewContent gettingStartedContent">
|
||||
<div class="kuiViewContent gettingStartedContent" data-test-subj="gettingStartedContainer">
|
||||
|
||||
<div
|
||||
ng-if="!gettingStarted.hasOptedOut()"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { get } from 'lodash';
|
||||
import uiRoutes from 'ui/routes';
|
||||
import uiRoutes, { WAIT_FOR_URL_CHANGE_TOKEN } from 'ui/routes';
|
||||
import uiChrome from 'ui/chrome';
|
||||
import KbnUrlProvider from 'ui/url';
|
||||
import { Notifier } from 'ui/notify/notifier';
|
||||
import { IndexPatternsGetIdsProvider } from 'ui/index_patterns/_get_ids';
|
||||
import { hasOptedOutOfGettingStarted, optOutOfGettingStarted } from 'ui/getting_started/opt_out_helpers';
|
||||
|
@ -14,8 +13,8 @@ import {
|
|||
uiRoutes
|
||||
.addSetupWork(function gettingStartedGateCheck(Private, $injector) {
|
||||
const getIds = Private(IndexPatternsGetIdsProvider);
|
||||
const kbnUrl = Private(KbnUrlProvider);
|
||||
const config = $injector.get('config');
|
||||
const kbnUrl = $injector.get('kbnUrl');
|
||||
const $route = $injector.get('$route');
|
||||
|
||||
const currentRoute = get($route, 'current.$$route');
|
||||
|
@ -68,14 +67,14 @@ uiRoutes
|
|||
});
|
||||
notify.error('Please create a new index pattern');
|
||||
kbnUrl.change(CREATE_INDEX_PATTERN_ROUTE);
|
||||
return;
|
||||
throw WAIT_FOR_URL_CHANGE_TOKEN;
|
||||
}
|
||||
|
||||
// Redirect the user to the Getting Started page (unless they are on it already)
|
||||
if (!isOnGettingStartedPage) {
|
||||
uiChrome.setVisible(false);
|
||||
kbnUrl.change(GETTING_STARTED_ROUTE);
|
||||
return;
|
||||
throw WAIT_FOR_URL_CHANGE_TOKEN;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
import { wrapRouteWithPrep } from './wrap_route_with_prep';
|
||||
import RouteSetupManager from './route_setup_manager';
|
||||
import { RouteSetupManager } from './route_setup_manager';
|
||||
|
||||
function RouteManager() {
|
||||
const self = this;
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
module.exports = class RouteSetupManager {
|
||||
// Throw this inside of an Angular route resolver after calling `kbnUrl.change`
|
||||
// so that the $router can observe the $location update. Otherwise, the location
|
||||
// route setup work will resovle before the route update occurs.
|
||||
export const WAIT_FOR_URL_CHANGE_TOKEN = new Error('WAIT_FOR_URL_CHANGE_TOKEN');
|
||||
|
||||
export class RouteSetupManager {
|
||||
constructor() {
|
||||
this.setupWork = [];
|
||||
this.onSetupComplete = [];
|
||||
|
@ -71,9 +76,18 @@ module.exports = class RouteSetupManager {
|
|||
|
||||
return defer.promise.then(() => Promise.all(userWork.doWork()));
|
||||
})
|
||||
.catch(error => {
|
||||
if (error === WAIT_FOR_URL_CHANGE_TOKEN) {
|
||||
// prevent moving forward, return a promise that never resolves
|
||||
// so that the $router can observe the $location update
|
||||
return Promise.halt();
|
||||
}
|
||||
|
||||
throw error;
|
||||
})
|
||||
.then(
|
||||
() => invokeEach(this.onWorkComplete),
|
||||
err => callErrorHandlers(this.onWorkError, err)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ import RouteManager from './route_manager';
|
|||
import 'angular-route/angular-route';
|
||||
import { uiModules } from 'ui/modules';
|
||||
const defaultRouteManager = new RouteManager();
|
||||
import { WAIT_FOR_URL_CHANGE_TOKEN } from './route_setup_manager';
|
||||
|
||||
module.exports = {
|
||||
...defaultRouteManager,
|
||||
WAIT_FOR_URL_CHANGE_TOKEN,
|
||||
enable() {
|
||||
uiModules
|
||||
.get('kibana', ['ngRoute'])
|
||||
|
|
|
@ -15,14 +15,12 @@ export default function ({ getService, getPageObjects }) {
|
|||
const retry = getService('retry');
|
||||
const log = getService('log');
|
||||
const screenshots = getService('screenshots');
|
||||
const PageObjects = getPageObjects(['common', 'console', 'gettingStarted']);
|
||||
const PageObjects = getPageObjects(['common', 'console']);
|
||||
|
||||
describe('console app', function describeIndexTests() {
|
||||
before(async function () {
|
||||
log.debug('navigateTo console');
|
||||
await PageObjects.common.navigateToUrl('settings', 'kibana/getting_started');
|
||||
await PageObjects.gettingStarted.clickOptOutLink();
|
||||
return PageObjects.common.navigateToApp('console');
|
||||
await PageObjects.common.navigateToApp('console');
|
||||
});
|
||||
|
||||
it('should show the default request', function () {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { delay } from 'bluebird';
|
|||
|
||||
import getUrl from '../../../src/test_utils/get_url';
|
||||
|
||||
export function CommonPageProvider({ getService, getPageObjects }) {
|
||||
export function CommonPageProvider({ getService, getPageObjects, getPageObject }) {
|
||||
const log = getService('log');
|
||||
const config = getService('config');
|
||||
const remote = getService('remote');
|
||||
|
@ -72,26 +72,30 @@ export function CommonPageProvider({ getService, getPageObjects }) {
|
|||
log.debug('returned from get, calling refresh');
|
||||
return remote.refresh();
|
||||
})
|
||||
.then(function () {
|
||||
return remote.getCurrentUrl();
|
||||
})
|
||||
.then(function (currentUrl) {
|
||||
.then(async function () {
|
||||
const currentUrl = await remote.getCurrentUrl();
|
||||
const loginPage = currentUrl.includes('/login');
|
||||
const wantedLoginPage = appUrl.includes('/login') || appUrl.includes('/logout');
|
||||
|
||||
if (loginPage && !wantedLoginPage) {
|
||||
log.debug('Found loginPage username = '
|
||||
+ config.get('servers.kibana.username'));
|
||||
return PageObjects.shield.login(config.get('servers.kibana.username'),
|
||||
config.get('servers.kibana.password'))
|
||||
.then(function () {
|
||||
return remote.getCurrentUrl();
|
||||
});
|
||||
} else {
|
||||
return currentUrl;
|
||||
log.debug(`Found loginPage username = ${config.get('servers.kibana.username')}`);
|
||||
await PageObjects.shield.login(
|
||||
config.get('servers.kibana.username'),
|
||||
config.get('servers.kibana.password')
|
||||
);
|
||||
}
|
||||
|
||||
if (currentUrl.includes('app/kibana')) {
|
||||
await testSubjects.find('kibanaChrome');
|
||||
const gettingStartedPage = getPageObject('gettingStarted');
|
||||
if (await gettingStartedPage.doesContainerExist()) {
|
||||
await gettingStartedPage.optOut();
|
||||
throw new Error('Retrying after receiving Getting Started page');
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(function (currentUrl) {
|
||||
currentUrl = currentUrl.replace(/\/\/\w+:\w+@/, '//');
|
||||
.then(async function () {
|
||||
const currentUrl = (await remote.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');
|
||||
const maxAdditionalLengthOnNavUrl = 230;
|
||||
// On several test failures at the end of the TileMap test we try to navigate back to
|
||||
// Visualize so we can create the next Vertical Bar Chart, but we can see from the
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
export function GettingStartedPageProvider({ getService }) {
|
||||
|
||||
const log = getService('log');
|
||||
const retry = getService('retry');
|
||||
const testSubjects = getService('testSubjects');
|
||||
|
||||
class GettingStartedPage {
|
||||
async clickOptOutLink() {
|
||||
async doesContainerExist() {
|
||||
return await testSubjects.exists('gettingStartedContainer');
|
||||
}
|
||||
|
||||
async optOut() {
|
||||
log.debug('Clicking opt-out link');
|
||||
await testSubjects.click('lnkGettingStartedOptOut');
|
||||
await retry.try(async () => {
|
||||
if (await this.doesContainerExist()) {
|
||||
throw new Error('Still on getting started page');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new GettingStartedPage();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue