-
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.
[RAM] Fix bulk snooze select all filter not matching rules list filter (
#141996) (#142029) * Select all filter now correctly match the rules list filter * Improve filter kuery node logic * unit tests Co-authored-by: Kibana Machine <[email protected]> (cherry picked from commit ace4f42) Co-authored-by: Jiawei Wu <[email protected]>
- Loading branch information
1 parent
bb90d2f
commit ffd3f54
Showing
12 changed files
with
259 additions
and
54 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
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
131 changes: 131 additions & 0 deletions
131
x-pack/plugins/triggers_actions_ui/public/application/hooks/use_bulk_edit_select.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,131 @@ | ||
/* | ||
* 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 { renderHook, act } from '@testing-library/react-hooks'; | ||
import { useBulkEditSelect } from './use_bulk_edit_select'; | ||
import { RuleTableItem } from '../../types'; | ||
|
||
const items = [ | ||
{ | ||
id: '1', | ||
isEditable: true, | ||
}, | ||
{ | ||
id: '2', | ||
isEditable: true, | ||
}, | ||
{ | ||
id: '3', | ||
isEditable: true, | ||
}, | ||
{ | ||
id: '4', | ||
isEditable: true, | ||
}, | ||
] as RuleTableItem[]; | ||
|
||
describe('useBulkEditSelectTest', () => { | ||
it('getFilter should return null when nothing is selected', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
}) | ||
); | ||
|
||
expect(result.current.getFilter()).toEqual(null); | ||
}); | ||
|
||
it('getFilter should return rule list filter when nothing is selected', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
tagsFilter: ['test: 123'], | ||
searchText: 'rules*', | ||
}) | ||
); | ||
|
||
expect(result.current.getFilter()?.arguments.length).toEqual(2); | ||
}); | ||
|
||
it('getFilter should return rule list filter when something is selected', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
tagsFilter: ['test: 123'], | ||
searchText: 'rules*', | ||
}) | ||
); | ||
|
||
act(() => { | ||
result.current.onSelectRow(items[0]); | ||
}); | ||
|
||
expect(result.current.getFilter()?.arguments.length).toEqual(2); | ||
expect([...result.current.selectedIds]).toEqual([items[0].id]); | ||
}); | ||
|
||
it('getFilter should return null when selecting all', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
}) | ||
); | ||
|
||
act(() => { | ||
result.current.onSelectAll(); | ||
}); | ||
|
||
expect(result.current.getFilter()).toEqual(null); | ||
}); | ||
|
||
it('getFilter should return rule list filter when selecting all', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
tagsFilter: ['test: 123'], | ||
searchText: 'rules*', | ||
}) | ||
); | ||
|
||
act(() => { | ||
result.current.onSelectAll(); | ||
}); | ||
|
||
expect(result.current.getFilter()?.arguments.length).toEqual(2); | ||
}); | ||
|
||
it('getFilter should return rule list filter and exclude ids when selecting all with excluded ids', async () => { | ||
const { result } = renderHook(() => | ||
useBulkEditSelect({ | ||
items, | ||
totalItemCount: 4, | ||
tagsFilter: ['test: 123'], | ||
searchText: 'rules*', | ||
}) | ||
); | ||
|
||
act(() => { | ||
result.current.onSelectAll(); | ||
result.current.onSelectRow(items[0]); | ||
}); | ||
|
||
expect(result.current.getFilter()?.arguments.length).toEqual(2); | ||
expect(result.current.getFilter()?.arguments[1].arguments[0].arguments).toEqual([ | ||
expect.objectContaining({ | ||
value: 'alert.id', | ||
}), | ||
expect.objectContaining({ | ||
value: 'alert:1', | ||
}), | ||
]); | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.