Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Show Active Products in Brand Plugin #1170

Merged
merged 15 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function subpages() {
? array(
'bluehost#/staging' => __( 'Staging', 'wp-plugin-bluehost' ),
)
: array();
: array();
$help = array(
'bluehost#/help' => __( 'Help', 'wp-plugin-bluehost' ),
);
Expand Down
7 changes: 7 additions & 0 deletions src/app/pages/home/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Container, Page } from '@newfold/ui-component-library';
import { NewfoldRuntime } from '@newfold-labs/wp-module-runtime';
import WebinarsBanner from 'App/components/webinars-banner';
import AccountCard from './accountCard';
import HelpCard from './helpCard';
import WelcomeSection from './welcomeSection';
import ProductSection from './productSection';

const abTestShowMyProducts = NewfoldRuntime.hasCapability(
'abTestShowMyProducts'
);

const Home = () => {
return (
Expand All @@ -17,6 +23,7 @@ const Home = () => {
</div>
</Container.Block>
</Container>
{ abTestShowMyProducts && <ProductSection /> }
</Page>
);
};
Expand Down
63 changes: 63 additions & 0 deletions src/app/pages/home/productSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Container } from '@newfold/ui-component-library';
import apiFetch from '@wordpress/api-fetch';
import { useState, useEffect } from '@wordpress/element';
import { NewfoldRuntime } from '@newfold-labs/wp-module-runtime';
import { default as NewfoldProducts } from '@newfold-labs/wp-module-my-products/components/product';

Check failure on line 5 in src/app/pages/home/productSection.js

View workflow job for this annotation

GitHub Actions / ESLint

Unable to resolve path to module '@newfold-labs/wp-module-my-products/components/product'
girish-lokapure marked this conversation as resolved.
Show resolved Hide resolved
import { isJarvis } from '../../util/helpers';

// constants to pass to module
const moduleConstants = {
text: {
error: __(
'Oops, there was an error loading products, please try again later.',
'bluehost-wordpress-plugin'
),
noProducts: __(
'Sorry, no products. Please, try again later.',
'bluehost-wordpress-plugin'
),
jarvisText: __(
'Please login to your account manager to see products.',
'bluehost-wordpress-plugin'
),
},
};

// methods to pass to module
const moduleMethods = {
apiFetch,
useState,
useEffect,
NewfoldRuntime,
isJarvis,
};

const ProductSection = () => {
return (
<Container className="wppbh-products-section">
<Container.Header
title={ __( 'My Products', 'bluehost-wordpress-plugin' ) }
>
<p>
{ __(
'A list of products associated with your Bluehost hosting package. For more information, check out the ',
'bluehost-wordpress-plugin'
) }

<a href="https://www.bluehost.com/my-account/renewal-center">
{ __(
'Bluehost Account Manager',
'bluehost-wordpress-plugin'
) }
</a>
</p>
</Container.Header>
<NewfoldProducts
methods={ moduleMethods }
constants={ moduleConstants }
/>
</Container>
);
};

export default ProductSection;
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' );
}
} );
} );
Loading