-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #36793 - Added TableHooks test and reorganized SelectAll to its …
…own directory
- Loading branch information
Showing
5 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
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
99 changes: 99 additions & 0 deletions
99
webpack/assets/javascripts/react_app/components/PF4/TableIndexPage/Table/TableHooks.test.js
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,99 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks'; | ||
import { useBulkSelect } from './TableHooks'; | ||
|
||
const isSelectable = () => true; | ||
const idColumn = 'errata_id'; | ||
const metadata = { | ||
error: null, selectable: 2, subtotal: 2, total: 2, | ||
}; | ||
const results = [ | ||
{ | ||
errata_id: 'RHSA-2022:2031', | ||
id: 311, | ||
severity: 'Low', | ||
type: 'security', | ||
}, | ||
{ | ||
errata_id: 'RHSA-2022:2110', | ||
id: 17, | ||
severity: 'Low', | ||
type: 'security', | ||
}, | ||
]; | ||
|
||
it('returns a scoped search string based on inclusionSet', () => { | ||
const { result } = renderHook(() => useBulkSelect({ | ||
results, | ||
metadata, | ||
idColumn, | ||
isSelectable, | ||
})); | ||
|
||
act(() => { | ||
result.current.selectOne(true, 'RHSA-2022:2031'); | ||
}); | ||
|
||
expect(result.current.fetchBulkParams()).toBe('errata_id ^ (RHSA-2022:2031)'); | ||
}); | ||
|
||
it('returns a scoped search string based on exclusionSet', () => { | ||
const { result } = renderHook(() => useBulkSelect({ | ||
results, | ||
metadata, | ||
idColumn, | ||
isSelectable, | ||
})); | ||
|
||
act(() => { | ||
result.current.selectAll(true); | ||
}); | ||
|
||
act(() => { | ||
result.current.selectOne(false, 'RHSA-2022:2031'); | ||
}); | ||
|
||
expect(result.current.fetchBulkParams()).toBe('errata_id !^ (RHSA-2022:2031)'); | ||
}); | ||
|
||
it('adds search query to scoped search string based on exclusionSet', () => { | ||
const { result } = renderHook(() => useBulkSelect({ | ||
results, | ||
metadata, | ||
idColumn, | ||
isSelectable, | ||
})); | ||
|
||
act(() => { | ||
result.current.updateSearchQuery('type=security'); | ||
}); | ||
|
||
act(() => { | ||
result.current.selectAll(true); | ||
}); | ||
|
||
act(() => { | ||
result.current.selectOne(false, 'RHSA-2022:2031'); | ||
}); | ||
|
||
expect(result.current.fetchBulkParams()).toBe('type=security and errata_id !^ (RHSA-2022:2031)'); | ||
}); | ||
|
||
it('adds filter dropdown query to scoped search string', () => { | ||
const { result } = renderHook(() => useBulkSelect({ | ||
results, | ||
metadata, | ||
idColumn, | ||
isSelectable, | ||
filtersQuery: 'severity=Low', | ||
})); | ||
|
||
act(() => { | ||
result.current.selectAll(true); | ||
}); | ||
|
||
act(() => { | ||
result.current.selectOne(false, 'RHSA-2022:2031'); | ||
}); | ||
|
||
expect(result.current.fetchBulkParams()).toBe('severity=Low and errata_id !^ (RHSA-2022:2031)'); | ||
}); |