forked from elastic/kibana
-
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.
[Security Solution][Detection Engine] fixes apply alert tags issue (e…
…lastic#194428) ## Summary - fixes elastic#192084 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...k/plugins/security_solution/public/common/components/toolbar/bulk_actions/reducer.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,53 @@ | ||
/* | ||
* 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 type { State } from './reducer'; | ||
import { createAlertTagsReducer } from './reducer'; | ||
|
||
const initialState: State = { | ||
selectableAlertTags: [], | ||
tagsToAdd: new Set<string>(['False positive']), | ||
tagsToRemove: new Set<string>(['Duplicate']), | ||
}; | ||
|
||
describe('createAlertTagsReducer', () => { | ||
it('should update state on addAlertTag action', () => { | ||
const reducer = createAlertTagsReducer(); | ||
const state = reducer(initialState, { type: 'addAlertTag', value: 'Duplicate' }); | ||
|
||
expect(Array.from(state.tagsToAdd)).toEqual(['False positive', 'Duplicate']); | ||
expect(Array.from(state.tagsToRemove)).toEqual([]); | ||
|
||
// reducer action must not mutate previous state | ||
expect(state.tagsToAdd).not.toBe(initialState.tagsToAdd); | ||
expect(state.tagsToRemove).not.toBe(initialState.tagsToRemove); | ||
expect(state).not.toBe(initialState); | ||
}); | ||
it('should update state on removeAlertTag action', () => { | ||
const reducer = createAlertTagsReducer(); | ||
const state = reducer(initialState, { type: 'removeAlertTag', value: 'False positive' }); | ||
|
||
expect(Array.from(state.tagsToRemove)).toEqual(['Duplicate', 'False positive']); | ||
expect(Array.from(state.tagsToAdd)).toEqual([]); | ||
|
||
// reducer action must not mutate previous state | ||
expect(state.tagsToRemove).not.toBe(initialState.tagsToRemove); | ||
expect(state.tagsToAdd).not.toBe(initialState.tagsToAdd); | ||
expect(state).not.toBe(initialState); | ||
}); | ||
it('should update state on setSelectableAlertTags action', () => { | ||
const reducer = createAlertTagsReducer(); | ||
const state = reducer(initialState, { | ||
type: 'setSelectableAlertTags', | ||
value: [{ label: 'Duplicate' }], | ||
}); | ||
|
||
expect(state.selectableAlertTags).toEqual([{ label: 'Duplicate' }]); | ||
// reducer action must not mutate previous state | ||
expect(state).not.toBe(initialState); | ||
}); | ||
}); |
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