Skip to content

Commit

Permalink
site capabilities tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeetha-nayak committed Dec 29, 2023
1 parent fcafda7 commit 7844297
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 84 deletions.
84 changes: 0 additions & 84 deletions tests/cypress/integration/Home/siteCapabilities.cy.js

This file was deleted.

163 changes: 163 additions & 0 deletions tests/cypress/integration/Site-Capabilities/siteCapabilities.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { GetPluginId, getAppId } from '../wp-module-support/pluginID.cy';

const customCommandTimeout = 60000;
const mediumWait = 30000;
const pluginId = GetPluginId()
const appId = getAppId();

describe( 'Verify Wondercart accessibility as per capabilities', () => {
const cTBAndYithTrue = JSON.stringify( {
canAccessAI: true,
canAccessHelpCenter: true,
canAccessGlobalCTB: true,
hasEcomdash: false,
hasYithExtended: true,
isEcommerce: true,
isJarvis: true,
} );

const cTBTrueYithFalse = JSON.stringify( {
...cTBAndYithTrue,
hasYithExtended: false,
isEcommerce: false,
} );

before( () => {
cy.visit( '/wp-admin/admin.php?page=' + pluginId + '#/store' );
cy.get( '.nfd-app-section-content .nfd-button--upsell' )
.eq( 0 )
.invoke( 'text' )
.then( ( btnText ) => {
if ( btnText == 'Install WooCommerce' ) {
cy.get( '.nfd-app-section-content .nfd-button--upsell' )
.contains( btnText )
.click();
cy.get( '.nfd-notification--success', {
timeout: customCommandTimeout,
} )
.contains(
'WooCommerce has been installed successfully'
)
.should( 'exist' );
}
} );
} );

beforeEach(() => {
if ( pluginId !== 'bluehost' ) {
this.skip();
}
cy.visit( '/wp-admin/admin.php?page=' + pluginId + '#/home' );
});

after(() => {
cy.exec(
`npx wp-env run cli wp option delete _transient_nfd_site_capabilities`,
{ failOnNonZeroExit: false }
);
})

it('Verify if Sales and Discounts sub tab is displayed', () => {
cy.exec(
`npx wp-env run cli wp option delete _transient_nfd_site_capabilities`,
{ failOnNonZeroExit: false }
);
cy.exec(
`npx wp-env run cli wp option set _transient_nfd_site_capabilities '${ cTBAndYithTrue }' --format=json`,
{ timeout: customCommandTimeout }
)
cy.reload();
cy.get( `.${ appId }-app-navitem-Store`, {
timeout: mediumWait,
} ).click();
cy.get( `.${ appId }-app-subnavitem` )
.contains( 'Sales & Discounts' )
.should( 'exist' );
})

it( 'Verify Buy Now is shown when canAccessGlobalCTB is true and commerce addon is false', () => {
cy.exec(
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '${ cTBTrueYithFalse }'`,
{ timeout: customCommandTimeout }
).then( ( result ) => {
cy.log( result.stdout );
cy.log( result.stderr );
} );
cy.reload();
cy.get( `.${ appId }-app-navitem-Store`, {
timeout: mediumWait,
} ).click();
cy.get( `.${ appId }-app-subnavitem` )
.contains( 'Sales & Discounts' )
.as( 'salesTab' )
.should( 'exist' );
cy.get( '@salesTab' ).click();
cy.get( '.nfd-button--upsell', { timeout: mediumWait } )
.contains( 'Buy now', { timeout: mediumWait } )
.should( 'exist' );
} );

it( 'Verify clicking on Buy Now leads to cpanel login page', () => {
cy.get( `.${ appId }-app-navitem-Store`, {
timeout: mediumWait,
} ).click();
cy.get( `.${ appId }-app-subnavitem` )
.contains( 'Sales & Discounts' )
.click();
cy.get( '.nfd-button--upsell', { timeout: mediumWait } )
.eq( 1 )
.as( 'buyButton' );

cy.get( '@buyButton' ).should( 'be.visible' );
cy.get( '@buyButton' )
.should( 'have.attr', 'href' )
.and(
'include',
'https://my.bluehost.com/hosting/app?utm_source=wp-marketplace&utm_medium=brand-plugin&utm_campaign=wordpress-ad&utm_content=buynow#/marketplace/product'
);
} );

it( 'Verify Install Now is shown when customer has ecommerce addon', () => {
cy.exec(
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '${ cTBAndYithTrue }' --format=json`,
{ timeout: customCommandTimeout }
)
cy.reload();
cy.get( `.${ appId }-app-navitem-Store`, {
timeout: mediumWait,
} ).click();
cy.get( `.${ appId }-app-subnavitem`, { timeout: mediumWait } )
.contains( 'Sales & Discounts' )
.as( 'salesTab' )
.should( 'exist' );
cy.get( '@salesTab' ).click();
cy.get( '.nfd-button--upsell', { timeout: mediumWait } )
.contains( 'Install now', { timeout: mediumWait } )
.should( 'exist' );
} );

it( 'Verify clicking Install Now successfully installs Wonder Cart', () => {
cy.get( `.${ appId }-app-navitem-Store`, {
timeout: mediumWait,
} ).click();
cy.get( `.${ appId }-app-subnavitem` )
.contains( 'Sales & Discounts' )
.click();
cy.get( '.nfd-button--upsell', { timeout: mediumWait } )
.contains( 'Install now' )
.scrollIntoView()
.click();
cy.get( '.nfd-notification--success', {
timeout: customCommandTimeout,
} )
.should( 'exist' )
.and( 'contain.text', 'Installed successfully' );

cy.get( '#wonder-cart-init', { timeout: mediumWait } ).should(
'exist'
);
cy.contains( 'Create campaign', { timeout: mediumWait } ).should(
'exist'
);
});
} );

0 comments on commit 7844297

Please sign in to comment.