Skip to content

Commit

Permalink
try checking with setInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Aug 17, 2022
1 parent 961b517 commit 15b5858
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions src/commands/check-block-pattern-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,42 @@ export const checkBlockPatternExists = ({
title: string;
categoryValue?: string;
}): void => {
cy.window().then(win => {
const { wp } = win;
cy.window()
.then(win => {
/* eslint-disable */
return new Promise(resolve => {
let elapsed = 1500;

/* eslint-disable */
const { getSettings } = wp.data.select('core/block-editor');
const allRegisteredPatterns = getSettings().__experimentalBlockPatterns;
setInterval(function () {
if (elapsed > 1500) {
resolve(false);
}

if (undefined !== allRegisteredPatterns) {
for (let i = 0; i < allRegisteredPatterns.length; i++) {
if (
title === allRegisteredPatterns[i].title &&
allRegisteredPatterns[i].categories &&
allRegisteredPatterns[i].categories.includes(categoryValue)
) {
cy.wrap(true);
return;
}
}
}
/* eslint-enable */
cy.wrap(false);
});
const { wp } = win;

const { getSettings } = wp.data.select('core/block-editor');
const allRegisteredPatterns =
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;
}
}
}

elapsed += 100;
}, 100);
});
})
.then(val => {
/* eslint-enable */
cy.wrap(val);
});
};

0 comments on commit 15b5858

Please sign in to comment.