Skip to content

Commit

Permalink
Update the cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Jun 7, 2024
1 parent 09473a7 commit 9f54a13
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cypress/component/BulkSelect.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ interface DataItem {
name: string
};

const BulkSelectTestComponent = ({ canSelectAll }: Omit<BulkSelectProps, 'onSelect' | 'selectedCount' >) => {
const BulkSelectTestComponent = ({ canSelectAll, isDataPaginated }: Omit<BulkSelectProps, 'onSelect' | 'selectedCount' >) => {
const [ selected, setSelected ] = useState<DataItem[]>([]);

const allData = [ { name: '1' }, { name: '2' }, { name: '3' }, { name: '4' }, { name: '5' }, { name: '6' } ];
const pageData = [ { name: '1' }, { name: '2' }, { name: '3' }, { name: '4' }, { name: '5' } ];
const pageDataNames = pageData.map((item) => item.name);
const pageSelected = pageDataNames.every(item => selected.find(selectedItem => selectedItem.name === item));

const handleBulkSelect = (value: BulkSelectValue) => {
value === BulkSelectValue.none && setSelected([]);
Expand All @@ -20,19 +21,20 @@ const BulkSelectTestComponent = ({ canSelectAll }: Omit<BulkSelectProps, 'onSele

return (
<BulkSelect
isDataPaginated={isDataPaginated}
canSelectAll={canSelectAll}
pageCount={pageData.length}
totalCount={allData.length}
selectedCount={selected.length}
pageSelected={selected.length > 0 && selected.length <= 5}
pagePartiallySelected={selected.length > 0 && selected.length < 5}
pageSelected={pageSelected}
pagePartiallySelected={pageDataNames.some(item => selected.find(selectedItem => selectedItem.name === item)) && !pageSelected}
onSelect={handleBulkSelect}
/>
);
};

describe('BulkSelect', () => {
it('renders the bulk select', () => {
it('renders the bulk select without all', () => {
cy.mount(
<BulkSelectTestComponent />
);
Expand All @@ -45,14 +47,14 @@ describe('BulkSelect', () => {
cy.contains('0 selected').should('not.exist');
});

it('renders the bulk select without all', () => {
it('renders the bulk select with all and without page', () => {
cy.mount(
<BulkSelectTestComponent canSelectAll />
<BulkSelectTestComponent canSelectAll isDataPaginated={false} />
);
cy.get('[data-ouia-component-id="BulkSelect-checkbox"]').should('exist');
cy.get('[data-ouia-component-id="BulkSelect-toggle"]').click();
cy.get('[data-ouia-component-id="BulkSelect-select-all"]').should('exist');
cy.get('[data-ouia-component-id="BulkSelect-select-page"]').should('exist');
cy.get('[data-ouia-component-id="BulkSelect-select-page"]').should('not.exist');
cy.get('[data-ouia-component-id="BulkSelect-select-none"]').should('exist');

cy.contains('0 selected').should('not.exist');
Expand All @@ -76,7 +78,7 @@ describe('BulkSelect', () => {
// Select none
cy.get('[data-ouia-component-id="BulkSelect-toggle"]').first().click({ force: true });
cy.get('[data-ouia-component-id="BulkSelect-select-none"]').first().click();
cy.contains('0 selected').should('not.exist');
cy.get('input[type="checkbox"]').should('not.be.checked');

// Select all
cy.get('[data-ouia-component-id="BulkSelect-toggle"]').first().click({ force: true });
Expand Down

0 comments on commit 9f54a13

Please sign in to comment.