diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.tsx b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.tsx
index 7203732c4c506..a25f44eadd235 100644
--- a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.tsx
+++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.tsx
@@ -288,94 +288,127 @@ describe(' create route', () => {
});
describe('results flyout', () => {
- const actionModes = ['simulate', 'force_simulate', 'execute', 'force_execute', 'skip'];
- const actionModeStatusesConditionMet = [
- 'simulated',
- 'simulated',
- 'executed',
- 'executed',
- 'throttled',
- ];
- const actionModeStatusesConditionNotMet = [
- 'not simulated',
- 'not simulated',
- 'not executed',
- 'not executed',
- 'throttled',
- ];
- const conditionMetStatuses = [true, false];
- const ACTION_NAME = 'my-logging-action';
- const ACTION_TYPE = 'logging';
- const ACTION_STATE = 'OK';
-
- actionModes.forEach((actionMode, i) => {
- conditionMetStatuses.forEach((conditionMet) => {
- describe('for ' + actionMode + ' action mode', () => {
- describe(
- conditionMet ? 'when the condition is met' : 'when the condition is not met',
- () => {
- beforeEach(async () => {
- const { actions, form } = testBed;
- form.setInputValue('actionModesSelect', actionMode);
-
- httpRequestsMockHelpers.setLoadExecutionResultResponse({
- watchHistoryItem: {
- details: {
- result: {
- condition: {
- met: conditionMet,
+ describe('correctly displays execution results', () => {
+ const actionModes = ['simulate', 'force_simulate', 'execute', 'force_execute', 'skip'];
+ const actionModeStatusesConditionMet = [
+ 'simulated',
+ 'simulated',
+ 'executed',
+ 'executed',
+ 'throttled',
+ ];
+ const actionModeStatusesConditionNotMet = [
+ 'not simulated',
+ 'not simulated',
+ 'not executed',
+ 'not executed',
+ 'throttled',
+ ];
+ const conditionMetStatuses = [true, false];
+ const ACTION_NAME = 'my-logging-action';
+ const ACTION_TYPE = 'logging';
+ const ACTION_STATE = 'OK';
+
+ actionModes.forEach((actionMode, i) => {
+ conditionMetStatuses.forEach((conditionMet) => {
+ describe('for ' + actionMode + ' action mode', () => {
+ describe(
+ conditionMet ? 'when the condition is met' : 'when the condition is not met',
+ () => {
+ beforeEach(async () => {
+ const { actions, form } = testBed;
+ form.setInputValue('actionModesSelect', actionMode);
+
+ httpRequestsMockHelpers.setLoadExecutionResultResponse({
+ watchHistoryItem: {
+ details: {
+ result: {
+ condition: {
+ met: conditionMet,
+ },
+ actions:
+ (conditionMet && [
+ {
+ id: ACTION_NAME,
+ type: ACTION_TYPE,
+ status: conditionMet && actionModeStatusesConditionMet[i],
+ },
+ ]) ||
+ [],
},
- actions:
- (conditionMet && [
- {
- id: ACTION_NAME,
- type: ACTION_TYPE,
- status: conditionMet && actionModeStatusesConditionMet[i],
- },
- ]) ||
- [],
+ },
+ watchStatus: {
+ actionStatuses: [
+ {
+ id: ACTION_NAME,
+ state: ACTION_STATE,
+ },
+ ],
},
},
- watchStatus: {
- actionStatuses: [
- {
- id: ACTION_NAME,
- state: ACTION_STATE,
- },
- ],
- },
- },
+ });
+
+ await actions.clickSimulateButton();
});
- await actions.clickSimulateButton();
- });
-
- test('should set the correct condition met status', () => {
- const { exists } = testBed;
- expect(exists('conditionMetStatus')).toBe(conditionMet);
- expect(exists('conditionNotMetStatus')).toBe(!conditionMet);
- });
-
- test('should set the correct values in the table', () => {
- const { table } = testBed;
- const { tableCellsValues } = table.getMetaData('simulateResultsTable');
- const row = tableCellsValues[0];
- expect(row).toEqual([
- ACTION_NAME,
- ACTION_TYPE,
- actionMode,
- ACTION_STATE,
- '',
- conditionMet
- ? actionModeStatusesConditionMet[i]
- : actionModeStatusesConditionNotMet[i],
- ]);
- });
- }
- );
+ test('should set the correct condition met status', () => {
+ const { exists } = testBed;
+ expect(exists('conditionMetStatus')).toBe(conditionMet);
+ expect(exists('conditionNotMetStatus')).toBe(!conditionMet);
+ });
+
+ test('should set the correct values in the table', () => {
+ const { table } = testBed;
+ const { tableCellsValues } = table.getMetaData('simulateResultsTable');
+ const row = tableCellsValues[0];
+ expect(row).toEqual([
+ ACTION_NAME,
+ ACTION_TYPE,
+ actionMode,
+ ACTION_STATE,
+ '',
+ conditionMet
+ ? actionModeStatusesConditionMet[i]
+ : actionModeStatusesConditionNotMet[i],
+ ]);
+ });
+ }
+ );
+ });
});
});
});
+
+ describe('when API returns no results', () => {
+ beforeEach(async () => {
+ const { actions } = testBed;
+
+ httpRequestsMockHelpers.setLoadExecutionResultResponse({
+ watchHistoryItem: {
+ details: {
+ result: {},
+ },
+ watchStatus: {
+ actionStatuses: [],
+ },
+ },
+ });
+
+ await actions.clickSimulateButton();
+ });
+
+ test('flyout renders', () => {
+ const { exists } = testBed;
+ expect(exists('simulateResultsFlyout')).toBe(true);
+ expect(exists('simulateResultsFlyoutTitle')).toBe(true);
+ });
+
+ test('condition status is not displayed', () => {
+ const { exists } = testBed;
+ expect(exists('conditionMetStatus')).toBe(false);
+ expect(exists('conditionNotMetStatus')).toBe(false);
+ });
+ });
});
});
});
diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx
index a4f156afcc14c..f56cf8dd75387 100644
--- a/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx
+++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx
@@ -80,7 +80,7 @@ export const SimulateWatchResultsFlyout = ({
executeResults.watchStatus && executeResults.watchStatus.actionStatuses;
return Object.keys(actions).map((actionKey) => {
const actionStatus = actionStatuses.find((status) => status.id === actionKey);
- const isConditionMet = executeResults.details?.result?.condition.met;
+ const isConditionMet = executeResults.details?.result?.condition?.met;
return {
actionId: actionKey,
@@ -90,7 +90,7 @@ export const SimulateWatchResultsFlyout = ({
actionReason: actionStatus && actionStatus.lastExecutionReason,
actionStatus:
(isConditionMet &&
- executeResults.details.result.actions.find((action: any) => action.id === actionKey)
+ executeResults.details?.result?.actions.find((action: any) => action.id === actionKey)
?.status) ||
conditionNotMetActionStatus(actionModes[actionKey]),
};
@@ -205,7 +205,7 @@ export const SimulateWatchResultsFlyout = ({
const { details } = executeResults;
- const conditionMetStatus = (details?.result?.condition.met && (
+ const conditionMetStatus = (details?.result?.condition?.met && (
<>
{' '}
{flyoutTitle}
-
- {conditionMetStatus}
+ {details?.result?.condition?.met != null && (
+ <>
+
+ {conditionMetStatus}
+ >
+ )}