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

My plugins tools page #55

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
185 changes: 185 additions & 0 deletions tests/cypress/integration/my_plugins&tools_categories.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// <reference types="Cypress" />
import { wpLogin } from '../wp-module-support/utils.cy';

const entitlementsFixture = require( '../fixtures/entitlements.json' );

describe( 'My Plugins and Tools in Plugin App', { testIsolation: true }, () => {
beforeEach( () => {
wpLogin();

const ecomCategories = {
// Example structure for ecom categories
categories: [
{ id: 1, name: "Store Operations"},
{ id: 2, name: "Search Engine Optimization" },
{ id: 3, name: "Sales & Checkout" },
{ id: 4, name: "Content Monetization" },
{ id: 5, name: "Core Tools" },
{ id: 6, name: "Customer Engagement" },
{ id: 7, name: "Product Management" }
],
}
// Mocked solution 1 - will only return a subset of categories
const serviceCategories = {

categories: [
{ id: 2, name: "Search Engine Optimization" },
{ id: 4, name: "Content Monetization" },
{ id: 5, name: "Core Tools" },
{ id: 6, name: "Customer Engagement" },
],
};

const contentcreatorCategories = {
categories: [
{id: 2, name: "Search Engine Optimization" },
{ id: 3, name: "Sales & Checkout" },
{ id: 4, name: "Content Monetization" },
{ id: 5, name: "Core Tools" },
],
};
cy.visit( '/wp-admin/index.php' );
} );

//Check Categories based on Solution Type (Content Creator, Services, Commerce)
it('Extracts the solution SKU from API response and check for the solution specific categories', () => {

// set up the intercept for entitlements
cy.intercept(
{
method: 'GET',
url: /newfold-solutions(\/|%2F)v1(\/|%2F)entitlements/,
},
{
body: entitlementsFixture,
delay: 100,
}
).as( 'getEntitlements' );

cy.visit('/wp-admin/admin.php?page=' + Cypress.env('pluginId') + '#/my_plugins_and_tools');
cy.wait('@getEntitlements').then((interception) => {
// Access the response body from the intercepted request
const solutions = interception.response.body.solutions;
// Log the solutions for debugging
cy.log('Solutions:', JSON.stringify(solutions));
const solutionSku = solutions[0]?.sku;
cy.log('Solution SKU:', solutionSku);
const solution = solutions.find(s => s.sku === solutionSku);
const categories = solution?.categories || [];
if (solutionSku === 'WP_SOLUTION_COMMERCE') {
cy.log('This site is associated with the "commerce" solution');
cy.get('.newfold-entitlements-container').should('contain', 'Search Engine Optimization');
cy.get('.newfold-entitlements-container').should('contain', 'Content Monetization');
cy.get('.newfold-entitlements-container').should('contain', 'Core Tools');
cy.get('.newfold-entitlements-container').should('contain', 'Customer Engagement');
cy.get('.newfold-entitlements-container').should('contain','Sales & Checkout' );
cy.get('.newfold-entitlements-container').should('contain','Store Operations' );
cy.get('.newfold-entitlements-container').should('contain','Product Management' );

} else if (solutionSku === 'WP_SOLUTION_SERVICE') {
cy.log('This site is associated with the "Service" solution');
cy.get('.newfold-entitlements-container').should('contain', 'Search Engine Optimization');
cy.get('.newfold-entitlements-container').should('contain', 'Content Monetization');
cy.get('.newfold-entitlements-container').should('contain', 'Core Tools');
cy.get('.newfold-entitlements-container').should('contain', 'Customer Engagement');

} else if (solutionSku === 'WP_SOLUTION_CREATOR') {
cy.log('This site is associated with the "Content Creator" solution');
cy.get('.newfold-entitlements-container').should('contain', 'Search Engine Optimization');
cy.get('.newfold-entitlements-container').should('contain','Sales & Checkout' );
cy.get('.newfold-entitlements-container').should('contain', 'Core Tools');
cy.get('.newfold-entitlements-container').should('contain', 'Customer Engagement');

}
else {
cy.log('No solution plan associated with the site');
}


// Dynamically check categories based on the solution SKU
categories.forEach(category => {
cy.get('.newfold-entitlements-container')
.contains('h2', category) // Check if the category is visible
.scrollIntoView()
.should('be.visible');
cy.log('categories');

} );
cy.get( '.newfold-entitlements-container' )
.contains( 'h2', 'My Plugins & Tools' )
.scrollIntoView()
.should( 'be.visible' );
//category:Core tools
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Core Tools' )
.scrollIntoView()
.should( 'be.visible' )
.click();

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

cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h3', 'WonderBlocks' )
.scrollIntoView()
.should( 'be.visible' );
//category:Content Monetization

cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Content Monetization' )
.scrollIntoView()
.should( 'be.visible' )
.click();
//category:Customer Engagement

cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Customer Engagement' )
.scrollIntoView()
.should( 'be.visible' )
.click();
//category:Product Management

cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Product Management' )
.scrollIntoView()
.should( 'be.visible' )
.click();
//category:Sales & Checkout
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Sales & Checkout' )
.scrollIntoView()
.should( 'be.visible' )
.click();

//category:Search Engine Optimization
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Search Engine Optimization' )
.scrollIntoView()
.should( 'be.visible' )
.click();

//category:Store Operations
cy.get( '.nfd-core-tool-mypluginsntools' )
.contains( 'h2', 'Store Operations' )
.scrollIntoView()
.should( 'be.visible' )
.click();


});
});

//verify Add New Plugin button link
it('Verify the Add New Plugin link near the title', () => {
cy.visit('/wp-admin/admin.php?page=' + Cypress.env('pluginId') + '#/my_plugins_and_tools');
cy.get('a')
.contains('Add a New Plugin')
.should('be.visible')
.click()
cy.url().should('eq', 'https://bjo.kax.mybluehost.me/website_489152c4/wp-admin/plugin-install.php')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely failing because in the runner the href will not match this. Try something more along these lines:

cy.get('a').contains('Add a New Plugin')
	.scrollIntoView()
	.should( 'be.visible' )
	.should( 'have.attr', 'href' )
	.and(
		'include',
		'wp-admin/plugin-install'
	);

The test doesn't need to click the link as that will take longer for the new page to load, since it can just check the href.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is to verify the list of categories based on the solution plan as the catergories those are displayed for each solution(ecom,content creator and services) are different. Where in I tried to add the mock data for verify categories based on solution plan.


});
});

Loading