Skip to content

Commit

Permalink
VULN-2063 chore: add unit tests for column management (#1406)
Browse files Browse the repository at this point in the history
* VULN-2063 chore: add unit tests for column management

* changes based on PR review

Co-authored-by: msajdik <[email protected]>
  • Loading branch information
MichalSajdik and msajdik authored Dec 22, 2021
1 parent 0aef3cd commit 64ff02d
Show file tree
Hide file tree
Showing 2 changed files with 1,259 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/Components/SmartComponents/Modals/ColumnManagementModal.test.js
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);
});

});
Loading

0 comments on commit 64ff02d

Please sign in to comment.