From bac587577aadd3c98f4a65370b52cd01871fea82 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 24 Jul 2024 20:38:35 +0530 Subject: [PATCH] added tests --- tests/cypress/fixtures/products.json | 14 ++++++ tests/cypress/integration/home.cy.js | 68 +++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/cypress/fixtures/products.json diff --git a/tests/cypress/fixtures/products.json b/tests/cypress/fixtures/products.json new file mode 100644 index 000000000..398361cdd --- /dev/null +++ b/tests/cypress/fixtures/products.json @@ -0,0 +1,14 @@ +[ + { + "autoRenewFlag": null, + "expirationDate": "9999.December.31 00:00:00", + "prodId": 7103940, + "prodName": "Free SSL" + }, + { + "autoRenewFlag": null, + "expirationDate": "2025.March.26 00:00:00", + "prodId": 7102074, + "prodName": "SiteLock Lite" + } +] \ No newline at end of file diff --git a/tests/cypress/integration/home.cy.js b/tests/cypress/integration/home.cy.js index 54cf10f97..b9a031492 100644 --- a/tests/cypress/integration/home.cy.js +++ b/tests/cypress/integration/home.cy.js @@ -1,5 +1,5 @@ // - +const productFixtures = require( '../fixtures/products.json' ); describe( 'Home Page', function () { let NewfoldRuntime; @@ -129,4 +129,70 @@ describe( 'Home Page', function () { cy.reload(); cy.get( '.wppbh-webinars-banner-section' ).should( 'not.exist' ); } ); + + it( 'My Products Section exists', () => { + if ( NewfoldRuntime.capabilities.abTestShowMyProducts ) { + cy.get( '.wppbh-products-section' ) + .contains( 'My Products' ) + .scrollIntoView() + .should( 'be.visible' ); + } else { + cy.get( '.wppbh-products-section' ).should( 'not.exist' ); + } + } ); + + it( 'Products Section Renders Correctly', () => { + if ( NewfoldRuntime.capabilities.abTestShowMyProducts ) { + cy.intercept( + 'GET', + '/index.php?rest_route=%2Fnewfold-my-products%2Fv1%2Fproducts&_locale=user', + productFixtures + ); + cy.reload(); + // Verify the table contains the correct product data + cy.get( '.wppbh-products-data-section' ).within( () => { + cy.contains( 'Products & Services' ).should( 'be.visible' ); + cy.contains( 'Free SSL' ).should( 'be.visible' ); + cy.contains( 'SiteLock Lite' ).should( 'be.visible' ); + } ); + } else { + cy.get( '.wppbh-products-section' ).should( 'not.exist' ); + } + } ); + + it( 'Products Section Renders Correctly for No products response', () => { + if ( NewfoldRuntime.capabilities.abTestShowMyProducts ) { + cy.intercept( + 'GET', + '/index.php?rest_route=%2Fnewfold-my-products%2Fv1%2Fproducts&_locale=user', + [] + ); + cy.reload(); + cy.get( '.wppbh-products-section' ) + .contains( 'Sorry, no products. Please, try again later.' ) + .scrollIntoView() + .should( 'be.visible' ); + } else { + cy.get( '.wppbh-products-section' ).should( 'not.exist' ); + } + } ); + + it( 'Products Section Renders Correctly for Empty response', () => { + if ( NewfoldRuntime.capabilities.abTestShowMyProducts ) { + cy.intercept( + 'GET', + '/index.php?rest_route=%2Fnewfold-my-products%2Fv1%2Fproducts&_locale=user', + {} + ); + cy.reload(); + cy.get( '.wppbh-products-section' ) + .contains( + 'Oops, there was an error loading products, please try again later.' + ) + .scrollIntoView() + .should( 'be.visible' ); + } else { + cy.get( '.wppbh-products-section' ).should( 'not.exist' ); + } + } ); } );