Skip to content

Commit

Permalink
Refactor some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Oct 4, 2022
1 parent 722597c commit 5a9d0ad
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions packages/components/src/alignment-matrix-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,35 @@ const getControl = () => {
return screen.getByRole( 'grid' );
};

const getCells = () => {
return within( getControl() ).getAllByRole( 'gridcell' );
const getCell = ( name ) => {
return within( getControl() ).getByRole( 'gridcell', { name } );
};

describe( 'AlignmentMatrixControl', () => {
describe( 'Basic rendering', () => {
it( 'should render', () => {
render( <AlignmentMatrixControl /> );

expect( getControl() ).toBeTruthy();
expect( getControl() ).toBeInTheDocument();
} );
} );

describe( 'Change value', () => {
it( 'should change value on cell click', () => {
const spy = jest.fn();
const alignments = [ 'center left', 'center center', 'bottom center' ];

render(
<AlignmentMatrixControl value={ 'center' } onChange={ spy } />
);
it.each( alignments )(
'should change value on %s cell click',
( alignment ) => {
const spy = jest.fn();

const cells = getCells();
render(
<AlignmentMatrixControl value="center" onChange={ spy } />
);

cells[ 3 ].focus();
getCell( alignment ).focus();

expect( spy.mock.calls[ 0 ][ 0 ] ).toBe( 'center left' );

cells[ 4 ].focus();

expect( spy.mock.calls[ 1 ][ 0 ] ).toBe( 'center center' );

cells[ 7 ].focus();

expect( spy.mock.calls[ 2 ][ 0 ] ).toBe( 'bottom center' );
} );
expect( spy ).toHaveBeenCalledWith( alignment );
}
);
} );
} );

0 comments on commit 5a9d0ad

Please sign in to comment.