Skip to content

Commit

Permalink
Merge pull request #43 from newfold-labs/update/test-isolation
Browse files Browse the repository at this point in the history
Update tests for test isolation
  • Loading branch information
circlecube authored Dec 3, 2024
2 parents e84e21c + 5b7d1df commit 6896b42
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 47 deletions.
64 changes: 43 additions & 21 deletions tests/cypress/integration/coming-soon-woo.cy.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
// <reference types="Cypress" />
import { wpLogin, wpCli } from '../wp-module-support/utils.cy';

describe( 'Coming Soon with WooCommerce', { testIsolation: true }, () => {
beforeEach( () => {
wpLogin();

describe( 'Coming Soon with WooCommerce', function () {
before( () => {
// Set coming soon option to true to start with
cy.exec( `npx wp-env run cli wp option update mm_coming_soon true` );
cy.exec( `npx wp-env run cli wp option update nfd_coming_soon true` );
wpCli( `option update mm_coming_soon true` );
wpCli( `option update nfd_coming_soon true` );

// Activate WooCommerce
cy.exec( `npx wp-env run cli wp plugin install woocommerce --activate`, {
wpCli( `plugin install woocommerce --activate`, {
timeout: 40000,
log: true,
} );

cy.visit( '/wp-admin/index.php' );
} );

after( () => {
// Uninstall WooCommerce and extensions
cy.exec(
'npx wp-env run cli wp plugin uninstall --all --deactivate --exclude=bluehost-wordpress-plugin,wp-plugin-hostgator,wp-plugin-crazy-domains,wp-plugin-web,wp-plugin-mojo',
wpCli(
'plugin uninstall --all --deactivate --exclude=bluehost-wordpress-plugin,wp-plugin-hostgator,wp-plugin-crazy-domains,wp-plugin-web,wp-plugin-mojo,wpforms-lite',
{
timeout: 60000,
log: true,
}
);
} );

it( 'Replace our admin bar site status badge with WooCommerce\'s when active', () => {
it( "Replace our admin bar site status badge with WooCommerce's when active", () => {
// Visit settings page
cy.visit(
'/wp-admin/admin.php?page=' +
Expand All @@ -33,16 +38,26 @@ describe( 'Coming Soon with WooCommerce', function () {
);

// Our badge shouldn't be visible
cy.get( '#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge' )
.should( 'not.exist' );
cy.get( '#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge' ).should(
'not.exist'
);

// WooCommerce badge should be visible
cy.get( '#wp-toolbar #wp-admin-bar-woocommerce-site-visibility-badge a.ab-item' )
cy.get(
'#wp-toolbar #wp-admin-bar-woocommerce-site-visibility-badge a.ab-item'
)
.contains( 'a', 'Coming soon' )
.should( 'be.visible' );
});
} );

it( 'Our plugin settings should toggle WooCommerce admin bar badge', () => {
// Visit settings page
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
'#/settings'
);

it ( 'Our plugin settings should toggle WooCommerce admin bar badge', () => {
// Deactivate coming soon - Launch Site
cy.get( '[data-id="coming-soon-toggle"]' ).click();
cy.wait( 1000 );
Expand All @@ -53,19 +68,26 @@ describe( 'Coming Soon with WooCommerce', function () {
.should( 'be.visible' );

// Re-enable coming soon mode
cy.get( '[data-id="coming-soon-toggle"]' )
.click();
cy.get( '[data-id="coming-soon-toggle"]' ).click();
cy.wait( 1000 );

// WooCommerce badge should now be coming soon
cy.get( '#wp-toolbar .woocommerce-site-status-badge-coming-soon a.ab-item' )
cy.get(
'#wp-toolbar .woocommerce-site-status-badge-coming-soon a.ab-item'
)
.contains( 'a', 'Coming soon' )
.should( 'be.visible' );
});
} );

it( 'Hide our site preview notice when WooCommerce is active', () => {
// Visit settings page
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
'#/settings'
);

cy.visit( '/' );
cy.get( '.nfd-site-preview-warning' )
.should( 'not.exist' );
});
cy.get( '.nfd-site-preview-warning' ).should( 'not.exist' );
} );
} );
47 changes: 21 additions & 26 deletions tests/cypress/integration/coming-soon.cy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// <reference types="Cypress" />
import { wpLogin, wpCli } from '../wp-module-support/utils.cy';

describe( 'Coming Soon', function () {
describe( 'Coming Soon', { testIsolation: true }, () => {
const appClass = '.' + Cypress.env( 'appId' );

before( () => {
beforeEach( () => {
wpLogin();
// Set coming soon option to true to start with
cy.exec( `npx wp-env run cli wp option update mm_coming_soon true` );
cy.exec( `npx wp-env run cli wp option update nfd_coming_soon true` );
wpCli( `option update mm_coming_soon true` );
wpCli( `option update nfd_coming_soon true` );

// Deactivate WooCommerce if it's active
cy.exec( `npx wp-env run cli wp plugin deactivate woocommerce`, {
wpCli( `plugin deactivate woocommerce`, {
timeout: 40000,
log: true,
failOnNonZeroExit: false,
} );
cy.visit( '/wp-admin/index.php' );
} );

it( 'Coming Soon is active', () => {
Expand Down Expand Up @@ -42,11 +45,11 @@ describe( 'Coming Soon', function () {
cy.get( '[data-id="coming-soon-toggle"]' )
.should( 'have.attr', 'aria-checked' )
.and( 'include', 'true' );
});

it( 'Displays Coming Soon in Site Status Admin Toolbar', () => {
// Admin bar contains label
cy.get( '#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge a.ab-item' )
cy.get(
'#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge a.ab-item'
)
.contains( 'a', 'Coming soon' )
.should( 'be.visible' );
} );
Expand All @@ -71,13 +74,13 @@ describe( 'Coming Soon', function () {
.contains( 'button', 'Launch' )
.should( 'exist' );

} );

it( 'Coming Soon Admin bar links to setting', () => {
cy.get( '#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge a.ab-item' ).click();
// Coming Soon Admin bar links to setting
cy.get(
'#wp-toolbar #wp-admin-bar-nfd-site-visibility-badge a.ab-item'
).click();
cy.location().should( ( loc ) => {
expect( loc.hash ).to.eq( '#/settings' )
});
expect( loc.hash ).to.eq( '#/settings' );
} );
} );

it( 'Coming Soon Toggle Turns Coming Soon Off', () => {
Expand Down Expand Up @@ -105,15 +108,8 @@ describe( 'Coming Soon', function () {
cy.get( '.nfd-notifications' )
.contains( '.nfd-notification', 'Coming soon deactivated' )
.should( 'be.visible' );
} );

it( 'Coming Soon Toggle Turns Coming Soon On', () => {
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
'#/settings'
);

// Coming Soon Toggle Turns Coming Soon Back On
// Activate Coming Soon - Unlaunch Site
cy.get( '[data-id="coming-soon-toggle"]' ).click();
cy.wait( 2000 );
Expand Down Expand Up @@ -156,9 +152,9 @@ describe( 'Coming Soon', function () {
cy.get( '#wrap' ).contains( 'Coming Soon' ).should( 'exist' );
} );

// this test is already in the ecommerce module, once the component is moved into this module this test can be used
it.skip( 'Launching launches site', () => {
cy.login( Cypress.env( 'wpUsername' ), Cypress.env( 'wpPassword' ) );
// this test is already in the ecommerce module, and the code is in the ecommerce module
// once the component is moved into this module this test will be used and the ecom test removed
it( 'Launching launches site', () => {
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
Expand Down Expand Up @@ -199,6 +195,5 @@ describe( 'Coming Soon', function () {
cy.get( '[data-id="coming-soon-toggle"]' )
.should( 'have.attr', 'aria-checked' )
.and( 'include', 'false' );

} );
} );
29 changes: 29 additions & 0 deletions tests/cypress/wp-module-support/utils.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Loginto WordPress.
*/
export const wpLogin = () => {
cy.login( Cypress.env( 'wpUsername' ), Cypress.env( 'wpPassword' ) );
};

/**
* wp-cli helper
*
* This wraps the command in the required npx wp-env run cli wp
*
* @param {string} cmd the command to send to wp-cli
* @param {Object} paramArgs any args to pass to exec
*/
export const wpCli = ( cmd, paramArgs ) => {
const defaultArgs = {
env: {
NODE_TLS_REJECT_UNAUTHORIZED: '1',
},
failOnNonZeroExit: true,
};
const args = { ...defaultArgs, ...paramArgs };
cy.exec( `npx wp-env run cli wp ${ cmd }`, args ).then( ( result ) => {
for ( const [ key, value ] of Object.entries( result ) ) {
cy.log( `${ key }: ${ value }` );
}
} );
};

0 comments on commit 6896b42

Please sign in to comment.