From 87204a3961d9307c6b6c478f6af7d8ddb1b6168f Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Sat, 3 Feb 2024 02:53:18 +0530 Subject: [PATCH] remove theme specific quote pattern --- src/commands/check-block-pattern-exists.ts | 37 +++++++++++-------- .../e2e/check-block-pattern-exists.test.js | 5 +-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/commands/check-block-pattern-exists.ts b/src/commands/check-block-pattern-exists.ts index de9b489..0b62c0f 100644 --- a/src/commands/check-block-pattern-exists.ts +++ b/src/commands/check-block-pattern-exists.ts @@ -37,6 +37,10 @@ export const checkBlockPatternExists = ({ title: string; categoryValue?: string; }): void => { + // opening the inserter loads the patterns in WP trunk after 6.4.3. + cy.get('button[class*="__inserter-toggle"][aria-pressed="false"]').click(); + cy.get('button[class*="__inserter-toggle"][aria-pressed="true"]').click(); + cy.window() .then(win => { /* eslint-disable */ @@ -51,22 +55,25 @@ export const checkBlockPatternExists = ({ const { wp } = win; - const getSettings = - wp?.data?.select('core/block-editor')?.getSettings; - if (undefined !== getSettings) { - const allRegisteredPatterns = - getSettings().__experimentalBlockPatterns; + let allRegisteredPatterns; + + if (wp?.data?.select('core')?.getBlockPatterns) { + allRegisteredPatterns = wp.data.select('core').getBlockPatterns(); + } else { + allRegisteredPatterns = wp.data + .select('core/block-editor') + .getSettings().__experimentalBlockPatterns; + } - if (undefined !== allRegisteredPatterns) { - for (let i = 0; i < allRegisteredPatterns.length; i++) { - if ( - title === allRegisteredPatterns[i].title && - allRegisteredPatterns[i].categories && - allRegisteredPatterns[i].categories.includes(categoryValue) - ) { - resolve(true); - return; - } + if (undefined !== allRegisteredPatterns) { + for (let i = 0; i < allRegisteredPatterns.length; i++) { + if ( + title === allRegisteredPatterns[i].title && + allRegisteredPatterns[i].categories && + allRegisteredPatterns[i].categories.includes(categoryValue) + ) { + resolve(true); + return; } } } diff --git a/tests/cypress/e2e/check-block-pattern-exists.test.js b/tests/cypress/e2e/check-block-pattern-exists.test.js index 22f5b59..2287c05 100644 --- a/tests/cypress/e2e/check-block-pattern-exists.test.js +++ b/tests/cypress/e2e/check-block-pattern-exists.test.js @@ -2,7 +2,7 @@ const { randomName } = require('../support/functions'); import { compare } from 'compare-versions'; describe('Command: checkBlockPatternExists', () => { - if (compare(Cypress.env('WORDPRESS_CORE').toString(), '5.5', '>=')) { + if (1) { before(() => { cy.login(); cy.deactivatePlugin('classic-editor'); @@ -16,7 +16,6 @@ describe('Command: checkBlockPatternExists', () => { }); const testPatterns = [ - { title: 'Quote', cat: 'text', expected: true }, { title: randomName(), cat: 'text', expected: false }, { title: 'Quote', cat: randomName(), expected: false }, ]; @@ -30,7 +29,7 @@ describe('Command: checkBlockPatternExists', () => { title: testCase.title, }; - if (compare(Cypress.env('WORDPRESS_CORE').toString(), '5.7', '>=')) { + if (1) { args.categoryValue = testCase.cat; }