-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from fhlavac/checkbox
Add DataViewCheckbox component
- Loading branch information
Showing
11 changed files
with
540 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import { DataViewCheckboxFilter, DataViewCheckboxFilterProps } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter'; | ||
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar'; | ||
|
||
describe('DataViewCheckboxFilter component', () => { | ||
const defaultProps: DataViewCheckboxFilterProps = { | ||
filterId: 'test-checkbox-filter', | ||
title: 'Test checkbox filter', | ||
value: [ 'workspace-one' ], | ||
options: [ | ||
{ label: 'Workspace one', value: 'workspace-one' }, | ||
{ label: 'Workspace two', value: 'workspace-two' }, | ||
{ label: 'Workspace three', value: 'workspace-three' }, | ||
], | ||
}; | ||
|
||
it('renders a checkbox filter with options', () => { | ||
const onChange = cy.stub().as('onChange'); | ||
|
||
cy.mount( | ||
<DataViewToolbar filters={<DataViewCheckboxFilter {...defaultProps} onChange={onChange} />} /> | ||
); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-toggle"]') | ||
.contains('Test checkbox filter') | ||
.should('be.visible'); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-badge"]') | ||
.should('exist') | ||
.contains('1'); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-toggle"]').click(); | ||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-menu"]').should('be.visible'); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-menu"]') | ||
.find('li') | ||
.should('have.length', 3) | ||
.first() | ||
.contains('Workspace one'); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-menu"]') | ||
.find('li') | ||
.first() | ||
.find('input[type="checkbox"]') | ||
.should('be.checked'); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-menu"]') | ||
.find('li') | ||
.eq(1) | ||
.find('input[type="checkbox"]') | ||
.click(); | ||
|
||
cy.get('@onChange').should('have.been.calledWith', Cypress.sinon.match.object, [ 'workspace-two', 'workspace-one' ]); | ||
}); | ||
|
||
it('renders a checkbox filter with no options selected', () => { | ||
const emptyProps = { ...defaultProps, value: [] }; | ||
|
||
cy.mount( | ||
<DataViewToolbar filters={<DataViewCheckboxFilter {...emptyProps} />} /> | ||
); | ||
|
||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-toggle"]').contains('Test checkbox filter'); | ||
cy.get('[data-ouia-component-id="DataViewCheckboxFilter-badge"]').should('not.exist'); | ||
}); | ||
}); |
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
24 changes: 24 additions & 0 deletions
24
packages/module/src/DataViewCheckboxFilter/DataViewCheckboxFilter.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,24 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import DataViewCheckboxFilter, { DataViewCheckboxFilterProps } from './DataViewCheckboxFilter'; | ||
import DataViewToolbar from '../DataViewToolbar'; | ||
|
||
describe('DataViewCheckboxFilter component', () => { | ||
const defaultProps: DataViewCheckboxFilterProps = { | ||
filterId: 'test-checkbox-filter', | ||
title: 'Test Checkbox Filter', | ||
value: [ 'workspace-one' ], | ||
options: [ | ||
{ label: 'Workspace one', value: 'workspace-one' }, | ||
{ label: 'Workspace two', value: 'workspace-two' }, | ||
{ label: 'Workspace three', value: 'workspace-three' }, | ||
], | ||
}; | ||
|
||
it('should render correctly', () => { | ||
const { container } = render( | ||
<DataViewToolbar filters={<DataViewCheckboxFilter {...defaultProps} />} /> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.