Skip to content

Commit

Permalink
[Uptime] Update Ml functional test (#62562)
Browse files Browse the repository at this point in the history
* update test

* added test

* updated type

* updated test

* updated test

* update test

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
shahzad31 and elasticmachine authored Apr 13, 2020
1 parent 61271c0 commit c7f61f9
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect } from 'react';
import React, { useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { indexStatusAction } from '../../../state/actions';
import { indexStatusSelector } from '../../../state/selectors';
import { EmptyStateComponent } from '../../functional/empty_state/empty_state';
import { UptimeRefreshContext } from '../../../contexts';

export const EmptyState: React.FC = ({ children }) => {
const { data, loading, error } = useSelector(indexStatusSelector);
const { lastRefresh } = useContext(UptimeRefreshContext);

const dispatch = useDispatch();

useEffect(() => {
dispatch(indexStatusAction.get());
}, [dispatch]);
}, [dispatch, lastRefresh]);

return (
<EmptyStateComponent
Expand Down

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.

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.

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 @@ -25,6 +25,7 @@ export const ConfirmJobDeletion: React.FC<Props> = ({ loading, onConfirm, onCanc
confirmButtonText="Delete"
buttonColor="danger"
defaultFocusedButton="confirm"
data-test-subj="uptimeMLJobDeleteConfirmModel"
>
{!loading ? (
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ShowLicenseInfo = () => {
return (
<>
<EuiCallOut
data-test-subj="uptimeMLLicenseInfo"
className="license-info-trial"
title={labels.START_TRAIL}
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro

const button = (
<EuiButtonEmpty
data-test-subj={hasMLJob ? 'uptimeManageMLJobBtn' : 'uptimeEnableAnomalyBtn'}
iconType={hasMLJob ? 'arrowDown' : 'machineLearningApp'}
iconSide={hasMLJob ? 'right' : 'left'}
onClick={hasMLJob ? () => setIsPopOverOpen(true) : onEnableJob}
Expand All @@ -60,6 +61,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
},
{
name: labels.DISABLE_ANOMALY_DETECTION,
'data-test-subj': 'uptimeDeleteMLJobBtn',
icon: <EuiIcon type="trash" size="m" />,
onClick: () => {
setIsPopOverOpen(false);
Expand All @@ -72,7 +74,11 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro

return (
<EuiPopover button={button} isOpen={isPopOverOpen} closePopover={() => setIsPopOverOpen(false)}>
<EuiContextMenu initialPanelId={0} panels={panels} />
<EuiContextMenu
initialPanelId={0}
panels={panels}
data-test-subj="uptimeManageMLContextMenu"
/>
</EuiPopover>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function MLFlyoutView({ isCreatingJob, onClickCreate, onClose, canCreateM
const hasPlatinumLicense = license?.getFeature('ml')?.isAvailable;

return (
<EuiFlyout onClose={onClose} size="s">
<EuiFlyout onClose={onClose} size="s" data-test-subj="uptimeMLFlyout">
<EuiFlyoutHeader>
<EuiTitle>
<h2>{labels.ENABLE_ANOMALY_DETECTION}</h2>
Expand Down Expand Up @@ -76,6 +76,7 @@ export function MLFlyoutView({ isCreatingJob, onClickCreate, onClose, canCreateM
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="uptimeMLCreateJobBtn"
onClick={() => onClickCreate()}
fill
isLoading={isCreatingJob}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const showMLJobNotification = (
) => {
if (success) {
notifications.toasts.success({
title: <p>{labels.JOB_CREATED_SUCCESS_TITLE}</p>,
title: (
<p data-test-subj="uptimeMLJobSuccessfullyCreated">{labels.JOB_CREATED_SUCCESS_TITLE}</p>
),
body: (
<p>
{labels.JOB_CREATED_SUCCESS_MESSAGE}
Expand All @@ -54,7 +56,7 @@ const showMLJobNotification = (
});
} else {
notifications.toasts.danger({
title: <p>{labels.JOB_CREATION_FAILED}</p>,
title: <p data-test-subj="uptimeMLJobCreationFailed">{labels.JOB_CREATION_FAILED}</p>,
body: message ?? <p>{labels.JOB_CREATION_FAILED_MESSAGE}</p>,
toastLifeTimeMs: 10000,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const MLIntegrationComponent = () => {
if (isConfirmDeleteJobOpen && jobDeletionSuccess?.[getMLJobId(monitorId as string)]?.deleted) {
setIsConfirmDeleteJobOpen(false);
notifications.toasts.success({
title: <p>{labels.JOB_DELETION}</p>,
title: <p data-test-subj="uptimeMLJobSuccessfullyDeleted">{labels.JOB_DELETION}</p>,
body: <p>{labels.JOB_DELETION_SUCCESS}</p>,
toastLifeTimeMs: 3000,
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/uptime/public/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const SettingsPageComponent = ({

return (
<>
<Link to={OVERVIEW_ROUTE}>
<Link to={OVERVIEW_ROUTE} data-test-subj="uptimeSettingsToOverviewLink">
<EuiButtonEmpty size="s" color="primary" iconType="arrowLeft">
{i18n.translate('xpack.uptime.settings.returnToOverviewLinkLabel', {
defaultMessage: 'Return to overview',
Expand Down
5 changes: 4 additions & 1 deletion x-pack/test/functional/apps/uptime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default ({ loadTestFile, getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const server = getService('kibanaServer');
const uptime = getService('uptime');

describe('Uptime app', function() {
this.tags('ciGroup6');
Expand Down Expand Up @@ -58,12 +59,14 @@ export default ({ loadTestFile, getService }: FtrProviderContext) => {
await esArchiver.unload(ARCHIVE);
await esArchiver.load(ARCHIVE);
await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'UTC' });
await uptime.navigation.goToUptime();
});
after(async () => await esArchiver.unload(ARCHIVE));

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

export default ({ getService }: FtrProviderContext) => {
const uptime = getService('uptime');
const log = getService('log');

describe('uptime ml anomaly', function() {
this.tags(['skipFirefox']);
const dateStart = 'Sep 10, 2019 @ 12:40:08.078';
const dateEnd = 'Sep 11, 2019 @ 19:40:08.078';
const monitorId = '0000-intermittent';

before(async () => {
if (!(await uptime.navigation.checkIfOnMonitorPage(monitorId))) {
await uptime.navigation.loadDataAndGoToMonitorPage(dateStart, dateEnd, monitorId);
}
if (await uptime.ml.alreadyHasJob()) {
log.info('Jon already exists so lets delete it to start fresh.');
await uptime.ml.deleteMLJob();
}
});

it('can open ml flyout', async () => {
await uptime.ml.openMLFlyout();
});

it('has permission to create job', async () => {
expect(uptime.ml.canCreateJob()).to.eql(true);
expect(uptime.ml.hasNoLicenseInfo()).to.eql(false);
});

it('can create job successfully', async () => {
await uptime.ml.createMLJob();
// await uptime.navigation.refreshApp();
});

it('can open ML Manage Menu', async () => {
await uptime.ml.openMLManageMenu();
});

it('can delete job successfully', async () => {
await uptime.ml.deleteMLJob();
});
});
};
7 changes: 1 addition & 6 deletions x-pack/test/functional/apps/uptime/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const dateStart = 'Sep 10, 2019 @ 12:40:08.078';
const dateEnd = 'Sep 11, 2019 @ 19:40:08.078';
const monitorId = '0000-intermittent';
const monitorName = '0000-intermittent';

before(async () => {
await esArchiver.loadIfNeeded(archive);
await uptimeService.navigation.goToUptime();
});

after(async () => {
await esArchiver.unload(archive);
});

it('loads and displays uptime data based on date range', async () => {
await uptime.loadDataAndGoToMonitorPage(dateStart, dateEnd, monitorId, monitorName);
await uptime.loadDataAndGoToMonitorPage(dateStart, dateEnd, monitorId);
});
});
};
24 changes: 13 additions & 11 deletions x-pack/test/functional/apps/uptime/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
describe('overview page', function() {
const DEFAULT_DATE_START = 'Sep 10, 2019 @ 12:40:08.078';
const DEFAULT_DATE_END = 'Sep 11, 2019 @ 19:40:08.078';

beforeEach(async () => {
await uptime.goToRoot();
await uptime.setDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.resetFilters();
});

it('loads and displays uptime data based on date range', async () => {
await uptime.goToUptimeOverviewAndLoadData(
DEFAULT_DATE_START,
Expand All @@ -22,13 +29,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
);
});

it('runs filter query without issues', async () => {
await uptime.inputFilterQuery('monitor.status:up and monitor.id:"0000-intermittent"');
await uptime.pageHasExpectedIds(['0000-intermittent']);
});

it('applies filters for multiple fields', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.selectFilterItems({
location: ['mpls'],
port: ['5678'],
Expand All @@ -49,7 +50,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('pagination is cleared when filter criteria changes', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.changePage('next');
await uptime.pageHasExpectedIds([
'0010-down',
Expand Down Expand Up @@ -83,7 +83,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('clears pagination parameters when size changes', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.changePage('next');
await uptime.pageUrlContains('pagination');
await uptime.setMonitorListPageSize(50);
Expand All @@ -92,7 +91,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('pagination size updates to reflect current selection', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.pageHasExpectedIds([
'0000-intermittent',
'0001-up',
Expand Down Expand Up @@ -162,7 +160,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('snapshot counts', () => {
it('updates the snapshot count when status filter is set to down', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.setStatusFilter('down');

await retry.tryForTime(12000, async () => {
Expand All @@ -172,13 +169,18 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('updates the snapshot count when status filter is set to up', async () => {
await uptime.goToUptimePageAndSetDateRange(DEFAULT_DATE_START, DEFAULT_DATE_END);
await uptime.setStatusFilter('up');
await retry.tryForTime(12000, async () => {
const counts = await uptime.getSnapshotCount();
expect(counts).to.eql({ up: '93', down: '0' });
});
});

it('runs filter query without issues', async () => {
await uptime.inputFilterQuery('monitor.status:up and monitor.id:"0000-intermittent"');
await uptime.pageHasExpectedIds(['0000-intermittent']);
await uptime.resetFilters();
});
});
});
};
Loading

0 comments on commit c7f61f9

Please sign in to comment.