Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Tests events API for get-experience page #329

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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'
}