Skip to content

Commit

Permalink
FIxes for the close welcome modal command
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Galanakis committed Aug 3, 2023
1 parent 1bbbebf commit 1096b0d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/commands/close-welcome-guide-javascript.ts
Original file line number Diff line number Diff line change
@@ -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 */
})
};
2 changes: 1 addition & 1 deletion src/commands/create-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 1096b0d

Please sign in to comment.