import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; import { DynamicSettings } from '../../../../plugins/uptime/common/runtime_types' ; import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../plugins/uptime/common/constants' ; import { makeChecks } from '../../../api_integration/apis/uptime/rest/helper/make_checks' ; export default ( { getPageObjects , getService } ) => { const { uptime : uptimePage } = getPageObjects ( [ 'uptime' ] ) ; const uptimeService = getService ( 'uptime' ) ; const es = getService ( 'es' ) ; describe ( 'uptime settings page' , ( ) => { beforeEach ( 'navigate to clean app root' , async ( ) => { await makeChecks ( es , 'myMonitor' , 1 , 1 , 1 ) ; await uptimePage . goToRoot ( ) ; } ) ; it ( 'loads the default settings' , async ( ) => { const settings = uptimeService . settings ; await settings . go ( ) ; const fields = await settings . loadFields ( ) ; expect ( fields ) . to . eql ( DYNAMIC_SETTINGS_DEFAULTS ) ; } ) ; it ( 'should disable the apply button when invalid or unchanged' , async ( ) => { const settings = uptimeService . settings ; await settings . go ( ) ; expect ( await settings . applyButtonIsDisabled ( ) ) . to . eql ( true ) ; await settings . changeHeartbeatIndicesInput ( 'somethingNew' ) ; expect ( await settings . applyButtonIsDisabled ( ) ) . to . eql ( false ) ; await settings . changeHeartbeatIndicesInput ( '' ) ; expect ( await settings . applyButtonIsDisabled ( ) ) . to . eql ( true ) ; } ) ; it ( 'changing index pattern setting is reflected elsewhere in UI' , async ( ) => { const settings = uptimeService . settings ; const originalCount = await uptimePage . getSnapshotCount ( ) ; expect ( originalCount . up ) . to . eql ( 1 ) ; await settings . go ( ) ; const newFieldValues = { heartbeatIndices : 'new*' , certAgeThreshold : 365 , certExpirationThreshold : 30 , defaultConnectors : [ ] , } ; await settings . changeHeartbeatIndicesInput ( newFieldValues . heartbeatIndices ) ; await settings . apply ( ) ; await uptimePage . goToRoot ( ) ; await uptimePage . pageHasDataMissing ( ) ; await settings . go ( ) ; const fields = await settings . loadFields ( ) ; 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 newExpirationThreshold = '5' ; await settings . changeErrorThresholdInput ( newExpirationThreshold ) ; await settings . apply ( ) ; await uptimePage . goToRoot ( ) ; await settings . go ( ) ; const fields = await settings . loadFields ( ) ; expect ( fields . certExpirationThreshold ) . to . eql ( newExpirationThreshold ) ; } ) ; it ( 'changing certificate expiration threshold is reflected in settings page' , async ( ) => { const settings = uptimeService . settings ; await settings . go ( ) ; const newAgeThreshold = '15' ; await settings . changeWarningThresholdInput ( newAgeThreshold ) ; await settings . apply ( ) ; await uptimePage . goToRoot ( ) ; await settings . go ( ) ; const fields = await settings . loadFields ( ) ; expect ( fields . certAgeThreshold ) . to . eql ( newAgeThreshold ) ; } ) ; } ) ; } ;