diff --git a/tests/cypress/integration/2-general-onboarding-flow/get-started-experience.cy.js b/tests/cypress/integration/2-general-onboarding-flow/get-started-experience.cy.js index 81c29b028..a506e7b8f 100644 --- a/tests/cypress/integration/2-general-onboarding-flow/get-started-experience.cy.js +++ b/tests/cypress/integration/2-general-onboarding-flow/get-started-experience.cy.js @@ -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( () => { @@ -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', () => { @@ -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'; diff --git a/tests/cypress/integration/3-ecommerce-onboarding-flow/get-started-experience.cy.js b/tests/cypress/integration/3-ecommerce-onboarding-flow/get-started-experience.cy.js index 87a23c40c..b14420fa6 100644 --- a/tests/cypress/integration/3-ecommerce-onboarding-flow/get-started-experience.cy.js +++ b/tests/cypress/integration/3-ecommerce-onboarding-flow/get-started-experience.cy.js @@ -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( () => { @@ -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', () => { @@ -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'; diff --git a/tests/cypress/integration/wp-module-support/EventsApi.cy.js b/tests/cypress/integration/wp-module-support/EventsApi.cy.js new file mode 100644 index 000000000..7c0e7a8a3 --- /dev/null +++ b/tests/cypress/integration/wp-module-support/EventsApi.cy.js @@ -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' +}