From 1096b0dbc7f7a9da3c2721f16053bca7d8e46aa2 Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Thu, 3 Aug 2023 11:32:45 +0300 Subject: [PATCH] FIxes for the close welcome modal command --- .../close-welcome-guide-javascript.ts | 64 +++++++++++++++++++ src/commands/create-post.ts | 2 +- src/index.ts | 3 + 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/commands/close-welcome-guide-javascript.ts diff --git a/src/commands/close-welcome-guide-javascript.ts b/src/commands/close-welcome-guide-javascript.ts new file mode 100644 index 0000000..e515ed6 --- /dev/null +++ b/src/commands/close-welcome-guide-javascript.ts @@ -0,0 +1,64 @@ +/* eslint-disable tsdoc/syntax */ +/** + * Check Block Pattern Exists. Works only with WordPress \>=5.5 + * + * \@param postData { + * `title` - Patttern name/title, + * `categoryValue` - Value of the pattern category, + * } + * + * @example + * For WP v5.5 + * ``` + * cy.checkBlockPatternExists({ + * title: 'Two buttons', + * }); + * ``` + * + * @example + * For WP v5.9 + * ``` + * cy.checkBlockPatternExists({ + * title: 'Three columns with offset images', + * categoryValue: 'gallery', + * }); + * ``` + */ +declare global { + interface Window { + wp: any; + } +} + +export const closeWelcomeGuideJavascript = (): void => { + cy.window() + .then(win => { + /* eslint-disable */ + let elapsed = 0; + console.log('hello'); + + setInterval(function () { + if (elapsed > 2500) { + return; + } + + const { wp } = win; + + const { isFeatureActive } = wp.data.select('core/edit-post'); + const { toggleFeature } = wp.data.dispatch('core/edit-post'); + const isWelcomeGuideActive = isFeatureActive('welcomeGuide'); + + if (!!isWelcomeGuideActive) { + toggleFeature('welcomeGuide'); + return; + } + + elapsed += 100; + }, 100); + + + + + /* eslint-enable */ + }) +}; diff --git a/src/commands/create-post.ts b/src/commands/create-post.ts index e226474..94abef3 100644 --- a/src/commands/create-post.ts +++ b/src/commands/create-post.ts @@ -71,7 +71,7 @@ export const createPost = ({ cy.get(contentInput).should('exist'); // Close Welcome Guide. - cy.closeWelcomeGuide(); + cy.closeWelcomeGuideJavascript(); // Fill out data. if (title.length > 0) { diff --git a/src/index.ts b/src/index.ts index a711e7e..ace9a9f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ import { login } from './commands/login'; import { createPost } from './commands/create-post'; import { uploadMedia } from './commands/upload-media'; import { checkSitemap } from './commands/check-sitemap-exists'; +import { closeWelcomeGuideJavascript } from "./commands/close-welcome-guide-javascript"; declare global { namespace Cypress { @@ -31,6 +32,7 @@ declare global { classicCreatePost: typeof classicCreatePost; insertBlock: typeof insertBlock; closeWelcomeGuide: typeof closeWelcomeGuide; + closeWelcomeGuideJavascript: typeof closeWelcomeGuideJavascript; wpCliEval: typeof wpCliEval; wpCli: typeof wpCli; deactivatePlugin: typeof deactivatePlugin; @@ -57,6 +59,7 @@ Cypress.Commands.add('checkPostExists', checkPostExists); Cypress.Commands.add('classicCreatePost', classicCreatePost); Cypress.Commands.add('insertBlock', insertBlock); Cypress.Commands.add('closeWelcomeGuide', closeWelcomeGuide); +Cypress.Commands.add('closeWelcomeGuideJavascript', closeWelcomeGuideJavascript); Cypress.Commands.add('wpCliEval', wpCliEval); Cypress.Commands.add('wpCli', wpCli); Cypress.Commands.add('deactivatePlugin', deactivatePlugin);