-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
x-pack/plugins/triggers_actions_ui/public/common/lib/rule_status_helper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getRuleHealthColor, getRuleStatusMessage } from './rule_status_helpers'; | ||
import { RuleTableItem } from '../../types'; | ||
|
||
import { getIsExperimentalFeatureEnabled } from '../get_experimental_features'; | ||
|
||
jest.mock('../get_experimental_features', () => ({ | ||
getIsExperimentalFeatureEnabled: jest.fn(), | ||
})); | ||
|
||
const mockRule = { | ||
id: '1', | ||
enabled: true, | ||
executionStatus: { | ||
status: 'active', | ||
}, | ||
lastRun: { | ||
outcome: 'succeeded', | ||
}, | ||
} as RuleTableItem; | ||
|
||
const warningRule = { | ||
...mockRule, | ||
executionStatus: { | ||
status: 'warning', | ||
}, | ||
lastRun: { | ||
outcome: 'warning', | ||
}, | ||
} as RuleTableItem; | ||
|
||
const failedRule = { | ||
...mockRule, | ||
executionStatus: { | ||
status: 'error', | ||
}, | ||
lastRun: { | ||
outcome: 'failed', | ||
}, | ||
} as RuleTableItem; | ||
|
||
const licenseErrorRule = { | ||
...mockRule, | ||
executionStatus: { | ||
status: 'error', | ||
error: { | ||
reason: 'license', | ||
}, | ||
}, | ||
lastRun: { | ||
outcome: 'failed', | ||
warning: 'license', | ||
}, | ||
} as RuleTableItem; | ||
|
||
beforeEach(() => { | ||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => true); | ||
}); | ||
|
||
describe('getRuleHealthColor', () => { | ||
it('should return the correct color for successful rule', () => { | ||
let color = getRuleHealthColor(mockRule); | ||
expect(color).toEqual('success'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
|
||
color = getRuleHealthColor(mockRule); | ||
expect(color).toEqual('success'); | ||
}); | ||
|
||
it('should return the correct color for warning rule', () => { | ||
let color = getRuleHealthColor(warningRule); | ||
expect(color).toEqual('warning'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
|
||
color = getRuleHealthColor(warningRule); | ||
expect(color).toEqual('warning'); | ||
}); | ||
|
||
it('should return the correct color for failed rule', () => { | ||
let color = getRuleHealthColor(failedRule); | ||
expect(color).toEqual('danger'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
|
||
color = getRuleHealthColor(failedRule); | ||
expect(color).toEqual('danger'); | ||
}); | ||
}); | ||
|
||
describe('getRuleStatusMessage', () => { | ||
it('should get the status message for a successful rule', () => { | ||
let statusMessage = getRuleStatusMessage(mockRule); | ||
expect(statusMessage).toEqual('Succeeded'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
statusMessage = getRuleStatusMessage(mockRule); | ||
expect(statusMessage).toEqual('Active'); | ||
}); | ||
|
||
it('should get the status message for a warning rule', () => { | ||
let statusMessage = getRuleStatusMessage(warningRule); | ||
expect(statusMessage).toEqual('Warning'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
statusMessage = getRuleStatusMessage(warningRule); | ||
expect(statusMessage).toEqual('Warning'); | ||
}); | ||
|
||
it('should get the status message for a failed rule', () => { | ||
let statusMessage = getRuleStatusMessage(failedRule); | ||
expect(statusMessage).toEqual('Failed'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
statusMessage = getRuleStatusMessage(failedRule); | ||
expect(statusMessage).toEqual('Error'); | ||
}); | ||
|
||
it('should get the status message for a license error rule', () => { | ||
let statusMessage = getRuleStatusMessage(licenseErrorRule); | ||
expect(statusMessage).toEqual('License Error'); | ||
|
||
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false); | ||
statusMessage = getRuleStatusMessage(licenseErrorRule); | ||
expect(statusMessage).toEqual('License Error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters