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

Add test files #21

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .github/workflows/brand-plugin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
File renamed without changes.
106 changes: 106 additions & 0 deletions tests/cypress/integration/solutions-app.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// <reference types="Cypress" />
const entitlementsFixture = require( '../fixtures/entitlements.json' );

describe( 'My Plugins and Tools in Plugin App', function () {
beforeEach( () => {
cy.visit( '/wp-admin/index.php' );
} );

// 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.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', 'Plugins & Tools' )
.scrollIntoView()
.should( 'be.visible' );

cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Core Tools' )
.scrollIntoView()
.should( 'be.visible' );

// accordion closed
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h3', 'Jetpack' )
.should( 'not.exist' );

// test accordion functionality
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Core Tools' )
.click();

// accordion opened
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h3', 'Jetpack' )
.scrollIntoView()
.should( 'be.visible' );
} );

// 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
} );
86 changes: 86 additions & 0 deletions tests/cypress/integration/solutions-plugins.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// <reference types="Cypress" />
const entitlementsFixture = require( '../fixtures/entitlements.json' );

describe( 'My Plugins and Tools in Plugin App', function () {
// path to the entitlements json to load into transient
const entitlementsjson =
'vendor/newfold-labs/wp-module-solutions/tests/cypress/fixtures/entitlements.json';

after( () => {
cy.exec(
`npx wp-env run cli wp option delete _transient_nfd_site_capabilities`
);
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 option delete _transient_nfd_site_capabilities`
);
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' );
// 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'
);
} );

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
} );
Loading