Skip to content

Commit

Permalink
BorderBoxControl test: wait for color picker popover to appear
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Dec 18, 2022
1 parent 8690500 commit 0b7fbd5
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions packages/components/src/border-box-control/test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { act } from 'react-test-renderer';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,6 +49,10 @@ const props = {
const toggleLabelRegex = /Border color( and style)* picker/;
const colorPickerRegex = /Border color picker/;

function getWrappingPopoverElement( element ) {
return element.closest( '.components-popover' );
}

describe( 'BorderBoxControl', () => {
describe( 'Linked view rendering', () => {
it( 'should render correctly when no value provided', () => {
Expand Down Expand Up @@ -187,7 +190,15 @@ describe( 'BorderBoxControl', () => {

const colorButton = screen.getByLabelText( colorPickerRegex );
await user.click( colorButton );
await act( () => Promise.resolve() );

// Wait for color picker popover to fully appear
await waitFor( () =>
expect(
getWrappingPopoverElement(
screen.getByLabelText( 'Custom color picker.' )
)
).toBePositionedPopover()
);

const styleLabel = screen.queryByText( 'Style' );
const solidButton = screen.queryByRole( 'button', {
Expand Down Expand Up @@ -277,8 +288,22 @@ describe( 'BorderBoxControl', () => {
);

const colorButtons = screen.getAllByLabelText( colorPickerRegex );
expect( colorButtons ).toHaveLength( 4 );

for ( let i = 0; i < colorButtons.length; i++ ) {
// Click on the color button to show the color picker popover.
await user.click( colorButtons[ 0 ] );

// Wait for color picker popover to fully appear
const colorPickerButton = screen.getByRole( 'button', {
name: 'Custom color picker.',
} );
await waitFor( () =>
expect(
getWrappingPopoverElement( colorPickerButton )
).toBePositionedPopover()
);

function assertStyleOptionsMissing() {
const styleLabel = screen.queryByText( 'Style' );
const solidButton = screen.queryByRole( 'button', {
name: 'Solid',
Expand All @@ -294,23 +319,10 @@ describe( 'BorderBoxControl', () => {
expect( solidButton ).not.toBeInTheDocument();
expect( dashedButton ).not.toBeInTheDocument();
expect( dottedButton ).not.toBeInTheDocument();
}

await user.click( colorButtons[ 0 ] );
assertStyleOptionsMissing();
await user.click( colorButtons[ 0 ] );

await user.click( colorButtons[ 1 ] );
assertStyleOptionsMissing();
await user.click( colorButtons[ 1 ] );

await user.click( colorButtons[ 2 ] );
assertStyleOptionsMissing();
await user.click( colorButtons[ 2 ] );

await user.click( colorButtons[ 3 ] );
assertStyleOptionsMissing();
await user.click( colorButtons[ 3 ] );
// Click again to hide the popover.
await user.click( colorButtons[ 0 ] );
}
} );
} );

Expand Down

1 comment on commit 0b7fbd5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3724168174
📝 Reported issues:

Please sign in to comment.