Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Watcher] Fix simulate flyout blank page #178016

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,94 +288,127 @@ describe('<JsonWatchEditPage /> 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);
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]),
};
Expand Down Expand Up @@ -205,7 +205,7 @@ export const SimulateWatchResultsFlyout = ({

const { details } = executeResults;

const conditionMetStatus = (details?.result?.condition.met && (
const conditionMetStatus = (details?.result?.condition?.met && (
<>
<EuiIcon color="green" type="check" data-test-subj="conditionMetStatus" />{' '}
<FormattedMessage
Expand Down Expand Up @@ -233,8 +233,12 @@ export const SimulateWatchResultsFlyout = ({
>
<EuiFlyoutHeader hasBorder>
{flyoutTitle}
<EuiSpacer size="s" />
{conditionMetStatus}
{details?.result?.condition?.met != null && (
<>
<EuiSpacer size="s" />
{conditionMetStatus}
</>
)}
</EuiFlyoutHeader>

<EuiFlyoutBody>
Expand Down