From 744edd9c9d17c343a0ca480bef245aa5cf3d5e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Mon, 22 Oct 2018 22:17:48 +0200 Subject: [PATCH] [Infra UI] functional browser test for infraops page (#24248) --- .../infra/public/components/empty_page.tsx | 3 ++ .../infra/public/components/waffle/index.tsx | 6 ++- .../waffle/waffle_time_controls.tsx | 2 +- .../plugins/infra/public/pages/home/index.tsx | 1 + .../test/functional/apps/infra/home_page.ts | 45 +++++++++++++++++++ x-pack/test/functional/apps/infra/index.ts | 14 ++++++ x-pack/test/functional/config.js | 6 +++ x-pack/test/functional/page_objects/index.js | 1 + .../page_objects/infra_home_page.ts | 39 ++++++++++++++++ x-pack/test/types/leadfoot.d.ts | 12 +++++ x-pack/test/types/providers.ts | 21 +++++++++ 11 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 x-pack/test/functional/apps/infra/home_page.ts create mode 100644 x-pack/test/functional/apps/infra/index.ts create mode 100644 x-pack/test/functional/page_objects/infra_home_page.ts create mode 100644 x-pack/test/types/leadfoot.d.ts create mode 100644 x-pack/test/types/providers.ts diff --git a/x-pack/plugins/infra/public/components/empty_page.tsx b/x-pack/plugins/infra/public/components/empty_page.tsx index ed29ad2e6f75f..c13d795493c26 100644 --- a/x-pack/plugins/infra/public/components/empty_page.tsx +++ b/x-pack/plugins/infra/public/components/empty_page.tsx @@ -12,6 +12,7 @@ interface EmptyPageProps { title: string; actionLabel: string; actionUrl: string; + 'data-test-subj'?: string; } export const EmptyPage: React.SFC = ({ @@ -19,6 +20,7 @@ export const EmptyPage: React.SFC = ({ actionUrl, message, title, + ...rest }) => ( {title}} @@ -28,5 +30,6 @@ export const EmptyPage: React.SFC = ({ {actionLabel} } + {...rest} /> ); diff --git a/x-pack/plugins/infra/public/components/waffle/index.tsx b/x-pack/plugins/infra/public/components/waffle/index.tsx index 8503a73eb765a..f379540419c8a 100644 --- a/x-pack/plugins/infra/public/components/waffle/index.tsx +++ b/x-pack/plugins/infra/public/components/waffle/index.tsx @@ -109,6 +109,7 @@ export class Waffle extends React.Component { Check for new data } + data-test-subj="noMetricsDataPrompt" /> ); } @@ -124,7 +125,10 @@ export class Waffle extends React.Component { {({ measureRef, content: { width = 0, height = 0 } }) => { const groupsWithLayout = applyWaffleMapLayout(map, width, height); return ( - measureRef(el)}> + measureRef(el)} + data-test-subj="waffleMap" + > {groupsWithLayout.map(this.renderGroup(bounds))} diff --git a/x-pack/plugins/infra/public/components/waffle/waffle_time_controls.tsx b/x-pack/plugins/infra/public/components/waffle/waffle_time_controls.tsx index 9453f636b9b4e..6331f86d24331 100644 --- a/x-pack/plugins/infra/public/components/waffle/waffle_time_controls.tsx +++ b/x-pack/plugins/infra/public/components/waffle/waffle_time_controls.tsx @@ -38,7 +38,7 @@ export class WaffleTimeControls extends React.Component ); return ( - + )} diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts new file mode 100644 index 0000000000000..d7efdb85838df --- /dev/null +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { KibanaFunctionalTestDefaultProviders } from '../../../types/providers'; + +const DATE_WITH_DATA = new Date(1539806283000); +const DATE_WITHOUT_DATA = new Date(1539122400000); + +// tslint:disable-next-line:no-default-export +export default ({ getPageObjects, getService }: KibanaFunctionalTestDefaultProviders) => { + const esArchiver = getService('esArchiver'); + const pageObjects = getPageObjects(['common', 'infraHome']); + + describe('Home page', () => { + describe('without metrics present', () => { + before(async () => await esArchiver.unload('infra')); + + it('renders an empty data prompt', async () => { + await pageObjects.common.navigateToApp('infraOps'); + await pageObjects.infraHome.getNoMetricsIndicesPrompt(); + }); + }); + + describe('with metrics present', () => { + before(async () => { + await esArchiver.load('infra'); + await pageObjects.common.navigateToApp('infraOps'); + }); + after(async () => await esArchiver.unload('infra')); + + it('renders the waffle map for dates with data', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + }); + + it('renders an empty data prompt for dates with no data', async () => { + await pageObjects.infraHome.goToTime(DATE_WITHOUT_DATA); + await pageObjects.infraHome.getNoMetricsDataPrompt(); + }); + }); + }); +}; diff --git a/x-pack/test/functional/apps/infra/index.ts b/x-pack/test/functional/apps/infra/index.ts new file mode 100644 index 0000000000000..efb3cc9f276bc --- /dev/null +++ b/x-pack/test/functional/apps/infra/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { KibanaFunctionalTestDefaultProviders } from '../../../types/providers'; + +// tslint:disable-next-line:no-default-export +export default ({ loadTestFile }: KibanaFunctionalTestDefaultProviders) => { + describe('InfraOps app', () => { + loadTestFile(require.resolve('./home_page')); + }); +}; diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index 33b0106f5dd2f..90e0aae8c093f 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -18,6 +18,7 @@ import { ReportingPageProvider, SpaceSelectorPageProvider, AccountSettingProvider, + InfraHomePageProvider, } from './page_objects'; import { @@ -69,6 +70,7 @@ export default async function ({ readConfigFile }) { resolve(__dirname, './apps/spaces'), resolve(__dirname, './apps/logstash'), resolve(__dirname, './apps/grok_debugger'), + resolve(__dirname, './apps/infra'), ], // define the name and providers for services that should be @@ -118,6 +120,7 @@ export default async function ({ readConfigFile }) { watcher: WatcherPageProvider, reporting: ReportingPageProvider, spaceSelector: SpaceSelectorPageProvider, + infraHome: InfraHomePageProvider, }, servers: kibanaFunctionalConfig.get('servers'), @@ -168,6 +171,9 @@ export default async function ({ readConfigFile }) { }, spaceSelector: { pathname: '/', + }, + infraOps: { + pathname: '/app/infra' } }, diff --git a/x-pack/test/functional/page_objects/index.js b/x-pack/test/functional/page_objects/index.js index 3ad10d395997c..d6654fec9f9be 100644 --- a/x-pack/test/functional/page_objects/index.js +++ b/x-pack/test/functional/page_objects/index.js @@ -13,3 +13,4 @@ export { WatcherPageProvider } from './watcher_page'; export { ReportingPageProvider } from './reporting_page'; export { SpaceSelectorPageProvider } from './space_selector_page'; export { AccountSettingProvider } from './accountsetting_page'; +export { InfraHomePageProvider } from './infra_home_page'; diff --git a/x-pack/test/functional/page_objects/infra_home_page.ts b/x-pack/test/functional/page_objects/infra_home_page.ts new file mode 100644 index 0000000000000..1ca44180622e8 --- /dev/null +++ b/x-pack/test/functional/page_objects/infra_home_page.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import testSubjSelector from '@kbn/test-subj-selector'; +import Keys from 'leadfoot/keys'; +import moment from 'moment'; + +import { KibanaFunctionalTestDefaultProviders } from '../../types/providers'; + +export function InfraHomePageProvider({ getService }: KibanaFunctionalTestDefaultProviders) { + const testSubjects = getService('testSubjects'); + const find = getService('find'); + + return { + async goToTime(time: number) { + const datePickerInput = await find.byCssSelector( + `${testSubjSelector('waffleDatePicker')} .euiDatePicker.euiFieldText` + ); + + await datePickerInput.type(Array(30).fill(Keys.BACKSPACE)); + await datePickerInput.type([moment(time).format('L LTS'), Keys.RETURN]); + }, + + async getWaffleMap() { + return await testSubjects.find('waffleMap'); + }, + + async getNoMetricsIndicesPrompt() { + return await testSubjects.find('noMetricsIndicesPrompt'); + }, + + async getNoMetricsDataPrompt() { + return await testSubjects.find('noMetricsDataPrompt'); + }, + }; +} diff --git a/x-pack/test/types/leadfoot.d.ts b/x-pack/test/types/leadfoot.d.ts new file mode 100644 index 0000000000000..a9a081afa8114 --- /dev/null +++ b/x-pack/test/types/leadfoot.d.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +declare module 'leadfoot/keys' { + type LeadfootKeys = 'BACKSPACE' | 'ENTER' | 'RETURN'; + + const keys: { [key in LeadfootKeys]: string }; + export default keys; +} diff --git a/x-pack/test/types/providers.ts b/x-pack/test/types/providers.ts new file mode 100644 index 0000000000000..6865fece8605a --- /dev/null +++ b/x-pack/test/types/providers.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export interface EsArchiverOptions { + skipExisting?: boolean; +} + +export interface EsArchiver { + load(archiveName: string, options?: EsArchiverOptions): Promise; + unload(archiveName: string): Promise; +} + +export interface KibanaFunctionalTestDefaultProviders { + getService(serviceName: 'esArchiver'): EsArchiver; + getService(serviceName: string): any; + getPageObjects(pageObjectNames: string[]): any; + loadTestFile(path: string): void; +}