Skip to content

Commit

Permalink
Refs #36793 - Added TableHooks test and reorganized SelectAll to its …
Browse files Browse the repository at this point in the history
…own directory
  • Loading branch information
parthaa committed Oct 19, 2023
1 parent 9de9103 commit b4c8eee
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Td } from '@patternfly/react-table';
import { ToolbarItem } from '@patternfly/react-core';
import { translate as __ } from '../../common/I18n';
import TableIndexPage from '../PF4/TableIndexPage/TableIndexPage';
import { ActionKebab } from '../PF4/TableIndexPage/ActionKebab';
import { ActionKebab } from './ActionKebab';
import { HOSTS_API_PATH, API_REQUEST_KEY } from '../../routes/Hosts/constants';
import { selectKebabItems } from './Selectors';
import { useAPI } from '../../common/hooks/API/APIHooks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
DropdownToggleCheckbox,
DropdownItem,
} from '@patternfly/react-core';
import { translate as __ } from '../../../../common/I18n';
import { noop } from '../../../../common/helpers';
import { translate as __ } from '../../../../../common/I18n';
import { noop } from '../../../../../common/helpers';

import './SelectAllCheckbox.scss';

Expand Down
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)');
});

0 comments on commit b4c8eee

Please sign in to comment.