Skip to content

Commit

Permalink
WPEX-3610 - add category for Coblocks patterns (#2599)
Browse files Browse the repository at this point in the history
* add category for coblocks patterns

* Add e2e test to make sure that  duplicate pattern does not crash

* php linting

* Make it work for WP 6.4 as well

* linting

---------

Co-authored-by: Olivier Lafleur <olafleur@godaddy.com>
  • Loading branch information
snovosel-godaddy and olafleur-godaddy authored Mar 18, 2024
1 parent 9c358fa commit daf468d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/blocks/counter/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ function coblocks_counter_register_block_patterns() {
'title' => __( 'Counter and Icon block Group', 'coblocks' ),
'blockTypes' => array( 'core/group', 'coblocks/counter', 'coblocks/icon' ),
'content' => '<!-- wp:group {"backgroundColor":"tertiary"} --><div class="wp-block-group has-tertiary-background-color has-background"><!-- wp:coblocks/icon {"icon":"build","contentAlign":"center","iconColor":"primary","className":"is-style-outlined"} /--><!-- wp:coblocks/counter {"align":"center","counterDescription":"Hours Worked","counterText":"\u003cstrong\u003e1000\u003c/strong\u003e","textColor":"primary","fontSize":"small"} --><div class="wp-block-coblocks-counter has-text-align-center has-primary-color has-text-color has-small-font-size" data-counter-speed="1"><strong>1000</strong></div><div class="wp-block-coblocks-counter has-text-align-center has-primary-color has-text-color has-small-font-size" data-counter-speed="1">Hours Worked</div><!-- /wp:coblocks/counter --></div><!-- /wp:group -->',
'categories' => array( 'coblocks' ),
);

$multi_digits_array = array(
'title' => __( 'Counter with multiple inline digits', 'coblocks' ),
'blockTypes' => array( 'coblocks/counter' ),
'content' => '<!-- wp:coblocks/counter {"align":"center","counterDescription":"Since Last Incident","counterText":"\u003cmeta charset=\u0022utf-8\u0022\u003e10 days, 20 hours","fontSize":"small"} --><div class="wp-block-coblocks-counter has-text-align-center has-small-font-size" data-counter-speed="1"><meta charset="utf-8">10 days, 20 hours</div><div class="wp-block-coblocks-counter has-text-align-center has-small-font-size" data-counter-speed="1">Since Last Incident</div><!-- /wp:coblocks/counter -->',
'categories' => array( 'coblocks' ),
);

if ( $should_include_viewport ) {
Expand All @@ -35,6 +37,13 @@ function coblocks_counter_register_block_patterns() {
register_block_pattern( 'counter/with-icon', $icon_array );
register_block_pattern( 'counter/with-multiple-digits', $multi_digits_array );

register_block_pattern_category(
'coblocks',
array(
'label' => 'Coblocks',
'description' => 'Coblocks Patterns',
)
);
}

add_action( 'init', 'coblocks_counter_register_block_patterns' );
Expand Down
21 changes: 21 additions & 0 deletions src/utils/duplicate-pattern.cypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { isWP65AtLeast } from '../../.dev/tests/cypress/helpers';

describe( 'Category for CoBlocks patterns', () => {
beforeEach( () => {
cy.visit( Cypress.env( 'testURL' ) + '/wp-admin/site-editor.php?path=%2Fpatterns&categoryType=pattern&categoryId=coblocks' );
} );

it( 'can be duplicated without errors', () => {
cy.get( '[aria-label="Actions"]' ).first().click();

cy.get( '[role="menuitem"]' ).contains( 'Duplicate' ).click( { force: true } );

if ( isWP65AtLeast() ) {
cy.get( '.components-modal__header-heading-container' ).contains( 'Duplicate pattern' );

cy.get( '.components-button.is-primary ' ).contains( 'Duplicate' ).click();
}

cy.get( '.components-snackbar__content' ).contains( 'duplicated' );
} );
} );

0 comments on commit daf468d

Please sign in to comment.