Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cypress test with testIsolation #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions tests/cypress/integration/wonder-blocks.cy.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
// <reference types="Cypress" />

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.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" );
} );
} );