From a721bded53490d73e846c573694745f51f020b94 Mon Sep 17 00:00:00 2001 From: sksaju Date: Mon, 25 Nov 2024 00:52:57 +0600 Subject: [PATCH] update support command functions --- tests/cypress/support/commands.js | 75 ++++++------------------------- 1 file changed, 13 insertions(+), 62 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 529b316..4136e78 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -1,77 +1,28 @@ /* eslint-disable no-undef */ +// Add local storage item Cypress.Commands.add('setLocalStorage', (key, value) => { cy.window().then((win) => { - win.localStorage.setItem(key, value); + win.localStorage.setItem(key, JSON.stringify(value)); }); }); -Cypress.Commands.add('createPost', (options = {}) => { - const { postType = 'post', title = '' } = options; - const userId = '1'; - - cy.setLocalStorage( - `WP_DATA_USER_${userId}`, - JSON.stringify({ - 'core/edit-post': { - preferences: { - panels: { - 'post-status': { - opened: true, - }, - }, - features: { - fixedToolbar: false, - welcomeGuide: false, - fullscreenMode: true, - showIconLabels: false, - themeStyles: true, - showBlockBreadcrumbs: true, - welcomeGuideTemplate: false, - }, - editorMode: 'visual', - hiddenBlockTypes: [], - preferredStyleVariations: {}, - localAutosaveInterval: 15, - }, - }, - 'core/editor': { - preferences: { - isPublishSidebarEnabled: false, - }, - }, - }), - ); - - cy.get('#wp-admin-bar-new-content-default') - .contains(postType, { matchCase: false }) - .click({ force: true }); - - cy.wait(100); - - // close the Yoast SEO metabox - cy.get('.wpseo-metabox .handlediv').then((button) => { - const isExpanded = button[0].getAttribute('aria-expanded') === 'true'; - if (isExpanded) { - cy.get('.wpseo-metabox .handlediv').click(); - } - }); - - cy.wait(100); - - if (title !== '') { - cy.get('.editor-post-title__input').type( - `Cypress - ${title} - ${new Date(Date.now()).toLocaleDateString()}`, - ); +// Create a new post +Cypress.Commands.add('createPost', ({ title = '' } = {}) => { + cy.visit('/wp-admin/post-new.php'); + if (title) { + cy.get('.editor-post-title__input').type(`${title} - ${Date.now()}`); } }); +// Save the post Cypress.Commands.add('savePost', () => { - cy.get('[type="button"]').contains('Publish').click(); + cy.get('button').contains('Publish').click(); }); +// Insert a Gutenberg block Cypress.Commands.add('insertBlock', (blockName) => { - cy.get('button[aria-label="Add block"]').first().click(); - cy.focused().type(blockName); - cy.get('button').contains(blockName).click(); + cy.get('button[aria-label="Add block"]').click(); + cy.get('.block-editor-inserter__search input').type(blockName); + cy.contains('.block-editor-block-types-list__item', blockName).click(); });