Skip to content

Commit

Permalink
changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Mar 19, 2023
1 parent 431b2ba commit a293716
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
29 changes: 13 additions & 16 deletions packages/block-library/src/cover/test/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
registerAllCoreBlocks,
unRegisterAllBlocks,
createTestBlock,
selectBlock,
} from 'test/integration/helpers/integration-test-editor';

async function setup( testBlock ) {
const block = await createTestBlock( testBlock.name, testBlock.attributes );
return initializeEditor( { testBlocks: [ block ] } );
}

async function createAndSelectCoverBlock() {
async function createAndselectBlock() {
await userEvent.click(
screen.getByRole( 'button', {
name: 'Color: Black',
Expand All @@ -32,10 +33,6 @@ async function createAndSelectCoverBlock() {
);
}

async function selectCoverBlock() {
await userEvent.click( screen.getByLabelText( 'Block: Cover' ) );
}

describe( 'Cover block', () => {
beforeAll( () => {
registerAllCoreBlocks();
Expand Down Expand Up @@ -98,7 +95,7 @@ describe( 'Cover block', () => {
describe( 'Block toolbar', () => {
test( 'full height toggle sets minHeight attributes to 100vh when clicked', async () => {
await setup( { name: 'core/cover' } );
await createAndSelectCoverBlock();
await createAndselectBlock();

expect( screen.getByLabelText( 'Block: Cover' ) ).not.toHaveStyle(
' min-height: 100vh;'
Expand All @@ -115,7 +112,7 @@ describe( 'Cover block', () => {

test( 'content position button sets content position', async () => {
await setup( { name: 'core/cover' } );
await createAndSelectCoverBlock();
await createAndselectBlock();

await userEvent.click(
screen.getByLabelText( 'Change content position' )
Expand Down Expand Up @@ -160,7 +157,7 @@ describe( 'Cover block', () => {
},
} );

await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
expect(
screen.getByRole( 'button', {
name: 'Media settings',
Expand All @@ -179,7 +176,7 @@ describe( 'Cover block', () => {
expect( screen.getByLabelText( 'Block: Cover' ) ).not.toHaveClass(
'has-parallax'
);
await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
await userEvent.click(
screen.getByLabelText( 'Fixed background' )
);
Expand All @@ -198,7 +195,7 @@ describe( 'Cover block', () => {
expect( screen.getByLabelText( 'Block: Cover' ) ).not.toHaveClass(
'is-repeated'
);
await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
await userEvent.click(
screen.getByLabelText( 'Repeated background' )
);
Expand All @@ -215,7 +212,7 @@ describe( 'Cover block', () => {
},
} );

await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
await userEvent.clear( screen.getByLabelText( 'Left' ) );
await userEvent.type( screen.getByLabelText( 'Left' ), '100' );
// eslint-disable-next-line testing-library/no-node-access
Expand All @@ -233,7 +230,7 @@ describe( 'Cover block', () => {
},
} );

await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
await userEvent.type(
screen.getByLabelText( 'Alt text (alternative text)' ),
'Me'
Expand All @@ -249,7 +246,7 @@ describe( 'Cover block', () => {
},
} );

await selectCoverBlock();
await selectBlock( 'Block: Cover', screen );
// eslint-disable-next-line testing-library/no-node-access
const img = container.getElementsByClassName(
'wp-block-cover__image-background'
Expand All @@ -269,7 +266,7 @@ describe( 'Cover block', () => {
test( 'applies selected opacity to block when number control value changed', async () => {
const { container } = await setup( { name: 'core/cover' } );

await createAndSelectCoverBlock();
await createAndselectBlock();

// eslint-disable-next-line testing-library/no-node-access
const overlay = container.getElementsByClassName(
Expand Down Expand Up @@ -299,7 +296,7 @@ describe( 'Cover block', () => {
test( 'applies selected opacity to block when slider moved', async () => {
const { container } = await setup( { name: 'core/cover' } );

await createAndSelectCoverBlock();
await createAndselectBlock();

// eslint-disable-next-line testing-library/no-node-access
const overlay = container.getElementsByClassName(
Expand Down Expand Up @@ -328,7 +325,7 @@ describe( 'Cover block', () => {
describe( 'Dimensions panel', () => {
test( 'sets minHeight attribute when number control value changed', async () => {
await setup( { name: 'core/cover' } );
await createAndSelectCoverBlock();
await createAndselectBlock();
await userEvent.click(
screen.getByRole( 'tab', {
name: 'Styles',
Expand Down
9 changes: 7 additions & 2 deletions test/integration/helpers/integration-test-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* WordPress dependencies
Expand Down Expand Up @@ -50,8 +51,12 @@ export function unRegisterAllBlocks() {
getBlockTypes().forEach( ( { name } ) => unregisterBlockType( name ) );
}

export function createTestBlock( name, attributes ) {
return createBlock( name, attributes || {} );
export async function selectBlock( name, screen ) {
await userEvent.click( screen.getByLabelText( name ) );
}

export function createTestBlock( name, attributes = {}, innerBlocks = [] ) {
return createBlock( name, attributes, innerBlocks );
}

/**
Expand Down

0 comments on commit a293716

Please sign in to comment.