-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] Create detector | Interval field can be empty opensearch-projec…
…t#378 Signed-off-by: Jovan Cvetkovic <[email protected]>
- Loading branch information
1 parent
0d514d8
commit ff8117e
Showing
11 changed files
with
1,713 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
AlertCondition, | ||
Detector, | ||
DetectorInput, | ||
DetectorRuleInfo, | ||
PeriodSchedule, | ||
TriggerAction, | ||
} from '../../../models/interfaces'; | ||
|
||
export const detectorRuleInfoMock: DetectorRuleInfo = { | ||
id: 'detectorRuleId', | ||
}; | ||
|
||
export const detectorInputMock: DetectorInput = { | ||
detector_input: { | ||
description: 'detectorDescription', | ||
indices: ['.windows'], | ||
pre_packaged_rules: [detectorRuleInfoMock], | ||
custom_rules: [detectorRuleInfoMock], | ||
}, | ||
}; | ||
|
||
export const periodScheduleMock: PeriodSchedule = { | ||
period: { | ||
interval: 1, | ||
unit: 'minute', | ||
}, | ||
}; | ||
|
||
export const triggerActionMock: TriggerAction = { | ||
id: 'someId', | ||
// Id of notification channel | ||
destination_id: 'destinationId', | ||
subject_template: { | ||
source: 'sourceTemplate', | ||
lang: 'en-US', | ||
}, | ||
name: 'triggerName', | ||
throttle_enabled: false, | ||
message_template: { | ||
source: 'messageSource', | ||
lang: 'en-US', | ||
}, | ||
throttle: { | ||
unit: 'throttleUnit', | ||
value: 1, | ||
}, | ||
}; | ||
|
||
export const alertConditionMock: AlertCondition = { | ||
// Trigger fields | ||
name: 'alertName', | ||
|
||
// Detector types | ||
types: ['detectorType1'], | ||
|
||
// Trigger fields based on Rules | ||
sev_levels: ['low'], | ||
tags: ['any.tag'], | ||
ids: ['ruleId1'], | ||
|
||
// Alert related fields | ||
actions: [triggerActionMock, triggerActionMock], | ||
severity: 'low', | ||
}; | ||
|
||
export const detectorMock: Detector = { | ||
type: 'detector', | ||
detector_type: '.windows', | ||
name: 'detectorName', | ||
enabled: true, | ||
createdBy: 'testUser', | ||
schedule: periodScheduleMock, | ||
inputs: [detectorInputMock], | ||
triggers: [alertConditionMock, alertConditionMock], | ||
}; |
29 changes: 29 additions & 0 deletions
29
public/models/Detectors/components/AlertTriggerView/AlertTriggerViewMock.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,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { RuleInfo, RuleSource } from '../../../../../server/models/interfaces'; | ||
import { alertConditionMock, detectorMock } from '../../InterfacesMock.test'; | ||
|
||
const ruleSource: RuleSource = { | ||
rule: 'ruleName', | ||
last_update_time: '12/12/2022', | ||
queries: [{ value: '.windows' }], | ||
}; | ||
|
||
const ruleInfo: RuleInfo = { | ||
_id: 'ruleId', | ||
_index: '.windows', | ||
_primary_term: 1, | ||
_source: ruleSource, | ||
_version: 1, | ||
}; | ||
|
||
export default { | ||
alertTrigger: alertConditionMock, | ||
orderPosition: 1, | ||
detector: detectorMock, | ||
notificationChannels: [], | ||
rules: { rileId: ruleInfo }, | ||
}; |
9 changes: 9 additions & 0 deletions
9
...models/Detectors/components/DetectorBasicDetailsView/DetectorBasicDetailsViewMock.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,9 @@ | ||
import { detectorMock } from '../../InterfacesMock.test'; | ||
|
||
export default { | ||
detector: detectorMock, | ||
rulesCanFold: true, | ||
enabled_time: 1, | ||
last_update_time: 1, | ||
onEditClicked: () => jest.fn(), | ||
}; |
9 changes: 9 additions & 0 deletions
9
public/models/Detectors/components/DetectorRulesView/DetectorRulesViewMock.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,9 @@ | ||
import { detectorMock } from '../../InterfacesMock.test'; | ||
|
||
const notificationsStart: NotificationsStart = {}; | ||
export default { | ||
detector: detectorMock, | ||
rulesCanFold: true, | ||
onEditClicked: jest.fn(), | ||
notifications: notificationsStart, | ||
}; |
17 changes: 17 additions & 0 deletions
17
public/pages/Detectors/components/AlertTriggerView/AlertTriggerView.test.tsx
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,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { AlertTriggerView } from './AlertTriggerView'; | ||
import props from '../../../../models/Detectors/components/AlertTriggerView/AlertTriggerViewMock.test'; | ||
import { expect } from '@jest/globals'; | ||
|
||
describe('<AlertTriggerView /> spec', () => { | ||
it('renders the component', () => { | ||
const view = render(<AlertTriggerView {...props} />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.