Skip to content

Commit

Permalink
[Uptime] [Test] Add functional test for monitor with location name bu…
Browse files Browse the repository at this point in the history
…t no geo (#55915)

* Add unit test for missing geo on named location.

* WIP writing a functional test.

* New named-location with no geo data test is functioning.

* Update snaps for functional test attribute.

* Rename test.

* Remove unnecessary async syntax.

* Delete unneeded symbols.

* Remove unnecessary boolean conversion.

* Fix typo in a comment.
  • Loading branch information
justinkambic authored Jan 29, 2020
1 parent 90ad260 commit e7899ff
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,20 @@ describe('LocationMap component', () => {
const warningComponent = component.find(LocationMissingWarning);
expect(warningComponent).toHaveLength(0);
});

it('renders named locations that have missing geo data', () => {
monitorLocations = {
monitorId: 'wapo',
locations: [
{
summary: { up: 4, down: 0 },
geo: { name: 'New York', location: undefined },
timestamp: '2020-01-13T22:50:06.536Z',
},
],
};

const component = shallowWithIntl(<LocationMap monitorLocations={monitorLocations} />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const LocationMissingWarning = () => {
);

return (
<EuiFlexGroup gutterSize="none">
<EuiFlexGroup data-test-subj="xpack.uptime.locationMap.locationMissing" gutterSize="none">
<EuiFlexItem grow={false} style={{ marginLeft: 'auto', marginRight: 20 }}>
<EuiPopover
id="popover"
Expand Down
24 changes: 16 additions & 8 deletions x-pack/test/functional/apps/uptime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ export default ({ loadTestFile, getService }: FtrProviderContext) => {
const kibanaServer = getService('kibanaServer');

describe('Uptime app', function() {
before(async () => {
await esArchiver.load(ARCHIVE);
await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'UTC' });
});
after(async () => await esArchiver.unload(ARCHIVE));
this.tags('ciGroup6');
describe('with generated data', () => {
before('load heartbeat data', async () => await esArchiver.load('uptime/blank'));
after('unload', async () => await esArchiver.unload('uptime/blank'));

loadTestFile(require.resolve('./locations'));
});
describe('with real-world data', () => {
before(async () => {
await esArchiver.load(ARCHIVE);
await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'UTC' });
});
after(async () => await esArchiver.unload(ARCHIVE));

loadTestFile(require.resolve('./feature_controls'));
loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./monitor'));
loadTestFile(require.resolve('./feature_controls'));
loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./monitor'));
});
});
};
48 changes: 48 additions & 0 deletions x-pack/test/functional/apps/uptime/locations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 { makeChecksWithStatus } from '../../../api_integration/apis/uptime/graphql/helpers/make_checks';
import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['uptime']);

describe('location', () => {
const start = new Date().toISOString();
const end = new Date().toISOString();

const MONITOR_ID = 'location-testing-id';
before(async () => {
/**
* This mogrify function will strip the documents of their location
* data (but preserve their location name), which is necessary for
* this test to work as desired.
* @param d current document
*/
const mogrifyNoLocation = (d: any) => {
if (d.observer?.geo?.location) {
d.observer.geo.location = undefined;
}
return d;
};
await makeChecksWithStatus(
getService('legacyEs'),
MONITOR_ID,
5,
2,
10000,
{},
'up',
mogrifyNoLocation
);
});

it('renders the location missing popover when monitor has location name, but no geo data', async () => {
await pageObjects.uptime.loadDataAndGoToMonitorPage(start, end, MONITOR_ID);
await pageObjects.uptime.locationMissingIsDisplayed();
});
});
};
11 changes: 9 additions & 2 deletions x-pack/test/functional/page_objects/uptime_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ export function UptimePageProvider({ getPageObjects, getService }: FtrProviderCo
datePickerStartValue: string,
datePickerEndValue: string,
monitorId: string,
monitorName: string
monitorName?: string
) {
await pageObjects.common.navigateToApp('uptime');
await pageObjects.timePicker.setAbsoluteRange(datePickerStartValue, datePickerEndValue);
await uptimeService.navigateToMonitorWithId(monitorId);
if ((await uptimeService.getMonitorNameDisplayedOnPageTitle()) !== monitorName) {
if (
monitorName &&
(await uptimeService.getMonitorNameDisplayedOnPageTitle()) !== monitorName
) {
throw new Error('Expected monitor name not found');
}
}
Expand Down Expand Up @@ -89,5 +92,9 @@ export function UptimePageProvider({ getPageObjects, getService }: FtrProviderCo
public async getSnapshotCount() {
return await uptimeService.getSnapshotCount();
}

public locationMissingIsDisplayed() {
return uptimeService.locationMissingExists();
}
})();
}
7 changes: 6 additions & 1 deletion x-pack/test/functional/services/uptime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function UptimeProvider({ getService }: FtrProviderContext) {
return url.indexOf(expected) >= 0;
},
async navigateToMonitorWithId(monitorId: string) {
await testSubjects.click(`monitor-page-link-${monitorId}`);
await testSubjects.click(`monitor-page-link-${monitorId}`, 5000);
},
async getMonitorNameDisplayedOnPageTitle() {
return await testSubjects.getVisibleText('monitor-page-title');
Expand Down Expand Up @@ -64,5 +64,10 @@ export function UptimeProvider({ getService }: FtrProviderContext) {
down: await testSubjects.getVisibleText('xpack.uptime.snapshot.donutChart.down'),
};
},
async locationMissingExists() {
return await testSubjects.existOrFail('xpack.uptime.locationMap.locationMissing', {
timeout: 3000,
});
},
};
}

0 comments on commit e7899ff

Please sign in to comment.