[Uptime] [Test] Add functional test for monitor with location name but no geo (#55915) (#56331)

* 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.
This commit is contained in:
Justin Kambic 2020-01-29 14:07:29 -07:00 committed by GitHub
parent b93d77eb3f
commit 7ae3221f01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 12 deletions

View file

@ -143,6 +143,45 @@ exports[`LocationMap component renders correctly against snapshot 1`] = `
</EuiErrorBoundary>
`;
exports[`LocationMap component renders named locations that have missing geo data 1`] = `
<EuiErrorBoundary>
<EuiFlexGroup>
<EuiFlexItem
grow={false}
>
<LocationStatusTags
locations={
Array [
Object {
"geo": Object {
"location": undefined,
"name": "New York",
},
"summary": Object {
"down": 0,
"up": 4,
},
"timestamp": "2020-01-13T22:50:06.536Z",
},
]
}
/>
</EuiFlexItem>
<EuiFlexItem
grow={true}
>
<LocationMissingWarning />
<styled.div>
<EmbeddedMap
downPoints={Array []}
upPoints={Array []}
/>
</styled.div>
</EuiFlexItem>
</EuiFlexGroup>
</EuiErrorBoundary>
`;
exports[`LocationMap component shows warning if geo information is missing 1`] = `
<EuiErrorBoundary>
<EuiFlexGroup>

View file

@ -3,6 +3,7 @@
exports[`LocationMissingWarning component renders correctly against snapshot 1`] = `
<div
class="euiFlexGroup euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="xpack.uptime.locationMap.locationMissing"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
@ -47,6 +48,7 @@ exports[`LocationMissingWarning component renders correctly against snapshot 1`]
exports[`LocationMissingWarning component shallow render correctly against snapshot 1`] = `
<EuiFlexGroup
data-test-subj="xpack.uptime.locationMap.locationMissing"
gutterSize="none"
>
<EuiFlexItem

View file

@ -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();
});
});

View file

@ -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"

View file

@ -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('./feature_controls'));
loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./monitor'));
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'));
});
});
};

View file

@ -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();
});
});
};

View file

@ -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');
}
}
@ -89,5 +92,9 @@ export function UptimePageProvider({ getPageObjects, getService }: FtrProviderCo
public async getSnapshotCount() {
return await uptimeService.getSnapshotCount();
}
public locationMissingIsDisplayed() {
return uptimeService.locationMissingExists();
}
})();
}

View file

@ -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');
@ -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,
});
},
};
}