From a193f4694b43eb81c7c39559849cb74a5940bade Mon Sep 17 00:00:00 2001 From: shahzad Date: Wed, 15 Apr 2020 17:05:24 +0200 Subject: [PATCH 1/7] update settings --- .../plugins/uptime/public/pages/settings.tsx | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx index 765b0e3c664bc0..a5953e0366f413 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx @@ -21,13 +21,11 @@ import { EuiTitle, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { connect } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { isEqual } from 'lodash'; import { i18n } from '@kbn/i18n'; import { Link } from 'react-router-dom'; -import { AppState } from '../state'; import { selectDynamicSettings } from '../state/selectors'; -import { DynamicSettingsState } from '../state/reducers/dynamic_settings'; import { getDynamicSettings, setDynamicSettings } from '../state/actions/dynamic_settings'; import { defaultDynamicSettings, DynamicSettings } from '../../common/runtime_types'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; @@ -35,20 +33,9 @@ import { OVERVIEW_ROUTE } from '../../common/constants'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; import { UptimePage, useUptimeTelemetry } from '../hooks'; -interface Props { - dynamicSettingsState: DynamicSettingsState; -} +export const SettingsPage = () => { + const dss = useSelector(selectDynamicSettings); -interface DispatchProps { - dispatchGetDynamicSettings: typeof getDynamicSettings; - dispatchSetDynamicSettings: typeof setDynamicSettings; -} - -export const SettingsPageComponent = ({ - dynamicSettingsState: dss, - dispatchGetDynamicSettings, - dispatchSetDynamicSettings, -}: Props & DispatchProps) => { const settingsBreadcrumbText = i18n.translate('xpack.uptime.settingsBreadcrumbText', { defaultMessage: 'Settings', }); @@ -56,9 +43,11 @@ export const SettingsPageComponent = ({ useUptimeTelemetry(UptimePage.Settings); + const dispatch = useDispatch(); + useEffect(() => { - dispatchGetDynamicSettings({}); - }, [dispatchGetDynamicSettings]); + dispatch(getDynamicSettings({})); + }, [dispatch]); const [formFields, setFormFields] = useState(dss.settings || null); @@ -81,7 +70,7 @@ export const SettingsPageComponent = ({ const onApply = (event: React.FormEvent) => { event.preventDefault(); if (formFields) { - dispatchSetDynamicSettings(formFields); + dispatch(setDynamicSettings(formFields)); } }; @@ -230,18 +219,3 @@ export const SettingsPageComponent = ({ ); }; - -const mapStateToProps = (state: AppState) => ({ - dynamicSettingsState: selectDynamicSettings(state), -}); - -const mapDispatchToProps = (dispatch: any) => ({ - dispatchGetDynamicSettings: () => { - return dispatch(getDynamicSettings({})); - }, - dispatchSetDynamicSettings: (settings: DynamicSettings) => { - return dispatch(setDynamicSettings(settings)); - }, -}); - -export const SettingsPage = connect(mapStateToProps, mapDispatchToProps)(SettingsPageComponent); From 3f3ea121f6fc766616bb2a593c9eb83aa9de1839 Mon Sep 17 00:00:00 2001 From: shahzad Date: Wed, 15 Apr 2020 20:25:07 +0200 Subject: [PATCH 2/7] added cert form --- .../components/settings/certificate_form.tsx | 136 ++++++++++++++++++ .../components/settings/indices_form.tsx | 84 +++++++++++ .../plugins/uptime/public/pages/settings.tsx | 82 ++--------- 3 files changed, 235 insertions(+), 67 deletions(-) create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/indices_form.tsx diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx new file mode 100644 index 00000000000000..6f0b58029224fe --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx @@ -0,0 +1,136 @@ +/* + * 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 React from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { useSelector } from 'react-redux'; +import { + EuiDescribedFormGroup, + EuiFormRow, + EuiCode, + EuiFieldNumber, + EuiTitle, + EuiSpacer, + EuiSelect, + EuiFlexGroup, + EuiFlexItem, +} from '@elastic/eui'; +import { defaultDynamicSettings } from '../../../common/runtime_types'; +import { selectDynamicSettings } from '../../state/selectors'; + +export const CertificateExpirationForm: React.FC = ({ + onChange, + formFields, + fieldErrors, + isDisabled, +}) => { + const dss = useSelector(selectDynamicSettings); + + return ( + <> + +

+ +

+
+ + + + + } + description={ + + } + > + {defaultDynamicSettings.heartbeatIndices}, + }} + /> + } + isInvalid={!!fieldErrors?.heartbeatIndices} + label={ + + } + > + + + onChange('heartbeatIndices', event.currentTarget.value)} + /> + + + + + + + {defaultDynamicSettings.heartbeatIndices}, + }} + /> + } + isInvalid={!!fieldErrors?.heartbeatIndices} + label={ + + } + > + + + onChange('heartbeatIndices', event.currentTarget.value)} + /> + + + + + + + + + ); +}; diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/indices_form.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/indices_form.tsx new file mode 100644 index 00000000000000..97508521f57ba5 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/indices_form.tsx @@ -0,0 +1,84 @@ +/* + * 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 React from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { useSelector } from 'react-redux'; +import { + EuiDescribedFormGroup, + EuiFormRow, + EuiCode, + EuiFieldText, + EuiTitle, + EuiSpacer, +} from '@elastic/eui'; +import { defaultDynamicSettings } from '../../../common/runtime_types'; +import { selectDynamicSettings } from '../../state/selectors'; + +export const IndicesForm: React.FC = ({ onChange, formFields, fieldErrors, isDisabled }) => { + const dss = useSelector(selectDynamicSettings); + + return ( + <> + +

+ +

+
+ + + + + } + description={ + + } + > + {defaultDynamicSettings.heartbeatIndices}, + }} + /> + } + isInvalid={!!fieldErrors?.heartbeatIndices} + label={ + + } + > + onChange('heartbeatIndices', event.currentTarget.value)} + /> + + + + ); +}; diff --git a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx index a5953e0366f413..aa52fbf03419ce 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx @@ -9,13 +9,9 @@ import { EuiButton, EuiButtonEmpty, EuiCallOut, - EuiCode, - EuiDescribedFormGroup, - EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiForm, - EuiFormRow, EuiPanel, EuiSpacer, EuiTitle, @@ -27,11 +23,13 @@ import { i18n } from '@kbn/i18n'; import { Link } from 'react-router-dom'; import { selectDynamicSettings } from '../state/selectors'; import { getDynamicSettings, setDynamicSettings } from '../state/actions/dynamic_settings'; -import { defaultDynamicSettings, DynamicSettings } from '../../common/runtime_types'; +import { DynamicSettings } from '../../common/runtime_types'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; import { OVERVIEW_ROUTE } from '../../common/constants'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; import { UptimePage, useUptimeTelemetry } from '../hooks'; +import { IndicesForm } from '../components/settings/indices_form'; +import { CertificateExpirationForm } from '../components/settings/certificate_form'; export const SettingsPage = () => { const dss = useSelector(selectDynamicSettings); @@ -117,68 +115,18 @@ export const SettingsPage = () => {
- -

- -

-
- - - - - } - description={ - - } - > - {defaultDynamicSettings.heartbeatIndices} - ), - }} - /> - } - isInvalid={!!fieldErrors?.heartbeatIndices} - label={ - - } - > - - onChangeFormField('heartbeatIndices', event.currentTarget.value) - } - /> - - + + From f703b9449da2f40c0194e727e70809b3f5daa248 Mon Sep 17 00:00:00 2001 From: shahzad Date: Thu, 16 Apr 2020 00:22:42 +0200 Subject: [PATCH 3/7] update settings --- .../common/runtime_types/dynamic_settings.ts | 19 +++++- .../components/settings/certificate_form.tsx | 61 +++++++++++-------- .../plugins/uptime/public/pages/settings.tsx | 18 ++++-- .../uptime/server/lib/saved_objects.ts | 16 +++-- 4 files changed, 77 insertions(+), 37 deletions(-) diff --git a/x-pack/legacy/plugins/uptime/common/runtime_types/dynamic_settings.ts b/x-pack/legacy/plugins/uptime/common/runtime_types/dynamic_settings.ts index 8dedd4672eeaea..985b51891da99f 100644 --- a/x-pack/legacy/plugins/uptime/common/runtime_types/dynamic_settings.ts +++ b/x-pack/legacy/plugins/uptime/common/runtime_types/dynamic_settings.ts @@ -6,10 +6,20 @@ import * as t from 'io-ts'; -export const DynamicSettingsType = t.type({ - heartbeatIndices: t.string, +export const CertificatesStatesThresholdType = t.interface({ + warningState: t.number, + errorState: t.number, }); +export const DynamicSettingsType = t.intersection([ + t.type({ + heartbeatIndices: t.string, + }), + t.partial({ + certificatesThresholds: CertificatesStatesThresholdType, + }), +]); + export const DynamicSettingsSaveType = t.intersection([ t.type({ success: t.boolean, @@ -21,7 +31,12 @@ export const DynamicSettingsSaveType = t.intersection([ export type DynamicSettings = t.TypeOf; export type DynamicSettingsSaveResponse = t.TypeOf; +export type CertificatesStatesThreshold = t.TypeOf; export const defaultDynamicSettings: DynamicSettings = { heartbeatIndices: 'heartbeat-8*', + certificatesThresholds: { + errorState: 7, + warningState: 30, + }, }; diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx index 6f0b58029224fe..6c7660023cf8e6 100644 --- a/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx @@ -44,35 +44,37 @@ export const CertificateExpirationForm: React.FC = ({ title={

} description={ } > {defaultDynamicSettings.heartbeatIndices}, + defaultValue: ( + {defaultDynamicSettings.certificatesThresholds.errorState} + ), }} /> } - isInvalid={!!fieldErrors?.heartbeatIndices} + isInvalid={!!fieldErrors?.certificatesThresholds?.errorState} label={ } @@ -80,36 +82,43 @@ export const CertificateExpirationForm: React.FC = ({ onChange('heartbeatIndices', event.currentTarget.value)} + value={formFields?.certificatesThresholds?.errorState || ''} + onChange={({ currentTarget: { value } }: any) => + onChange( + 'certificatesThresholds.errorState', + value === '' ? undefined : Number(value) + ) + } /> - + {defaultDynamicSettings.heartbeatIndices}, + defaultValue: ( + {defaultDynamicSettings.certificatesThresholds.warningState} + ), }} /> } - isInvalid={!!fieldErrors?.heartbeatIndices} + isInvalid={!!fieldErrors?.certificatesThresholds.warningState} label={ } @@ -117,16 +126,20 @@ export const CertificateExpirationForm: React.FC = ({ onChange('heartbeatIndices', event.currentTarget.value)} + value={formFields?.certificatesThresholds?.warningState || ''} + onChange={(event: any) => + onChange('certificatesThresholds.warningState', Number(event.currentTarget.value)) + } /> - + diff --git a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx index aa52fbf03419ce..41bef871d0bec1 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx @@ -14,16 +14,15 @@ import { EuiForm, EuiPanel, EuiSpacer, - EuiTitle, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { useDispatch, useSelector } from 'react-redux'; -import { isEqual } from 'lodash'; +import { isEqual, set, cloneDeep } from 'lodash'; import { i18n } from '@kbn/i18n'; import { Link } from 'react-router-dom'; import { selectDynamicSettings } from '../state/selectors'; import { getDynamicSettings, setDynamicSettings } from '../state/actions/dynamic_settings'; -import { DynamicSettings } from '../../common/runtime_types'; +import { DynamicSettings, DynamicSettingsType } from '../../common/runtime_types'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; import { OVERVIEW_ROUTE } from '../../common/constants'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; @@ -53,15 +52,22 @@ export const SettingsPage = () => { setFormFields({ ...dss.settings }); } + const blankStr = 'May not be blank'; const fieldErrors = formFields && { - heartbeatIndices: formFields.heartbeatIndices.match(/^\S+$/) ? null : 'May not be blank', + heartbeatIndices: formFields.heartbeatIndices.match(/^\S+$/) ? null : blankStr, + certificatesThresholds: { + errorState: formFields.certificatesThresholds?.errorState ? null : blankStr, + warningState: formFields.certificatesThresholds?.warningState ? null : blankStr, + }, }; + const isFormValid = !(fieldErrors && Object.values(fieldErrors).find(v => !!v)); const onChangeFormField = (field: keyof DynamicSettings, value: any) => { if (formFields) { - formFields[field] = value; - setFormFields({ ...formFields }); + const newFormFields = cloneDeep(formFields); + set(newFormFields, field, value); + setFormFields(cloneDeep(newFormFields)); } }; diff --git a/x-pack/plugins/uptime/server/lib/saved_objects.ts b/x-pack/plugins/uptime/server/lib/saved_objects.ts index 175634ef797ccc..9067fcb9919001 100644 --- a/x-pack/plugins/uptime/server/lib/saved_objects.ts +++ b/x-pack/plugins/uptime/server/lib/saved_objects.ts @@ -7,14 +7,10 @@ import { DynamicSettings, defaultDynamicSettings, -} from '../../../../legacy/plugins/uptime/common/runtime_types/dynamic_settings'; +} from '../../../../legacy/plugins/uptime/common/runtime_types'; import { SavedObjectsType, SavedObjectsErrorHelpers } from '../../../../../src/core/server'; import { UMSavedObjectsQueryFn } from './adapters'; -export interface UMDynamicSettingsType { - heartbeatIndices: string; -} - export interface UMSavedObjectsAdapter { getUptimeDynamicSettings: UMSavedObjectsQueryFn; setUptimeDynamicSettings: UMSavedObjectsQueryFn; @@ -32,6 +28,16 @@ export const umDynamicSettings: SavedObjectsType = { heartbeatIndices: { type: 'keyword', }, + certificatesThresholds: { + properties: { + errorState: { + type: 'long', + }, + warningState: { + type: 'long', + }, + }, + }, }, }, }; From aa3b048f25620936cc10ec098ad6437ac7a48873 Mon Sep 17 00:00:00 2001 From: shahzad Date: Thu, 16 Apr 2020 12:43:03 +0200 Subject: [PATCH 4/7] update types --- .../components/settings/certificate_form.tsx | 21 +++++++--- .../components/settings/indices_form.tsx | 8 +++- .../plugins/uptime/public/pages/settings.tsx | 41 +++++++++++++------ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx index 6c7660023cf8e6..5103caee1e1c05 100644 --- a/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx @@ -18,10 +18,21 @@ import { EuiFlexGroup, EuiFlexItem, } from '@elastic/eui'; -import { defaultDynamicSettings } from '../../../common/runtime_types'; +import { defaultDynamicSettings, DynamicSettings } from '../../../common/runtime_types'; import { selectDynamicSettings } from '../../state/selectors'; -export const CertificateExpirationForm: React.FC = ({ +type NumStr = string | number; + +export type OnFieldChangeType = (field: string, value?: NumStr) => void; + +export interface SettingsFormProps { + onChange: OnFieldChangeType; + formFields: DynamicSettings | null; + fieldErrors: any; + isDisabled: boolean; +} + +export const CertificateExpirationForm: React.FC = ({ onChange, formFields, fieldErrors, @@ -66,7 +77,7 @@ export const CertificateExpirationForm: React.FC = ({ defaultMessage="The default value is {defaultValue}" values={{ defaultValue: ( - {defaultDynamicSettings.certificatesThresholds.errorState} + {defaultDynamicSettings?.certificatesThresholds?.errorState} ), }} /> @@ -110,12 +121,12 @@ export const CertificateExpirationForm: React.FC = ({ defaultMessage="The default value is {defaultValue}" values={{ defaultValue: ( - {defaultDynamicSettings.certificatesThresholds.warningState} + {defaultDynamicSettings?.certificatesThresholds?.warningState} ), }} /> } - isInvalid={!!fieldErrors?.certificatesThresholds.warningState} + isInvalid={!!fieldErrors?.certificatesThresholds?.warningState} label={ { +export const IndicesForm: React.FC = ({ + onChange, + formFields, + fieldErrors, + isDisabled, +}) => { const dss = useSelector(selectDynamicSettings); return ( diff --git a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx index 41bef871d0bec1..049dffecd3f2ef 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/settings.tsx @@ -17,18 +17,42 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { useDispatch, useSelector } from 'react-redux'; -import { isEqual, set, cloneDeep } from 'lodash'; +import { cloneDeep, isEqual, set } from 'lodash'; import { i18n } from '@kbn/i18n'; import { Link } from 'react-router-dom'; import { selectDynamicSettings } from '../state/selectors'; import { getDynamicSettings, setDynamicSettings } from '../state/actions/dynamic_settings'; -import { DynamicSettings, DynamicSettingsType } from '../../common/runtime_types'; +import { DynamicSettings } from '../../common/runtime_types'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; import { OVERVIEW_ROUTE } from '../../common/constants'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; import { UptimePage, useUptimeTelemetry } from '../hooks'; import { IndicesForm } from '../components/settings/indices_form'; -import { CertificateExpirationForm } from '../components/settings/certificate_form'; +import { + CertificateExpirationForm, + OnFieldChangeType, +} from '../components/settings/certificate_form'; + +const getFieldErrors = (formFields: DynamicSettings | null) => { + if (formFields) { + const blankStr = 'May not be blank'; + const { certificatesThresholds, heartbeatIndices } = formFields; + const heartbeatIndErr = heartbeatIndices.match(/^\S+$/) ? '' : blankStr; + const errorStateErr = certificatesThresholds?.errorState ? null : blankStr; + const warningStateErr = certificatesThresholds?.warningState ? null : blankStr; + return { + heartbeatIndices: heartbeatIndErr, + certificatesThresholds: + errorStateErr || warningStateErr + ? { + errorState: errorStateErr, + warningState: warningStateErr, + } + : null, + }; + } + return null; +}; export const SettingsPage = () => { const dss = useSelector(selectDynamicSettings); @@ -52,18 +76,11 @@ export const SettingsPage = () => { setFormFields({ ...dss.settings }); } - const blankStr = 'May not be blank'; - const fieldErrors = formFields && { - heartbeatIndices: formFields.heartbeatIndices.match(/^\S+$/) ? null : blankStr, - certificatesThresholds: { - errorState: formFields.certificatesThresholds?.errorState ? null : blankStr, - warningState: formFields.certificatesThresholds?.warningState ? null : blankStr, - }, - }; + const fieldErrors = getFieldErrors(formFields); const isFormValid = !(fieldErrors && Object.values(fieldErrors).find(v => !!v)); - const onChangeFormField = (field: keyof DynamicSettings, value: any) => { + const onChangeFormField: OnFieldChangeType = (field, value) => { if (formFields) { const newFormFields = cloneDeep(formFields); set(newFormFields, field, value); From 9a009ca518486db869f85eb015c2091e70842857 Mon Sep 17 00:00:00 2001 From: shahzad Date: Thu, 16 Apr 2020 13:04:57 +0200 Subject: [PATCH 5/7] update test --- .../certificate_form.test.tsx.snap | 69 +++++++++++++++++++ .../__snapshots__/indices_form.test.tsx.snap | 69 +++++++++++++++++++ .../__tests__/certificate_form.test.tsx | 27 ++++++++ .../settings/__tests__/indices_form.test.tsx | 27 ++++++++ 4 files changed, 192 insertions(+) create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx create mode 100644 x-pack/legacy/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap new file mode 100644 index 00000000000000..36bc9bb8602111 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CertificateForm shallow renders expected elements for valid props 1`] = ` + + + +`; diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap new file mode 100644 index 00000000000000..93151198c0f494 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CertificateForm shallow renders expected elements for valid props 1`] = ` + + + +`; diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx new file mode 100644 index 00000000000000..a3158f3d724456 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx @@ -0,0 +1,27 @@ +/* + * 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 React from 'react'; +import { CertificateExpirationForm } from '../certificate_form'; +import { shallowWithRouter } from '../../../lib'; + +describe('CertificateForm', () => { + it('shallow renders expected elements for valid props', () => { + expect( + shallowWithRouter( + + ) + ).toMatchSnapshot(); + }); +}); diff --git a/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx new file mode 100644 index 00000000000000..654d51019d4e57 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx @@ -0,0 +1,27 @@ +/* + * 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 React from 'react'; +import { IndicesForm } from '../indices_form'; +import { shallowWithRouter } from '../../../lib'; + +describe('CertificateForm', () => { + it('shallow renders expected elements for valid props', () => { + expect( + shallowWithRouter( + + ) + ).toMatchSnapshot(); + }); +}); From 3074ed4943673d922be88263e0f84fc583f03cfd Mon Sep 17 00:00:00 2001 From: shahzad Date: Thu, 16 Apr 2020 14:41:02 +0200 Subject: [PATCH 6/7] updated tests --- .../apis/uptime/rest/dynamic_settings.ts | 8 ++++- .../test/functional/apps/uptime/settings.ts | 36 ++++++++++++++++++- .../functional/services/uptime/settings.ts | 33 +++++++++++++---- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts b/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts index f4dd7c244f8b51..a1b731169f0a0d 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts @@ -18,7 +18,13 @@ export default function({ getService }: FtrProviderContext) { }); it('can change the settings', async () => { - const newSettings = { heartbeatIndices: 'myIndex1*' }; + const newSettings = { + heartbeatIndices: 'myIndex1*', + certificatesThresholds: { + errorState: 5, + warningState: 15, + }, + }; const postResponse = await supertest .post(`/api/uptime/dynamic_settings`) .set('kbn-xsrf', 'true') diff --git a/x-pack/test/functional/apps/uptime/settings.ts b/x-pack/test/functional/apps/uptime/settings.ts index 3294d928b61b3e..64cfee50ac9825 100644 --- a/x-pack/test/functional/apps/uptime/settings.ts +++ b/x-pack/test/functional/apps/uptime/settings.ts @@ -74,7 +74,41 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { // Verify that the settings page shows the value we previously saved await settings.go(); const fields = await settings.loadFields(); - expect(fields).to.eql(newFieldValues); + expect(fields.heartbeatIndices).to.eql(newFieldValues.heartbeatIndices); + }); + + it('changing certificate expiration error threshold is reflected in settings page', async () => { + const settings = uptimeService.settings; + + await settings.go(); + + const newErrorThreshold = '5'; + await settings.changeErrorThresholdInput(newErrorThreshold); + await settings.apply(); + + await uptimePage.goToRoot(); + + // Verify that the settings page shows the value we previously saved + await settings.go(); + const fields = await settings.loadFields(); + expect(fields.certificatesThresholds.errorState).to.eql(newErrorThreshold); + }); + + it('changing certificate expiration warning threshold is reflected in settings page', async () => { + const settings = uptimeService.settings; + + await settings.go(); + + const newWarningThreshold = '15'; + await settings.changeWarningThresholdInput(newWarningThreshold); + await settings.apply(); + + await uptimePage.goToRoot(); + + // Verify that the settings page shows the value we previously saved + await settings.go(); + const fields = await settings.loadFields(); + expect(fields.certificatesThresholds.warningState).to.eql(newWarningThreshold); }); }); }; diff --git a/x-pack/test/functional/services/uptime/settings.ts b/x-pack/test/functional/services/uptime/settings.ts index a64d39cd62a6d4..14cab368b766a2 100644 --- a/x-pack/test/functional/services/uptime/settings.ts +++ b/x-pack/test/functional/services/uptime/settings.ts @@ -10,20 +10,41 @@ export function UptimeSettingsProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); const retry = getService('retry'); + const changeInputField = async (text: string, field: string) => { + const input = await testSubjects.find(field, 5000); + await input.clearValueWithKeyboard(); + await input.type(text); + }; + return { go: async () => { await testSubjects.click('settings-page-link', 5000); }, + changeHeartbeatIndicesInput: async (text: string) => { - const input = await testSubjects.find('heartbeat-indices-input-loaded', 5000); - await input.clearValueWithKeyboard(); - await input.type(text); + await changeInputField(text, 'heartbeat-indices-input-loaded'); + }, + changeErrorThresholdInput: async (text: string) => { + await changeInputField(text, 'error-state-threshold-input-loaded'); + }, + changeWarningThresholdInput: async (text: string) => { + await changeInputField(text, 'warning-state-threshold-input-loaded'); }, loadFields: async () => { - const input = await testSubjects.find('heartbeat-indices-input-loaded', 5000); - const heartbeatIndices = await input.getAttribute('value'); + const indInput = await testSubjects.find('heartbeat-indices-input-loaded', 5000); + const errorInput = await testSubjects.find('error-state-threshold-input-loaded', 5000); + const warningInput = await testSubjects.find('warning-state-threshold-input-loaded', 5000); + const heartbeatIndices = await indInput.getAttribute('value'); + const errorThreshold = await errorInput.getAttribute('value'); + const warningThreshold = await warningInput.getAttribute('value'); - return { heartbeatIndices }; + return { + heartbeatIndices, + certificatesThresholds: { + errorState: errorThreshold, + warningState: warningThreshold, + }, + }; }, applyButtonIsDisabled: async () => { return !!(await (await testSubjects.find('apply-settings-button')).getAttribute('disabled')); From ac2e520acae507c3f4722f714c7987e7837f7f29 Mon Sep 17 00:00:00 2001 From: shahzad Date: Thu, 16 Apr 2020 18:51:30 +0200 Subject: [PATCH 7/7] updated snapshots --- .../server/lib/alerts/__tests__/status_check.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x-pack/plugins/uptime/server/lib/alerts/__tests__/status_check.test.ts b/x-pack/plugins/uptime/server/lib/alerts/__tests__/status_check.test.ts index 2eb17d588d297b..2cc6f23ebaae50 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/__tests__/status_check.test.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/__tests__/status_check.test.ts @@ -88,6 +88,10 @@ describe('status check alert', () => { Object { "callES": [MockFunction], "dynamicSettings": Object { + "certificatesThresholds": Object { + "errorState": 7, + "warningState": 30, + }, "heartbeatIndices": "heartbeat-8*", }, "locations": Array [], @@ -131,6 +135,10 @@ describe('status check alert', () => { Object { "callES": [MockFunction], "dynamicSettings": Object { + "certificatesThresholds": Object { + "errorState": 7, + "warningState": 30, + }, "heartbeatIndices": "heartbeat-8*", }, "locations": Array [],