From f00214cc7e1c024d57f7c21d5dcdd3079274c39f Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Thu, 10 Oct 2024 15:31:58 -0400 Subject: [PATCH 1/6] add some test files for starting --- tests/cypress/integration/solutions-app.cy.js | 96 +++++++++++++++++++ .../integration/solutions-plugins.cy.js | 58 +++++++++++ 2 files changed, 154 insertions(+) create mode 100644 tests/cypress/integration/solutions-app.cy.js create mode 100644 tests/cypress/integration/solutions-plugins.cy.js diff --git a/tests/cypress/integration/solutions-app.cy.js b/tests/cypress/integration/solutions-app.cy.js new file mode 100644 index 0000000..63d30bb --- /dev/null +++ b/tests/cypress/integration/solutions-app.cy.js @@ -0,0 +1,96 @@ +// + +describe( 'My Plugins and Tools in Plugin App', function () { + beforeEach( () => { + cy.visit( '/wp-admin/index.php' ); + + // we should move the debug.json entitlement response into a fixture. + // for now this test will work if debug mode is on since it will load the debug data. + // also need to devise a way to set capabilities via cli command for testing with/without solutions. + } ); + + // check that it does not display when capabilities.hasSolution is false + it( 'My Plugins & Tools nav does not display without solution', () => { + cy.visit( + '/wp-admin/admin.php?page=' + + Cypress.env( 'pluginId' ) + + '#/', + { + onLoad() { + cy.window().then( ( win ) => { + win.NewfoldRuntime.capabilities.hasSolution = false; + } ); + }, + } + ); + cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('not.exist'); + } ); + + // check that my plugins and tools displays when capabilities.hasSolution is true + it( 'My Plugins & Tools nav displays with Solution', () => { + cy.visit( + '/wp-admin/admin.php?page=' + + Cypress.env( 'pluginId' ) + + '#/', + { + onLoad() { + cy.window().then( ( win ) => { + win.NewfoldRuntime.capabilities.hasSolution = true; + } ); + }, + } + ); + cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('be.visible'); + } ); + + // check that entitlement categories load in accordions + it( 'Entitlements Display with Solution', () => { + cy.visit( + '/wp-admin/admin.php?page=' + + Cypress.env( 'pluginId' ) + + '#/my_plugins_and_tools', + { + onLoad() { + cy.window().then( ( win ) => { + win.NewfoldRuntime.capabilities.hasSolution = true; + } ); + }, + } + ); + + cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('be.visible'); + + cy.get( '.newfold-entitlements-container' ) + .contains( 'h2', 'Tools' ) + .scrollIntoView() + .should( 'be.visible' ); + + cy.get( '.nfd-core-tool-mypluginsntools' ) + .contains( 'h3', 'Core Tools' ) + .scrollIntoView() + .should( 'be.visible' ); + + cy.get( '.nfd-core-tool-mypluginsntools' ) + .contains( 'h4', 'Jetpack') + .scrollIntoView() + .should( 'be.visible' ); + + // test accordion functionality + cy.get( '.nfd-core-tool-mypluginsntools' ) + .contains( 'h3', 'Core Tools' ) + .click(); + + // accordion closed + cy.get( '.nfd-core-tool-mypluginsntools' ) + .contains( 'h4', 'Jetpack') + .should( 'not.exist' ); + } ); + + // test entitlement button case states + // 1. plugin already installed and active + // 2. plugin already installed but not active + // 3. free plugin not installed, needs appropriate installer attributes + // 4. premium plugin not installed, needs appropriate pls attributes + + +} ); diff --git a/tests/cypress/integration/solutions-plugins.cy.js b/tests/cypress/integration/solutions-plugins.cy.js new file mode 100644 index 0000000..e2c68f9 --- /dev/null +++ b/tests/cypress/integration/solutions-plugins.cy.js @@ -0,0 +1,58 @@ +// + +describe( 'My Plugins and Tools in Plugin App', function () { + beforeEach( () => { + cy.visit( '/wp-admin/plugin-install.php' ); + } ); + + it( 'Tab exists', () => { + cy.visit( '/wp-admin/plugin-install.php' ); + // check that my plugins and tools tab displays when capabilities.hasSolution is true + // check that it does not display when capabilities.hasSolution is false + + // check that entitlement plugins load + cy.visit( '/wp-admin/plugin-install.php?tab=nfd_my_plugins_and_tools' ); + + + } ); + + // check that it does not display when capabilities.hasSolution is false + it( 'My Plugins & Tools tab does not display without solution', () => { + // need a cli command to set a capability before a test + cy.visit( + '/wp-admin/plugin-install.php', + { + onLoad() { + cy.window().then( ( win ) => { + win.NewfoldRuntime.capabilities.hasSolution = false; + } ); + }, + } + ); + + cy.get('.plugin-install-nfd_my_plugins_and_tools').should('not.exist'); + } ); + + // check that my plugins and tools displays when capabilities.hasSolution is true + it( 'My Plugins & Tools tab displays with Solution', () => { + cy.visit( + '/wp-admin/plugin-install.php', + { + onLoad() { + cy.window().then( ( win ) => { + win.NewfoldRuntime.capabilities.hasSolution = true; + } ); + }, + } + ); + cy.get('.plugin-install-nfd_my_plugins_and_tools').should('be.visible'); + } ); + + + // test each entitlement button case state + // 1. plugin already installed and active + // 2. plugin already installed but not active + // 3. free plugin not installed, needs appropriate installer attributes + // 4. premium plugin not installed, needs appropriate pls attributes + +} ); From 4417def0f97f399293d06049b38082535d90f905 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 23 Oct 2024 18:26:18 -0400 Subject: [PATCH 2/6] move debug data to test fixture file --- .../js/debug.json => tests/cypress/fixtures/entitlements.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename includes/js/debug.json => tests/cypress/fixtures/entitlements.json (100%) diff --git a/includes/js/debug.json b/tests/cypress/fixtures/entitlements.json similarity index 100% rename from includes/js/debug.json rename to tests/cypress/fixtures/entitlements.json From 24d20503d33cc128994e82c9ca212f16ed0389a1 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Fri, 25 Oct 2024 16:47:58 -0400 Subject: [PATCH 3/6] remove solutions branch from test workflow --- .github/workflows/brand-plugin-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/brand-plugin-test.yml b/.github/workflows/brand-plugin-test.yml index 8c56251..203665c 100644 --- a/.github/workflows/brand-plugin-test.yml +++ b/.github/workflows/brand-plugin-test.yml @@ -32,7 +32,6 @@ jobs: module-repo: ${{ github.repository }} module-branch: ${{ needs.setup.outputs.branch }} plugin-repo: 'bluehost/bluehost-wordpress-plugin' - plugin-branch: 'feature/solutions' secrets: inherit # hostgator: From a4a596b95f4db7176a1ff4fa2645d519ad3938e2 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Tue, 29 Oct 2024 12:58:30 -0400 Subject: [PATCH 4/6] update app solutions tests to use fixture --- tests/cypress/integration/solutions-app.cy.js | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/tests/cypress/integration/solutions-app.cy.js b/tests/cypress/integration/solutions-app.cy.js index 63d30bb..fe5cb9a 100644 --- a/tests/cypress/integration/solutions-app.cy.js +++ b/tests/cypress/integration/solutions-app.cy.js @@ -1,20 +1,15 @@ // +const entitlementsFixture = require( '../fixtures/entitlements.json' ); describe( 'My Plugins and Tools in Plugin App', function () { beforeEach( () => { cy.visit( '/wp-admin/index.php' ); - - // we should move the debug.json entitlement response into a fixture. - // for now this test will work if debug mode is on since it will load the debug data. - // also need to devise a way to set capabilities via cli command for testing with/without solutions. } ); // check that it does not display when capabilities.hasSolution is false it( 'My Plugins & Tools nav does not display without solution', () => { cy.visit( - '/wp-admin/admin.php?page=' + - Cypress.env( 'pluginId' ) + - '#/', + '/wp-admin/admin.php?page=' + Cypress.env( 'pluginId' ) + '#/', { onLoad() { cy.window().then( ( win ) => { @@ -23,15 +18,15 @@ describe( 'My Plugins and Tools in Plugin App', function () { }, } ); - cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('not.exist'); + cy.get( 'a.wppbh-app-navitem[href="#/my_plugins_and_tools"]' ).should( + 'not.exist' + ); } ); // check that my plugins and tools displays when capabilities.hasSolution is true it( 'My Plugins & Tools nav displays with Solution', () => { cy.visit( - '/wp-admin/admin.php?page=' + - Cypress.env( 'pluginId' ) + - '#/', + '/wp-admin/admin.php?page=' + Cypress.env( 'pluginId' ) + '#/', { onLoad() { cy.window().then( ( win ) => { @@ -40,7 +35,9 @@ describe( 'My Plugins and Tools in Plugin App', function () { }, } ); - cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('be.visible'); + cy.get( 'a.wppbh-app-navitem[href="#/my_plugins_and_tools"]' ).should( + 'be.visible' + ); } ); // check that entitlement categories load in accordions @@ -57,40 +54,53 @@ describe( 'My Plugins and Tools in Plugin App', function () { }, } ); - - cy.get('a.wppbh-app-navitem[href="#/my_plugins_and_tools"]').should('be.visible'); - + + cy.intercept( + { + method: 'GET', + url: /newfold-solutions(\/|%2F)v1(\/|%2F)entitlements/, + }, + { + body: entitlementsFixture, + delay: 100, + } + ).as( 'getEntitlements' ); + cy.wait( '@getEntitlements' ); + + cy.get( 'a.wppbh-app-navitem[href="#/my_plugins_and_tools"]' ).should( + 'be.visible' + ); + cy.get( '.newfold-entitlements-container' ) - .contains( 'h2', 'Tools' ) + .contains( 'h2', 'Plugins & Tools' ) .scrollIntoView() .should( 'be.visible' ); - + cy.get( '.nfd-core-tool-mypluginsntools' ) - .contains( 'h3', 'Core Tools' ) + .contains( 'h2', 'Core Tools' ) .scrollIntoView() .should( 'be.visible' ); + // accordion closed cy.get( '.nfd-core-tool-mypluginsntools' ) - .contains( 'h4', 'Jetpack') - .scrollIntoView() - .should( 'be.visible' ); - + .contains( 'h3', 'Jetpack' ) + .should( 'not.exist' ); + // test accordion functionality cy.get( '.nfd-core-tool-mypluginsntools' ) - .contains( 'h3', 'Core Tools' ) + .contains( 'h2', 'Core Tools' ) .click(); - // accordion closed + // accordion opened cy.get( '.nfd-core-tool-mypluginsntools' ) - .contains( 'h4', 'Jetpack') - .should( 'not.exist' ); + .contains( 'h3', 'Jetpack' ) + .scrollIntoView() + .should( 'be.visible' ); } ); - // test entitlement button case states + // test entitlement button case states // 1. plugin already installed and active // 2. plugin already installed but not active // 3. free plugin not installed, needs appropriate installer attributes // 4. premium plugin not installed, needs appropriate pls attributes - - } ); From 75936814547bb62e1bd3756981fe409d87d95a94 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Tue, 29 Oct 2024 14:16:37 -0400 Subject: [PATCH 5/6] update plugin page solutions test to pull in fixture properly --- .../integration/solutions-plugins.cy.js | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/tests/cypress/integration/solutions-plugins.cy.js b/tests/cypress/integration/solutions-plugins.cy.js index e2c68f9..20cfdce 100644 --- a/tests/cypress/integration/solutions-plugins.cy.js +++ b/tests/cypress/integration/solutions-plugins.cy.js @@ -1,58 +1,86 @@ // +const entitlementsFixture = require( '../fixtures/entitlements.json' ); describe( 'My Plugins and Tools in Plugin App', function () { - beforeEach( () => { - cy.visit( '/wp-admin/plugin-install.php' ); - } ); + // path to the entitlements json to load into transient + const entitlementsjson = + 'vendor/newfold-labs/wp-module-solutions/tests/cypress/fixtures/entitlements.json'; - it( 'Tab exists', () => { - cy.visit( '/wp-admin/plugin-install.php' ); - // check that my plugins and tools tab displays when capabilities.hasSolution is true - // check that it does not display when capabilities.hasSolution is false - - // check that entitlement plugins load - cy.visit( '/wp-admin/plugin-install.php?tab=nfd_my_plugins_and_tools' ); - - + after( () => { + cy.exec( + `npx wp-env run cli wp transient delete nfd_site_capabilities` + ); + cy.exec( `npx wp-env run cli wp transient delete newfold_solutions` ); + cy.exec( `npx wp-env run cli wp option delete nfd_data_token` ); } ); // check that it does not display when capabilities.hasSolution is false it( 'My Plugins & Tools tab does not display without solution', () => { + cy.exec( + `npx wp-env run cli wp transient delete nfd_site_capabilities` + ); + cy.exec( `npx wp-env run cli wp transient delete newfold_solutions` ); + // need a cli command to set a capability before a test - cy.visit( - '/wp-admin/plugin-install.php', - { - onLoad() { - cy.window().then( ( win ) => { - win.NewfoldRuntime.capabilities.hasSolution = false; - } ); - }, - } - ); - - cy.get('.plugin-install-nfd_my_plugins_and_tools').should('not.exist'); + cy.visit( '/wp-admin/plugin-install.php' ); + // check that my plugins and tools tab displays when capabilities.hasSolution is true + cy.get( + '#adminmenu a[href="plugin-install.php?tab=nfd_my_plugins_and_tools"]' + ).should( 'not.exist' ); + cy.get( '.plugin-install-nfd_my_plugins_and_tools' ).should( + 'not.exist' + ); } ); - // check that my plugins and tools displays when capabilities.hasSolution is true - it( 'My Plugins & Tools tab displays with Solution', () => { - cy.visit( - '/wp-admin/plugin-install.php', - { - onLoad() { - cy.window().then( ( win ) => { - win.NewfoldRuntime.capabilities.hasSolution = true; - } ); - }, - } - ); - cy.get('.plugin-install-nfd_my_plugins_and_tools').should('be.visible'); - } ); + it( 'My Plugins & Tools exists', () => { + // drop test entitlements into transient + cy.exec( + `npx wp-env run cli wp option set _transient_newfold_solutions --format=json < ${ entitlementsjson }` + ); + // spoof hiive connection + cy.exec( `npx wp-env run cli wp option set nfd_data_token 'xyc123'` ); + // Set hasSolution:true in capabilities + cy.exec( + `npx wp-env run cli wp option set _transient_nfd_site_capabilities '{"hasSolution": true}' --format=json` + ); + // Set a long timeout for the transients + cy.exec( + `npx wp-env run cli wp option set _transient_timeout_newfold_solutions 4102444800` + ); + cy.exec( + `npx wp-env run cli wp option set _transient_timeout_nfd_site_capabilities 4102444800` + ); + + // reload plugin install page + cy.reload( true ); + cy.visit( '/wp-admin/plugin-install.php' ); + + // check that my plugins and tools tab displays when capabilities.hasSolution is true + cy.get( + '#adminmenu a[href="plugin-install.php?tab=nfd_my_plugins_and_tools"]' + ).should( 'be.visible' ); + + // check that entitlement plugins load + cy.visit( '/wp-admin/plugin-install.php?tab=nfd_my_plugins_and_tools' ); + cy.get( '.plugin-install-nfd_my_plugins_and_tools' ).should( + 'be.visible' + ); + + cy.get( '.nfd-solutions-availble-list' ) + .contains( 'h3', 'Jetpack' ) + .scrollIntoView() + .should( 'be.visible' ); + + cy.get( '.nfd-solutions-availble-list' ) + .contains( 'h3', 'Yoast SEO' ) + .scrollIntoView() + .should( 'be.visible' ); + } ); // test each entitlement button case state // 1. plugin already installed and active // 2. plugin already installed but not active // 3. free plugin not installed, needs appropriate installer attributes // 4. premium plugin not installed, needs appropriate pls attributes - } ); From 3aaeb4342bc4b07c4c3bc722e1b030ba1d9a47a4 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Tue, 29 Oct 2024 14:50:25 -0400 Subject: [PATCH 6/6] clear test data as options rather than transients --- tests/cypress/integration/solutions-plugins.cy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cypress/integration/solutions-plugins.cy.js b/tests/cypress/integration/solutions-plugins.cy.js index 20cfdce..94ff13d 100644 --- a/tests/cypress/integration/solutions-plugins.cy.js +++ b/tests/cypress/integration/solutions-plugins.cy.js @@ -8,18 +8,18 @@ describe( 'My Plugins and Tools in Plugin App', function () { after( () => { cy.exec( - `npx wp-env run cli wp transient delete nfd_site_capabilities` + `npx wp-env run cli wp option delete _transient_nfd_site_capabilities` ); - cy.exec( `npx wp-env run cli wp transient delete newfold_solutions` ); + cy.exec( `npx wp-env run cli wp option delete _transient_newfold_solutions` ); cy.exec( `npx wp-env run cli wp option delete nfd_data_token` ); } ); // check that it does not display when capabilities.hasSolution is false it( 'My Plugins & Tools tab does not display without solution', () => { cy.exec( - `npx wp-env run cli wp transient delete nfd_site_capabilities` + `npx wp-env run cli wp option delete _transient_nfd_site_capabilities` ); - cy.exec( `npx wp-env run cli wp transient delete newfold_solutions` ); + cy.exec( `npx wp-env run cli wp option delete _transient_newfold_solutions` ); // need a cli command to set a capability before a test cy.visit( '/wp-admin/plugin-install.php' );