Skip to content

Commit

Permalink
Merge changes from WP66-beta1 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHerman committed Jul 25, 2024
2 parents ecd84bb + d91b12b commit 926a80d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 32 deletions.
29 changes: 18 additions & 11 deletions .dev/tests/cypress/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Returns true if styles tab exists false otherwise.
*/
export function selectStylesTabIfExists() {
cy.get( '.edit-post-sidebar' ).find( 'button[aria-label="Styles"]' ).click();
cy.get( sidebarClass() ).find( 'button[aria-label="Styles"]' ).click();
}

/**
Expand Down Expand Up @@ -172,7 +172,11 @@ export function addNewGroupToPost() {
* From inside the WordPress editor open the CoBlocks Gutenberg editor panel
*/
export function savePage() {
cy.get( '.editor-post-publish-button.is-primary' ).click();
if ( isWP66AtLeast() ) {
cy.get( '.editor-header__settings button.is-primary' ).click();
} else {
cy.get( '.edit-post-header__settings button.is-primary' ).click();
}

cy.get( '.components-editor-notices__snackbar', { timeout: 120000 } ).should( 'not.be.empty' );

Expand Down Expand Up @@ -263,7 +267,7 @@ export function getBlockSlug() {
export function setBlockStyle( style ) {
openSettingsPanel( RegExp( 'styles', 'i' ) );

cy.get( '.edit-post-sidebar [class*="editor-block-styles"]' )
cy.get( sidebarClass() + ' [class*="editor-block-styles"]' )
.contains( RegExp( style, 'i' ) )
.click();
}
Expand All @@ -276,7 +280,7 @@ export function setBlockStyle( style ) {
export function setNewBlockStyle( style ) {
selectStylesTabIfExists();

cy.get( '.edit-post-sidebar [class*="editor-block-styles"]' )
cy.get( sidebarClass() + ' [class*="editor-block-styles"]' )
.contains( RegExp( style, 'i' ) )
.click();
}
Expand Down Expand Up @@ -350,7 +354,7 @@ export function setBlockAlignment( alignment ) {
export function setInputValue( panelName, settingName, value, ignoreCase = true ) {
openSettingsPanel( ignoreCase ? RegExp( panelName, 'i' ) : panelName );

cy.get( '.edit-post-sidebar' )
cy.get( sidebarClass() )
.contains( ignoreCase ? RegExp( settingName, 'i' ) : settingName ).not( '.block-editor-block-card__description' )
.then( ( $settingSection ) => {
cy.get( Cypress.$( $settingSection ).parent() )
Expand Down Expand Up @@ -557,7 +561,7 @@ export function addCustomBlockClass( classes, blockID = '' ) {
}
} );

cy.get( 'div.edit-post-sidebar' )
cy.get( 'div' + sidebarClass() )
.contains( /Additional CSS/i )
.next( 'input' )
.then( ( $inputElem ) => {
Expand Down Expand Up @@ -612,15 +616,14 @@ export function isNotWPLocalEnv() {
return Cypress.env( 'testURL' ) !== 'http://localhost:8889';
}

// A condition to determine if we are testing on WordPress 6.4+
export function isWP64AtLeast() {
return Cypress.$( "[class*='branch-6-4']" ).length > 0 || Cypress.$( "[class*='branch-6-5']" ).length > 0;
}

export function isWP65AtLeast() {
return Cypress.$( "[class*='branch-6-5']" ).length > 0 || Cypress.$( "[class*='branch-6-6']" ).length > 0;
}

export function isWP66AtLeast() {
return Cypress.$( "[class*='branch-6-6']" ).length > 0 || Cypress.$( "[class*='branch-6-7']" ).length > 0;
}

function getIframeDocument( containerClass ) {
return cy.get( containerClass + ' iframe' ).its( '0.contentDocument' ).should( 'exist' );
}
Expand All @@ -631,3 +634,7 @@ export function getIframeBody( containerClass ) {
// chaining more Cypress commands, like ".find(...)"
.then( cy.wrap );
}

export const sidebarClass = () => {
return isWP66AtLeast() ? '.editor-sidebar__panel' : '.edit-post-sidebar';
};
6 changes: 3 additions & 3 deletions src/blocks/features/test/features.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ describe( 'Test CoBlocks Features Block', function() {

cy.get( '.wp-block-coblocks-feature' ).should( 'have.length', 2 );

cy.get( '.edit-post-sidebar' ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 1 );
cy.get( helpers.sidebarClass() ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 1 );

cy.get( '.wp-block-coblocks-feature' ).should( 'have.length', 2 ); // Children should never decrease with column count

cy.get( '.edit-post-sidebar' ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 3 );
cy.get( helpers.sidebarClass() ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 3 );

cy.get( '.wp-block-coblocks-feature' ).should( 'have.length', 3 );

cy.get( '.edit-post-sidebar' ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 4 );
cy.get( helpers.sidebarClass() ).find( 'input[aria-label="Columns"][type="number"]' ).focus().type( '{selectall}' ).type( 4 );

cy.get( '.wp-block-coblocks-feature' ).should( 'have.length', 4 );

Expand Down
4 changes: 2 additions & 2 deletions src/blocks/form/test/form.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ describe( 'Test CoBlocks Form Block', function() {
cy.get( '[data-type="coblocks/form"]' )
.click( { force: true } );

cy.get( 'div.edit-post-sidebar' )
cy.get( 'div' + helpers.sidebarClass() )
.contains( /Subject/i )
.next( 'input' )
.then( ( $inputElem ) => {
Expand Down Expand Up @@ -479,7 +479,7 @@ describe( 'Test CoBlocks Form Block', function() {
cy.get( '[data-type="coblocks/form"]' )
.click( { force: true } );

cy.get( 'div.edit-post-sidebar' )
cy.get( 'div' + helpers.sidebarClass() )
.contains( /Success Message/i )
.next( 'textarea' )
.then( ( $inputElem ) => {
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/gif/test/gif.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe( 'Test CoBlocks Gif Block', function() {

cy.get( '.wp-block-coblocks-gif' ).find( 'img' ).should( 'have.length', 1 );

cy.get( '.edit-post-sidebar' ).contains( /Alt text/ ).parent().find( 'textarea' ).type( gifText );
cy.get( helpers.sidebarClass() ).contains( /Alt text/ ).parent().find( 'textarea' ).type( gifText );

helpers.savePage();

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/hero/test/hero.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe( 'Test CoBlocks Hero Block', function() {

cy.get( '.wp-block-coblocks-hero' ).find( '.is-fullscreen' ).should( 'exist' );

cy.get( '.edit-post-sidebar' ).find( 'div[aria-label="Select layout"]' ).children().each( ( $layoutButton ) => {
cy.get( helpers.sidebarClass() ).find( 'div[aria-label="Select layout"]' ).children().each( ( $layoutButton ) => {
cy.get( $layoutButton ).click();
} );

Expand Down
4 changes: 2 additions & 2 deletions src/blocks/post-carousel/test/post-carousel.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe( 'Test CoBlocks Post Carousel Block', function() {
it( 'Test the post-carousel block custom classes.', function() {
helpers.addBlockToPost( 'coblocks/post-carousel', true );

cy.get( '.edit-post-sidebar' ).contains( /post carousel settings/i ).click( { force: true } );
cy.get( helpers.sidebarClass() ).contains( /post carousel settings/i ).click( { force: true } );

cy.get( '.edit-post-sidebar' ).contains( /feed settings/i ).click( { force: true } );
cy.get( helpers.sidebarClass() ).contains( /feed settings/i ).click( { force: true } );

helpers.addCustomBlockClass( 'my-custom-class', 'post-carousel' );

Expand Down
4 changes: 2 additions & 2 deletions src/blocks/posts/test/posts.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ describe( 'Test CoBlocks Posts Block', function() {
it( 'Test posts block custom classes.', function() {
helpers.addBlockToPost( 'coblocks/posts', true );

cy.get( '.edit-post-sidebar' ).contains( /posts settings/i ).click( { force: true } );
cy.get( helpers.sidebarClass() ).contains( /posts settings/i ).click( { force: true } );

cy.get( '.edit-post-sidebar' ).contains( /feed settings/i ).click( { force: true } );
cy.get( helpers.sidebarClass() ).contains( /feed settings/i ).click( { force: true } );

helpers.addCustomBlockClass( 'my-custom-class', 'posts' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ describe( 'Test CoBlocks Pricing Table Item Block', function() {

featuresText = ' ' + featuresText;

if ( helpers.isWP64AtLeast() ) {
firstTableItem().find( '.wp-block-coblocks-pricing-table-item__features' ).should( 'have.text', featuresText );
} else {
firstTableItem().find( '.wp-block-coblocks-pricing-table-item__features > li' ).should( 'have.text', featuresText );
}
firstTableItem().find( '.wp-block-coblocks-pricing-table-item__features' ).should( 'have.text', featuresText );

firstTableItem().find( '.wp-block-button' ).should( 'have.text', buttonText );
} );
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/row/test/row.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe( 'Test CoBlocks Row Block', function() {

cy.get( '.wp-block-coblocks-row' ).click( { force: true } );

cy.get( '.edit-post-sidebar' ).contains( /row settings/i ).click();
cy.get( helpers.sidebarClass() ).contains( /row settings/i ).click();

helpers.addCustomBlockClass( 'my-custom-class', 'row' );

Expand Down
4 changes: 2 additions & 2 deletions src/blocks/services/service/test/service.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe( 'Test CoBlocks Service Block', function() {
}
} );

cy.get( 'div.edit-post-sidebar' )
cy.get( 'div' + helpers.sidebarClass() )
.contains( /Additional CSS/i )
.next( 'input' )
.then( ( $inputElem ) => {
Expand All @@ -56,7 +56,7 @@ describe( 'Test CoBlocks Service Block', function() {
}
} );

cy.get( 'div.edit-post-sidebar' )
cy.get( 'div' + helpers.sidebarClass() )
.contains( /Additional CSS/i )
.next( 'input' )
.then( ( $inputElem ) => {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/shape-divider/test/shape-divider.cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe( 'Test CoBlocks Shape Divider Block', function() {

helpers.openSettingsPanel( 'Divider settings' );

cy.get( '.edit-post-sidebar' )
cy.get( helpers.sidebarClass() )
.contains( 'Shape height' ).not( '.block-editor-block-card__description' )
.then( ( $settingSection ) => {
cy.get( Cypress.$( $settingSection ).parent().parent() )
Expand All @@ -69,7 +69,7 @@ describe( 'Test CoBlocks Shape Divider Block', function() {
.type( `{selectall}${ shapeHeight }` );
} );

cy.get( '.edit-post-sidebar' )
cy.get( helpers.sidebarClass() )
.contains( 'Background height' ).not( '.block-editor-block-card__description' )
.then( ( $settingSection ) => {
cy.get( Cypress.$( $settingSection ).parent().parent() )
Expand Down

0 comments on commit 926a80d

Please sign in to comment.