Skip to content

Commit

Permalink
remove redundant checks, prefer toBeVisible over toBeInDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Apr 13, 2023
1 parent caad0ef commit 9fd4841
Showing 1 changed file with 8 additions and 64 deletions.
72 changes: 8 additions & 64 deletions packages/components/src/color-picker/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,12 @@ describe( 'ColorPicker', () => {
);

const formatSelector = screen.getByRole( 'combobox' );

if ( formatSelector === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( formatSelector ).toBeInTheDocument();
expect( formatSelector ).toBeVisible();

await user.selectOptions( formatSelector, 'hex' );

const hexInput = screen.getByRole( 'textbox' );

if ( hexInput === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( hexInput ).toBeInTheDocument();
expect( hexInput ).toBeVisible();

await user.clear( hexInput );
await user.type( hexInput, '1ab' );
Expand All @@ -96,26 +82,12 @@ describe( 'ColorPicker', () => {
);

const formatSelector = screen.getByRole( 'combobox' );

if ( formatSelector === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( formatSelector ).toBeInTheDocument();
expect( formatSelector ).toBeVisible();

await user.selectOptions( formatSelector, 'hex' );

const hexInput = screen.getByRole( 'textbox' );

if ( hexInput === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( hexInput ).toBeInTheDocument();
expect( hexInput ).toBeVisible();

await user.clear( hexInput );
await user.type( hexInput, '1ab' );
Expand Down Expand Up @@ -144,27 +116,13 @@ describe( 'ColorPicker', () => {
);

const formatSelector = screen.getByRole( 'combobox' );

if ( formatSelector === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( formatSelector ).toBeInTheDocument();
expect( formatSelector ).toBeVisible();

await user.selectOptions( formatSelector, 'rgb' );

const inputElement =
screen.getAllByRole( 'spinbutton' )[ inputIndex ];

if ( inputElement === null ) {
throw new Error(
`The ${ colorInput } input could not be found`
);
}

expect( inputElement ).toBeInTheDocument();
expect( inputElement ).toBeVisible();

await user.clear( inputElement );
await user.type( inputElement, '125' );
Expand Down Expand Up @@ -193,27 +151,13 @@ describe( 'ColorPicker', () => {
);

const formatSelector = screen.getByRole( 'combobox' );

if ( formatSelector === null ) {
throw new Error(
'The color format selector could not be found'
);
}

expect( formatSelector ).toBeInTheDocument();
expect( formatSelector ).toBeVisible();

await user.selectOptions( formatSelector, 'hsl' );

const inputElement =
screen.getAllByRole( 'spinbutton' )[ inputIndex ];

if ( inputElement === null ) {
throw new Error(
`The ${ colorInput } input could not be found`
);
}

expect( inputElement ).toBeInTheDocument();
expect( inputElement ).toBeVisible();

await user.clear( inputElement );
await user.type( inputElement, '75' );
Expand Down

0 comments on commit 9fd4841

Please sign in to comment.