-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VULN-2063 chore: add unit tests for column management (#1406)
* VULN-2063 chore: add unit tests for column management * changes based on PR review Co-authored-by: msajdik <[email protected]>
- Loading branch information
1 parent
0aef3cd
commit 64ff02d
Showing
2 changed files
with
1,259 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
src/Components/SmartComponents/Modals/ColumnManagementModal.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,107 @@ | ||
import React from 'react'; | ||
import { mountWithIntl } from '../../../Helpers/MiscHelper'; | ||
import ColumnManagementModal from './ColumnManagementModal'; | ||
import toJson from 'enzyme-to-json'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { expandable, nowrap, sortable, wrappable } from '@patternfly/react-table'; | ||
|
||
export const SYSTEM_DETAILS_HEADER = [ | ||
{ | ||
title: 'unhidable item', | ||
key: 'unhidable_item', | ||
transforms: [sortable], | ||
columnTransforms: [wrappable], | ||
cellFormatters: [expandable], | ||
isShownByDefault: true, | ||
isUnhidable: true | ||
}, | ||
{ | ||
title: 'is shown by default item', | ||
key: 'is_show_by_default_item', | ||
transforms: [sortable, wrappable], | ||
isShownByDefault: true | ||
}, | ||
{ | ||
title: 'unchecked item 1', | ||
key: 'unchecked_item_1', | ||
transforms: [sortable, wrappable], | ||
columnTransforms: [nowrap], | ||
isShownByDefault: false | ||
}, | ||
{ | ||
title: 'unchecked item 2', | ||
key: 'unchecked_item_2', | ||
transforms: [sortable, wrappable], | ||
isShownByDefault: false | ||
}, | ||
|
||
]; | ||
|
||
let wrapper; | ||
beforeEach(() => { | ||
wrapper = mountWithIntl( | ||
<Router> | ||
<ColumnManagementModal appliedColumns={SYSTEM_DETAILS_HEADER} | ||
applyColumns={null} | ||
isModalOpen={true} | ||
setModalOpen={null}/> | ||
</Router> | ||
); | ||
}); | ||
|
||
describe('ColumnManagementModal', () => { | ||
it('Should match snapshots', () => { | ||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
it('Should render isShownByDefault as checked', () => { | ||
const checkBoxes = wrapper.find('DataListCheck'); | ||
|
||
expect(checkBoxes.get(0).props.checked === true); | ||
expect(checkBoxes.get(1).props.checked === true); | ||
expect(checkBoxes.get(2).props.checked === false); | ||
expect(checkBoxes.get(3).props.checked === false); | ||
}); | ||
|
||
it('Should uncheck second item', () => { | ||
const checkBoxes = wrapper.find('DataListCheck'); | ||
|
||
checkBoxes.at(1).simulate('click'); | ||
|
||
expect(checkBoxes.get(1).props.checked === false); | ||
}); | ||
|
||
it('Should isUnhidable item by disabled', () => { | ||
const checkBoxes = wrapper.find('DataListCheck'); | ||
|
||
expect(checkBoxes.get(0).props.disabled === true); | ||
}); | ||
|
||
it('Should select all items', () => { | ||
const checkBoxes = wrapper.find('DataListCheck'); | ||
const selectAllButton = wrapper.find({ variant: 'link' }).first(); | ||
|
||
selectAllButton.simulate('click'); | ||
|
||
expect(checkBoxes.get(0).props.checked === true); | ||
expect(checkBoxes.get(1).props.checked === true); | ||
expect(checkBoxes.get(2).props.checked === true); | ||
expect(checkBoxes.get(3).props.checked === true); | ||
}); | ||
|
||
it('Should reset to default select all default items and unselect all other items', () => { | ||
const checkBoxes = wrapper.find('DataListCheck'); | ||
const resetToDefaultButton = wrapper.find({ variant: 'link' }).last(); | ||
|
||
checkBoxes.at(2).simulate('click'); | ||
checkBoxes.at(3).simulate('click'); | ||
|
||
resetToDefaultButton.simulate('click'); | ||
|
||
expect(checkBoxes.get(0).props.checked === true); | ||
expect(checkBoxes.get(1).props.checked === true); | ||
expect(checkBoxes.get(2).props.checked === false); | ||
expect(checkBoxes.get(3).props.checked === false); | ||
}); | ||
|
||
}); |
Oops, something went wrong.