Skip to content

Commit 725a38b

Browse files
committed
Address comments
1 parent 8d222b4 commit 725a38b

File tree

3 files changed

+144
-3
lines changed

3 files changed

+144
-3
lines changed

x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rules_list.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ export const RulesList = ({
490490
setShowErrors((prevValue) => {
491491
if (!prevValue) {
492492
const rulesToExpand = rulesState.data.reduce((acc, ruleItem) => {
493-
if (ruleItem.lastRun?.outcome === RuleLastRunOutcomeValues[2]) {
493+
// Check both outcome and executionStatus for now until we deprecate executionStatus
494+
if (
495+
ruleItem.lastRun?.outcome === RuleLastRunOutcomeValues[2] ||
496+
ruleItem.executionStatus.status === 'error'
497+
) {
494498
return {
495499
...acc,
496500
[ruleItem.id]: (
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { getRuleHealthColor, getRuleStatusMessage } from './rule_status_helpers';
9+
import { RuleTableItem } from '../../types';
10+
11+
import { getIsExperimentalFeatureEnabled } from '../get_experimental_features';
12+
13+
jest.mock('../get_experimental_features', () => ({
14+
getIsExperimentalFeatureEnabled: jest.fn(),
15+
}));
16+
17+
const mockRule = {
18+
id: '1',
19+
enabled: true,
20+
executionStatus: {
21+
status: 'active',
22+
},
23+
lastRun: {
24+
outcome: 'succeeded',
25+
},
26+
} as RuleTableItem;
27+
28+
const warningRule = {
29+
...mockRule,
30+
executionStatus: {
31+
status: 'warning',
32+
},
33+
lastRun: {
34+
outcome: 'warning',
35+
},
36+
} as RuleTableItem;
37+
38+
const failedRule = {
39+
...mockRule,
40+
executionStatus: {
41+
status: 'error',
42+
},
43+
lastRun: {
44+
outcome: 'failed',
45+
},
46+
} as RuleTableItem;
47+
48+
const licenseErrorRule = {
49+
...mockRule,
50+
executionStatus: {
51+
status: 'error',
52+
error: {
53+
reason: 'license',
54+
},
55+
},
56+
lastRun: {
57+
outcome: 'failed',
58+
warning: 'license',
59+
},
60+
} as RuleTableItem;
61+
62+
beforeEach(() => {
63+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => true);
64+
});
65+
66+
describe('getRuleHealthColor', () => {
67+
it('should return the correct color for successful rule', () => {
68+
let color = getRuleHealthColor(mockRule);
69+
expect(color).toEqual('success');
70+
71+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
72+
73+
color = getRuleHealthColor(mockRule);
74+
expect(color).toEqual('success');
75+
});
76+
77+
it('should return the correct color for warning rule', () => {
78+
let color = getRuleHealthColor(warningRule);
79+
expect(color).toEqual('warning');
80+
81+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
82+
83+
color = getRuleHealthColor(warningRule);
84+
expect(color).toEqual('warning');
85+
});
86+
87+
it('should return the correct color for failed rule', () => {
88+
let color = getRuleHealthColor(failedRule);
89+
expect(color).toEqual('danger');
90+
91+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
92+
93+
color = getRuleHealthColor(failedRule);
94+
expect(color).toEqual('danger');
95+
});
96+
});
97+
98+
describe('getRuleStatusMessage', () => {
99+
it('should get the status message for a successful rule', () => {
100+
let statusMessage = getRuleStatusMessage(mockRule);
101+
expect(statusMessage).toEqual('Succeeded');
102+
103+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
104+
statusMessage = getRuleStatusMessage(mockRule);
105+
expect(statusMessage).toEqual('Active');
106+
});
107+
108+
it('should get the status message for a warning rule', () => {
109+
let statusMessage = getRuleStatusMessage(warningRule);
110+
expect(statusMessage).toEqual('Warning');
111+
112+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
113+
statusMessage = getRuleStatusMessage(warningRule);
114+
expect(statusMessage).toEqual('Warning');
115+
});
116+
117+
it('should get the status message for a failed rule', () => {
118+
let statusMessage = getRuleStatusMessage(failedRule);
119+
expect(statusMessage).toEqual('Failed');
120+
121+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
122+
statusMessage = getRuleStatusMessage(failedRule);
123+
expect(statusMessage).toEqual('Error');
124+
});
125+
126+
it('should get the status message for a license error rule', () => {
127+
let statusMessage = getRuleStatusMessage(licenseErrorRule);
128+
expect(statusMessage).toEqual('License Error');
129+
130+
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
131+
statusMessage = getRuleStatusMessage(licenseErrorRule);
132+
expect(statusMessage).toEqual('License Error');
133+
});
134+
});

x-pack/plugins/triggers_actions_ui/public/common/lib/rule_status_helpers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const getRuleHealthColor = (rule: Rule) => {
5656
};
5757

5858
export const getIsLicenseError = (rule: Rule) => {
59-
return rule.lastRun?.warning === RuleExecutionStatusErrorReasons.License;
59+
return (
60+
rule.lastRun?.warning === RuleExecutionStatusErrorReasons.License ||
61+
rule.executionStatus.error?.reason === RuleExecutionStatusErrorReasons.License
62+
);
6063
};
6164

6265
export const getRuleStatusMessage = (rule: Rule) => {
@@ -67,7 +70,7 @@ export const getRuleStatusMessage = (rule: Rule) => {
6770
return ALERT_STATUS_LICENSE_ERROR;
6871
}
6972
if (isRuleLastRunOutcomeEnabled) {
70-
return (rule.lastRun && rulesLastRunOutcomeTranslationMapping[rule.lastRun.outcome]) || '';
73+
return rule.lastRun && rulesLastRunOutcomeTranslationMapping[rule.lastRun.outcome];
7174
}
7275
return rulesStatusesTranslationsMapping[rule.executionStatus.status];
7376
};

0 commit comments

Comments
 (0)