Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests/functional] opt out of getting started on navigation #11881

Merged
Merged
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="kuiViewContent gettingStartedContent">
<div class="kuiViewContent gettingStartedContent" data-test-subj="gettingStartedContainer">

<div
ng-if="!gettingStarted.hasOptedOut()"
Expand Down
11 changes: 5 additions & 6 deletions src/core_plugins/getting_started/public/lib/add_setup_work.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ycombinator I tried a different approach, throwing this token from within a route setup work function will halt the setup work, allowing it to wait for kbnUrl to change. What do you think?

/cc @cjcenizal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spalger Do you think this throw should just become part of the kbnUrl.change function? It seems to me the two would always want to travel together, no?

}

// 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;
}
});
});
});
2 changes: 1 addition & 1 deletion src/ui/public/routes/route_manager.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 16 additions & 2 deletions src/ui/public/routes/route_setup_manager.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -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 changes: 2 additions & 0 deletions src/ui/public/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
6 changes: 2 additions & 4 deletions test/functional/apps/console/_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
36 changes: 20 additions & 16 deletions test/functional/page_objects/common_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions test/functional/page_objects/getting_started_page.js
Original file line number Diff line number Diff line change
@@ -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();
}
}