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

Conversation

spalger
Copy link
Contributor

@spalger spalger commented May 17, 2017

When running the functional tests, before finishing navigations, check if the getting started page is visible and if so opt out of it.

return await testSubjects.exists('gettingStartedContainer');
}

async outOut() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: should be optOut.

@spalger spalger force-pushed the fix/opt-out-of-getting-started-on-navigation branch from 9b4e19b to a7fae68 Compare May 17, 2017 23:28
@spalger spalger force-pushed the fix/opt-out-of-getting-started-on-navigation branch from a7fae68 to 1b77840 Compare May 17, 2017 23:29
@rashmivkulkarni
Copy link
Contributor

Pulled your changes and tested it locally. It opts out of the getting started link on navigation. LGTM .

Copy link
Contributor

@rashmivkulkarni rashmivkulkarni left a comment

Choose a reason for hiding this comment

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

LGTM- pulled your changes and tested it locally.

@ycombinator
Copy link
Contributor

@spalger how would this work for functional tests about the Getting Started page redirect functionality itself? For example, in #11850 I'm trying to write a test that attempts to navigate to the Discover page and expect to end up on the Getting Started page.

@ycombinator
Copy link
Contributor

Never mind, I suppose if I stay clear of navigateToApp() in my tests in #11850, I should be good.

@ycombinator
Copy link
Contributor

Ruh roh, CI appears to be failing around the Console functional tests: https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-selenium/4688/consoleFull

...
12:10:33.538      └- ✖ fail: "console app console app should show the default request"
12:10:33.542      │        tryForTime timeout: NoSuchElement: An element could not be located on the page using the given search parameters.
...

@spalger
Copy link
Contributor Author

spalger commented May 18, 2017

So, when you visit http://localhost:5601/app/kibana#/dev_tools/console before opt-out of the getting started page the getting started route setup work was calling kbnUrl.change() but then allowing the setup work promise to resolve. This means that the route change didn't go into effect until the next digest cycle and lead to the sense-welcome directive being rendered and then destroyed, which prevents it from showing a second time and broke the tests... Since #11246 is too complicated, and there isn't any other way to prevent this behavior without throwing an error, I updated the setup work to return promises that will never resolve, preventing the setup work from ever completing and the route from ever rendering. Then, on the next digest cycle, the new route (getting started page) will be detected and rendered without ever rendering the console.

@@ -68,14 +69,14 @@ uiRoutes
});
notify.error('Please create a new index pattern');
kbnUrl.change(CREATE_INDEX_PATTERN_ROUTE);
return;
return Promise.halt(); //prevent route resolve
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to explain for the benefit of our future selves why this is necessary via a comment in this file somewhere. Since this is being done in a couple of places maybe we can extract a function here that changes the route and return a halted promise?

@spalger spalger force-pushed the fix/opt-out-of-getting-started-on-navigation branch 2 times, most recently from 27a6773 to 9dc3498 Compare May 18, 2017 04:07
@@ -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?

@spalger spalger force-pushed the fix/opt-out-of-getting-started-on-navigation branch from 9dc3498 to f88c940 Compare May 18, 2017 04:08
@@ -2,9 +2,11 @@ import RouteManager from './route_manager';
import 'angular-route/angular-route';
import { uiModules } from 'ui/modules';
const defaultRouteManager = new RouteManager();
import { ABORT_SETUP_WORK_TOKEN } from './route_setup_manager';
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean this to be 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.

Oops


// prevent moving forward, return a promise that never resolves
// so that the $router can observe the $location update
return Promise.halt();
Copy link
Contributor

Choose a reason for hiding this comment

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

Super minor nit, but this seems more like the "early exit" exception, and throwing the error seems more like the default flow, so I'd suggest swapping the two:

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;

@@ -1,6 +1,8 @@
import _ from 'lodash';

module.exports = class RouteSetupManager {
export const WAIT_FOR_URL_CHANGE_TOKEN = new Error('WAIT_FOR_URL_CHANGE_TOKEN');
Copy link
Contributor

Choose a reason for hiding this comment

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

If I were coming across this code, I'd end up here, where this token is defined, to try to understand why and how to use it. Maybe just leave a comment here, explaining its role?

// Throw this inside of an Angular route resolver after calling `kbnUrl.change` so that the $router can
// observe the $location update. Otherwise, the location won't be updated.
export const WAIT_FOR_URL_CHANGE_TOKEN = new Error('WAIT_FOR_URL_CHANGE_TOKEN');

@cjcenizal
Copy link
Contributor

@spalger This is a really nice elegant solution! I found it really easy to follow and understand. Thanks for CCing me and letting me take a look.

@spalger spalger merged commit c9c8e8d into elastic:master May 19, 2017
spalger added a commit that referenced this pull request May 19, 2017
* [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

(cherry picked from commit c9c8e8d)
@spalger
Copy link
Contributor Author

spalger commented May 19, 2017

5.5/5.x: 3f181d1

@spalger spalger deleted the fix/opt-out-of-getting-started-on-navigation branch May 19, 2017 02:34
snide pushed a commit to snide/kibana that referenced this pull request May 30, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants