Skip to content

Commit

Permalink
Merge pull request #329 from newfold-labs/add/cypress-test-events-for…
Browse files Browse the repository at this point in the history
…-experience-page

Cypress Tests events API for get-experience page
  • Loading branch information
arunshenoy99 authored Oct 20, 2023
2 parents 7a4a7d0 + db860a9 commit 24759b1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CheckInfoPanel,
CheckIntroPanel,
} from '../wp-module-support/sidebar.cy';
import { APIList } from '../wp-module-support/EventsApi.cy';

describe( 'Start Setup WP Experience Page', function () {
before( () => {
Expand Down Expand Up @@ -34,9 +35,9 @@ describe( 'Start Setup WP Experience Page', function () {
} );

it( 'Check if `site` appears in heading', () => {
cy.get('.nfd-step-card-heading')
.should('be.visible')
.contains('site');
cy.get( '.nfd-step-card-heading' )
.should( 'be.visible' )
.contains( 'site' );
} );

it( 'Check if Radio Options load', () => {
Expand All @@ -51,6 +52,48 @@ describe( 'Start Setup WP Experience Page', function () {
cy.url().should( 'contain', 'get-started/experience' );
} );

const EventsAPI = ( experience_val ) => {
cy.intercept( APIList.get_started_experience ).as( 'events' );
cy.wait( '@events' ).then( ( requestObject ) => {
const responseBody = requestObject.request.body;
const responseData1 = responseBody[ 0 ].data;
if ( 'experience_level' in responseData1 ) {
expect( responseData1.experience_level ).equal(
experience_val
);
} else {
const responseData2 = responseBody[ 1 ].data;
if ( 'experience_level' in responseData2 ) {
expect( responseData2.experience_level ).equal(
experience_val
);
}
}
} );
};

it( 'Check if events API call being made after radio buttons are clicked', () => {
let radioCount = 0;
const className = '.components-radio-control__option';
const arr = cy.get( className );
arr.each( () => {
cy.get( '[type="radio"]' )
.eq( radioCount )
.click( { force: true } );
if ( radioCount == 0 ) {
EventsAPI( 'novice' );
}
if ( radioCount == 1 ) {
EventsAPI( 'intermediate' );
}
if ( radioCount > 1 ) {
cy.wait( 5000 );
EventsAPI( 'expert' );
}
radioCount += 1;
} );
} );

it( 'Checks if all the Radio Buttons are Enabled and Highlighted when clicked', () => {
let radioCount = 0;
const className = '.components-radio-control__option';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CheckInfoPanel,
CheckIntroPanel,
} from '../wp-module-support/sidebar.cy';
import { APIList } from '../wp-module-support/EventsApi.cy';

describe( 'Start Setup WP Experience Page', function () {
before( () => {
Expand Down Expand Up @@ -34,9 +35,9 @@ describe( 'Start Setup WP Experience Page', function () {
} );

it( 'Check if `store` appears in heading', () => {
cy.get('.nfd-step-card-heading')
.should('be.visible')
.contains('store');
cy.get( '.nfd-step-card-heading' )
.should( 'be.visible' )
.contains( 'store' );
} );

it( 'Check if Radio Options load', () => {
Expand All @@ -51,6 +52,48 @@ describe( 'Start Setup WP Experience Page', function () {
cy.url().should( 'contain', 'get-started/experience' );
} );

const EventsAPI = ( experience_val ) => {
cy.intercept( APIList.get_started_experience_ecomm ).as( 'events' );
cy.wait( '@events' ).then( ( requestObject ) => {
const responseBody = requestObject.request.body;
const responseData1 = responseBody[ 0 ].data;
if ( 'experience_level' in responseData1 ) {
expect( responseData1.experience_level ).equal(
experience_val
);
} else {
const responseData2 = responseBody[ 1 ].data;
if ( 'experience_level' in responseData2 ) {
expect( responseData2.experience_level ).equal(
experience_val
);
}
}
} );
};

it( 'Check if events API call being made after radio buttons are clicked', () => {
let radioCount = 0;
const className = '.components-radio-control__option';
const arr = cy.get( className );
arr.each( () => {
cy.get( '[type="radio"]' )
.eq( radioCount )
.click( { force: true } );
if ( radioCount == 0 ) {
EventsAPI( 'novice' );
}
if ( radioCount == 1 ) {
EventsAPI( 'intermediate' );
}
if ( radioCount > 1 ) {
cy.wait( 5000 );
EventsAPI( 'expert' );
}
radioCount += 1;
} );
} );

it( 'Checks if all the Radio Buttons are Enabled and Highlighted when clicked', () => {
let radioCount = 0;
const className = '.components-radio-control__option';
Expand Down
4 changes: 4 additions & 0 deletions tests/cypress/integration/wp-module-support/EventsApi.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const APIList = {
'get_started_experience' : 'http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
'get_started_experience_ecomm' : 'http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user'
}

0 comments on commit 24759b1

Please sign in to comment.