From 3fd70768af220fc0b65a2d931aab8b4aa7a2a8c1 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 18 Dec 2024 13:36:29 -0500 Subject: [PATCH 1/2] update cypress test with testIsolation --- tests/cypress/integration/wonder-blocks.cy.js | 64 ++++++++----------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/tests/cypress/integration/wonder-blocks.cy.js b/tests/cypress/integration/wonder-blocks.cy.js index feb04116..03e248e2 100644 --- a/tests/cypress/integration/wonder-blocks.cy.js +++ b/tests/cypress/integration/wonder-blocks.cy.js @@ -1,45 +1,37 @@ // -describe("WonderBlocks", function () { - before(() => { - cy.visit("/wp-admin/post-new.php"); - }); +describe( "WonderBlocks", { testIsolation: true }, () => { + beforeEach( () => { + cy.login( Cypress.env( "wpUsername" ), Cypress.env( "wpPassword" ) ); + cy.visit( "/wp-admin/post-new.php" ); + } ); - it("WonderBlocks button exists", () => { - cy.get("#nfd-wba-toolbar-button").should("exist"); - }); + it( "WonderBlocks button present and modal functions", () => { + cy.get( "#nfd-wba-toolbar-button" ).should( "exist" ); - it("WonderBlocks button opens modal", () => { - cy.wait(1000); + cy.wait( 1000 ); - cy.window().then((win) => { - win.wp.data.select("core/edit-post").isFeatureActive("welcomeGuide") && - win.wp.data.dispatch("core/edit-post").toggleFeature("welcomeGuide"); - }); - - cy.wait(100); - cy.get("#nfd-wba-toolbar-button button").click(); - cy.wait(100); + cy.wait( 100 ); + cy.get( "#nfd-wba-toolbar-button button" ).click(); + cy.wait( 100 ); // body has class modal-open - cy.get("body").should("have.class", "modal-open"); + cy.get( "body" ).should( "have.class", "modal-open" ); // modal window exists - cy.get('.nfd-wba-modal[role="dialog"]').should("be.visible"); - }); + cy.get( '.nfd-wba-modal[role="dialog"]' ).should( "be.visible" ); - it("Close buttons closes modal", () => { - cy.get('.nfd-wba-modal__header button[aria-label="Close dialog"]').should("exist"); - cy.get('.nfd-wba-modal__header button[aria-label="Close dialog"]').click(); - cy.wait(100); - cy.get("body").should("not.have.class", "modal-open"); - cy.get('.nfd-wba-modal[role="dialog"]').should("not.exist"); - }); + // Close buttons closes modal + cy.get( '.nfd-wba-modal__header button[aria-label="Close dialog"]' ).should( "exist" ); + cy.get( '.nfd-wba-modal__header button[aria-label="Close dialog"]' ).click(); + cy.wait( 100 ); + cy.get( "body" ).should( "not.have.class", "modal-open" ); + cy.get( '.nfd-wba-modal[role="dialog"]' ).should( "not.exist" ); - it("ESC button closes modal too", () => { - cy.get("#nfd-wba-toolbar-button button").click(); - cy.wait(100); - cy.get('.nfd-wba-modal[role="dialog"]').should("be.visible"); - cy.get("body").type("{esc}"); - cy.wait(100); - cy.get('.nfd-wba-modal[role="dialog"]').should("not.exist"); - }); -}); + // ESC button closes modal too + cy.get( "#nfd-wba-toolbar-button button" ).click(); + cy.wait( 100 ); + cy.get( '.nfd-wba-modal[role="dialog"]' ).should( "be.visible" ); + cy.get( "body" ).type( "{esc}" ); + cy.wait( 100 ); + cy.get( '.nfd-wba-modal[role="dialog"]' ).should( "not.exist" ); + } ); +} ); From 03e28292e638f968ede79d3eb750f94fbba3ce48 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 18 Dec 2024 13:42:05 -0500 Subject: [PATCH 2/2] keeping window accidentally removed in rewrite it should close the welcome guide if it displays so the test can perform --- tests/cypress/integration/wonder-blocks.cy.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/cypress/integration/wonder-blocks.cy.js b/tests/cypress/integration/wonder-blocks.cy.js index 03e248e2..f8dfb071 100644 --- a/tests/cypress/integration/wonder-blocks.cy.js +++ b/tests/cypress/integration/wonder-blocks.cy.js @@ -11,6 +11,11 @@ describe( "WonderBlocks", { testIsolation: true }, () => { cy.wait( 1000 ); + cy.window().then( ( win ) => { + win.wp.data.select( "core/edit-post" ).isFeatureActive( "welcomeGuide" ) && + win.wp.data.dispatch( "core/edit-post" ).toggleFeature( "welcomeGuide" ); + } ); + cy.wait( 100 ); cy.get( "#nfd-wba-toolbar-button button" ).click(); cy.wait( 100 );