Skip to content

Commit

Permalink
[Infra UI] functional browser test for infraops page (#24248)
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort authored Oct 22, 2018
1 parent 914bf52 commit 744edd9
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 2 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/infra/public/components/empty_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ interface EmptyPageProps {
title: string;
actionLabel: string;
actionUrl: string;
'data-test-subj'?: string;
}

export const EmptyPage: React.SFC<EmptyPageProps> = ({
actionLabel,
actionUrl,
message,
title,
...rest
}) => (
<EuiEmptyPrompt
title={<h2>{title}</h2>}
Expand All @@ -28,5 +30,6 @@ export const EmptyPage: React.SFC<EmptyPageProps> = ({
{actionLabel}
</EuiButton>
}
{...rest}
/>
);
6 changes: 5 additions & 1 deletion x-pack/plugins/infra/public/components/waffle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class Waffle extends React.Component<Props, {}> {
Check for new data
</EuiButton>
}
data-test-subj="noMetricsDataPrompt"
/>
);
}
Expand All @@ -124,7 +125,10 @@ export class Waffle extends React.Component<Props, {}> {
{({ measureRef, content: { width = 0, height = 0 } }) => {
const groupsWithLayout = applyWaffleMapLayout(map, width, height);
return (
<WaffleMapOuterContiner innerRef={(el: any) => measureRef(el)}>
<WaffleMapOuterContiner
innerRef={(el: any) => measureRef(el)}
data-test-subj="waffleMap"
>
<WaffleMapInnerContainer>
{groupsWithLayout.map(this.renderGroup(bounds))}
</WaffleMapInnerContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class WaffleTimeControls extends React.Component<WaffleTimeControlsProps>
);

return (
<EuiFormControlLayout append={liveStreamingButton}>
<EuiFormControlLayout append={liveStreamingButton} data-test-subj="waffleDatePicker">
<EuiDatePicker
className="euiFieldText--inGroup"
dateFormat="L LTS"
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class HomePage extends React.PureComponent {
message="Let's add some!"
actionLabel="Setup Instructions"
actionUrl={`${basePath}/app/kibana#/home/tutorial_directory/metrics`}
data-test-subj="noMetricsIndicesPrompt"
/>
)}
</WithKibanaChrome>
Expand Down
45 changes: 45 additions & 0 deletions x-pack/test/functional/apps/infra/home_page.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
};
14 changes: 14 additions & 0 deletions x-pack/test/functional/apps/infra/index.ts
Original file line number Diff line number Diff line change
@@ -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'));
});
};
6 changes: 6 additions & 0 deletions x-pack/test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ReportingPageProvider,
SpaceSelectorPageProvider,
AccountSettingProvider,
InfraHomePageProvider,
} from './page_objects';

import {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -118,6 +120,7 @@ export default async function ({ readConfigFile }) {
watcher: WatcherPageProvider,
reporting: ReportingPageProvider,
spaceSelector: SpaceSelectorPageProvider,
infraHome: InfraHomePageProvider,
},

servers: kibanaFunctionalConfig.get('servers'),
Expand Down Expand Up @@ -168,6 +171,9 @@ export default async function ({ readConfigFile }) {
},
spaceSelector: {
pathname: '/',
},
infraOps: {
pathname: '/app/infra'
}
},

Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/page_objects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
39 changes: 39 additions & 0 deletions x-pack/test/functional/page_objects/infra_home_page.ts
Original file line number Diff line number Diff line change
@@ -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');
},
};
}
12 changes: 12 additions & 0 deletions x-pack/test/types/leadfoot.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions x-pack/test/types/providers.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
unload(archiveName: string): Promise<void>;
}

export interface KibanaFunctionalTestDefaultProviders {
getService(serviceName: 'esArchiver'): EsArchiver;
getService(serviceName: string): any;
getPageObjects(pageObjectNames: string[]): any;
loadTestFile(path: string): void;
}

0 comments on commit 744edd9

Please sign in to comment.