Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
girish-lokapure committed Jul 24, 2024
1 parent 5a1bf2a commit bac5875
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/cypress/fixtures/products.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
68 changes: 67 additions & 1 deletion tests/cypress/integration/home.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <reference types="Cypress" />

const productFixtures = require( '../fixtures/products.json' );
describe( 'Home Page', function () {
let NewfoldRuntime;

Expand Down Expand Up @@ -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' );
}
} );
} );

0 comments on commit bac5875

Please sign in to comment.