diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts index ce9160abdb086..95371b5b501f5 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts @@ -6,7 +6,7 @@ import expect from '@kbn/expect'; import uuid from 'uuid'; -import { omit } from 'lodash'; +import { omit, mapValues } from 'lodash'; import moment from 'moment'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -210,59 +210,60 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { // Verify content await testSubjects.existOrFail('alertInstancesList'); - const { - alertInstances: { - ['us-central']: { - meta: { - lastScheduledActions: { date }, - }, - }, - }, - } = await alerting.alerts.getAlertState(alert.id); + const { alertInstances } = await alerting.alerts.getAlertState(alert.id); - const dateOnAllInstances = moment(date) - .utc() - .format('D MMM YYYY @ HH:mm:ss'); + const dateOnAllInstances = mapValues( + alertInstances, + ({ + meta: { + lastScheduledActions: { date }, + }, + }) => moment(date).utc() + ); const instancesList = await pageObjects.alertDetailsUI.getAlertInstancesList(); expect(instancesList.map(instance => omit(instance, 'duration'))).to.eql([ { instance: 'us-central', status: 'Active', - start: dateOnAllInstances, + start: dateOnAllInstances['us-central'].format('D MMM YYYY @ HH:mm:ss'), }, { instance: 'us-east', status: 'Active', - start: dateOnAllInstances, + start: dateOnAllInstances['us-east'].format('D MMM YYYY @ HH:mm:ss'), }, { instance: 'us-west', status: 'Active', - start: dateOnAllInstances, + start: dateOnAllInstances['us-west'].format('D MMM YYYY @ HH:mm:ss'), }, ]); - const durationFromInstanceTillPageLoad = moment.duration( - testBeganAt.diff(moment(date).utc()) + const durationFromInstanceTillPageLoad = mapValues(dateOnAllInstances, date => + moment.duration(testBeganAt.diff(moment(date).utc())) ); instancesList - .map(alertInstance => alertInstance.duration.split(':').map(part => parseInt(part, 10))) - .map(([hours, minutes, seconds]) => - moment.duration({ + .map(alertInstance => ({ + id: alertInstance.instance, + duration: alertInstance.duration.split(':').map(part => parseInt(part, 10)), + })) + .map(({ id, duration: [hours, minutes, seconds] }) => ({ + id, + duration: moment.duration({ hours, minutes, seconds, - }) - ) - .forEach(alertInstanceDuration => { + }), + })) + .forEach(({ id, duration }) => { // make sure the duration is within a 10 second range which is // good enough as the alert interval is 1m, so we know it is a fresh value - expect(alertInstanceDuration.as('milliseconds')).to.greaterThan( - durationFromInstanceTillPageLoad.subtract(1000 * 10).as('milliseconds') + expect(duration.as('milliseconds')).to.greaterThan( + durationFromInstanceTillPageLoad[id].subtract(1000 * 10).as('milliseconds') ); - expect(alertInstanceDuration.as('milliseconds')).to.lessThan( - durationFromInstanceTillPageLoad.add(1000 * 10).as('milliseconds') + expect(duration.as('milliseconds')).to.lessThan( + durationFromInstanceTillPageLoad[id].add(1000 * 10).as('milliseconds') ); }); });