From 85b5d4853366d4f0ca7cfb7efffd561b80313ae3 Mon Sep 17 00:00:00 2001 From: Avneet Raj Date: Tue, 10 Oct 2023 19:16:44 +0530 Subject: [PATCH 1/4] add events API for experience page --- .../get-started-experience.cy.js | 39 +++++++++++++++++++ .../get-started-experience.cy.js | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) 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..fa83753f3 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 @@ -65,6 +65,45 @@ describe( 'Start Setup WP Experience Page', function () { } ); } ); + const EventsAPI = ( experience_val ) => { + cy.intercept('http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user').as('events'); + cy.wait('@events').then((interception) => { + const responseBody = interception.request.body; + const responseData1 = responseBody[0].data; + const responseData2 = responseBody[1].data; + if("experience_level" in responseData1){ + expect(responseData1.experience_level).equal(experience_val); + }; + 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.reload(); + cy.wait(2000); + 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 Continue Setup Button is Enabled after the Radio Button is Checked.', () => { cy.get( '[type=radio]:checked' ).should( 'have.css', 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..bcbacbe61 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 @@ -65,6 +65,45 @@ describe( 'Start Setup WP Experience Page', function () { } ); } ); + const EventsAPI = ( experience_val ) => { + cy.intercept('http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user').as('events'); + cy.wait('@events').then((interception) => { + const responseBody = interception.request.body; + const responseData1 = responseBody[0].data; + const responseData2 = responseBody[1].data; + if("experience_level" in responseData1){ + expect(responseData1.experience_level).equal(experience_val); + }; + 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.reload(); + cy.wait(2000); + 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 Continue Setup Button is Enabled after the Radio Button is Checked.', () => { cy.get( '[type=radio]:checked' ).should( 'have.css', From f5c8adeda91a46dc7b5d4b1fcd57076ea997a8ff Mon Sep 17 00:00:00 2001 From: Avneet Raj Date: Tue, 17 Oct 2023 15:56:11 +0530 Subject: [PATCH 2/4] handling edge cases and moving APIs in a single file --- .../get-started-experience.cy.js | 51 ++++++++++--------- .../get-started-experience.cy.js | 51 ++++++++++--------- .../wp-module-support/EventsApi.cy.js | 4 ++ 3 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 tests/cypress/integration/wp-module-support/EventsApi.cy.js 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 fa83753f3..2b4cbf47b 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( () => { @@ -51,31 +52,21 @@ describe( 'Start Setup WP Experience Page', function () { cy.url().should( 'contain', 'get-started/experience' ); } ); - it( 'Checks if all the Radio Buttons are Enabled and Highlighted when 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 } ) - .should( 'not.be.disabled' ) - .should( 'be.checked' ); - radioCount += 1; - } ); - } ); - const EventsAPI = ( experience_val ) => { - cy.intercept('http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user').as('events'); - cy.wait('@events').then((interception) => { - const responseBody = interception.request.body; - const responseData1 = responseBody[0].data; - const responseData2 = responseBody[1].data; - if("experience_level" in responseData1){ - expect(responseData1.experience_level).equal(experience_val); + cy.intercept(APIList.get_started_experience).as('events'); + cy.wait('@events').then((requestObject) => { + const responseBody = requestObject.request.body; + if(typeof responseBody[0].data != "undefined"){ + const responseData1 = responseBody[0].data; + if("experience_level" in responseData1){ + expect(responseData1.experience_level).equal(experience_val); + }; }; - if("experience_level" in responseData2){ - expect(responseData2.experience_level).equal(experience_val); + if(typeof responseBody[1].data != "undefined"){ + const responseData2 = responseBody[1].data; + if("experience_level" in responseData2){ + expect(responseData2.experience_level).equal(experience_val); + }; }; }); }; @@ -104,6 +95,20 @@ describe( 'Start Setup WP Experience Page', function () { } ); } ); + it( 'Checks if all the Radio Buttons are Enabled and Highlighted when 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 } ) + .should( 'not.be.disabled' ) + .should( 'be.checked' ); + radioCount += 1; + } ); + } ); + it( 'Checks if Continue Setup Button is Enabled after the Radio Button is Checked.', () => { cy.get( '[type=radio]:checked' ).should( 'have.css', 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 bcbacbe61..ca7301887 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( () => { @@ -51,31 +52,21 @@ describe( 'Start Setup WP Experience Page', function () { cy.url().should( 'contain', 'get-started/experience' ); } ); - it( 'Checks if all the Radio Buttons are Enabled and Highlighted when 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 } ) - .should( 'not.be.disabled' ) - .should( 'be.checked' ); - radioCount += 1; - } ); - } ); - const EventsAPI = ( experience_val ) => { - cy.intercept('http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user').as('events'); - cy.wait('@events').then((interception) => { - const responseBody = interception.request.body; - const responseData1 = responseBody[0].data; - const responseData2 = responseBody[1].data; - if("experience_level" in responseData1){ - expect(responseData1.experience_level).equal(experience_val); + cy.intercept(APIList.get_started_experience_ecomm).as('events'); + cy.wait('@events').then((requestObject) => { + const responseBody = requestObject.request.body; + if(typeof responseBody[0].data != "undefined"){ + const responseData1 = responseBody[0].data; + if("experience_level" in responseData1){ + expect(responseData1.experience_level).equal(experience_val); + }; }; - if("experience_level" in responseData2){ - expect(responseData2.experience_level).equal(experience_val); + if(typeof responseBody[1].data != "undefined"){ + const responseData2 = responseBody[1].data; + if("experience_level" in responseData2){ + expect(responseData2.experience_level).equal(experience_val); + }; }; }); }; @@ -104,6 +95,20 @@ describe( 'Start Setup WP Experience Page', function () { } ); } ); + it( 'Checks if all the Radio Buttons are Enabled and Highlighted when 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 } ) + .should( 'not.be.disabled' ) + .should( 'be.checked' ); + radioCount += 1; + } ); + } ); + it( 'Checks if Continue Setup Button is Enabled after the Radio Button is Checked.', () => { cy.get( '[type=radio]:checked' ).should( 'have.css', 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' +} From 38971bb49344bb29fb5e98a4883df28b034dfda4 Mon Sep 17 00:00:00 2001 From: Avneet Raj Date: Wed, 18 Oct 2023 14:09:35 +0530 Subject: [PATCH 3/4] remove reload on every step --- .../get-started-experience.cy.js | 14 +++++--------- .../get-started-experience.cy.js | 14 +++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) 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 2b4cbf47b..c7787c24c 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 @@ -56,13 +56,11 @@ describe( 'Start Setup WP Experience Page', function () { cy.intercept(APIList.get_started_experience).as('events'); cy.wait('@events').then((requestObject) => { const responseBody = requestObject.request.body; - if(typeof responseBody[0].data != "undefined"){ - const responseData1 = responseBody[0].data; - if("experience_level" in responseData1){ - expect(responseData1.experience_level).equal(experience_val); - }; - }; - if(typeof responseBody[1].data != "undefined"){ + 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); @@ -76,8 +74,6 @@ describe( 'Start Setup WP Experience Page', function () { const className = '.components-radio-control__option'; const arr = cy.get( className ); arr.each( () => { - cy.reload(); - cy.wait(2000); cy.get( '[type="radio"]' ) .eq( radioCount ) .click( { force: true } ) 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 ca7301887..cdc4bf3fd 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 @@ -56,13 +56,11 @@ describe( 'Start Setup WP Experience Page', function () { cy.intercept(APIList.get_started_experience_ecomm).as('events'); cy.wait('@events').then((requestObject) => { const responseBody = requestObject.request.body; - if(typeof responseBody[0].data != "undefined"){ - const responseData1 = responseBody[0].data; - if("experience_level" in responseData1){ - expect(responseData1.experience_level).equal(experience_val); - }; - }; - if(typeof responseBody[1].data != "undefined"){ + 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); @@ -76,8 +74,6 @@ describe( 'Start Setup WP Experience Page', function () { const className = '.components-radio-control__option'; const arr = cy.get( className ); arr.each( () => { - cy.reload(); - cy.wait(2000); cy.get( '[type="radio"]' ) .eq( radioCount ) .click( { force: true } ) From db860a99b2e9779814951c407b74dc46c9f17289 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 20 Oct 2023 15:11:01 +0530 Subject: [PATCH 4/4] lint fixes --- .../get-started-experience.cy.js | 55 ++++++++++--------- .../get-started-experience.cy.js | 55 ++++++++++--------- 2 files changed, 58 insertions(+), 52 deletions(-) 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 c7787c24c..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 @@ -35,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', () => { @@ -53,20 +53,23 @@ describe( 'Start Setup WP Experience Page', function () { } ); const EventsAPI = ( experience_val ) => { - cy.intercept(APIList.get_started_experience).as('events'); - cy.wait('@events').then((requestObject) => { + 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); + 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 + ); } - 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', () => { @@ -76,17 +79,17 @@ describe( 'Start Setup WP Experience Page', function () { 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"); - }; + .click( { force: true } ); + if ( radioCount == 0 ) { + EventsAPI( 'novice' ); + } + if ( radioCount == 1 ) { + EventsAPI( 'intermediate' ); + } + if ( radioCount > 1 ) { + cy.wait( 5000 ); + EventsAPI( 'expert' ); + } radioCount += 1; } ); } ); 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 cdc4bf3fd..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 @@ -35,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', () => { @@ -53,20 +53,23 @@ describe( 'Start Setup WP Experience Page', function () { } ); const EventsAPI = ( experience_val ) => { - cy.intercept(APIList.get_started_experience_ecomm).as('events'); - cy.wait('@events').then((requestObject) => { + 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); + 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 + ); } - 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', () => { @@ -76,17 +79,17 @@ describe( 'Start Setup WP Experience Page', function () { 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"); - }; + .click( { force: true } ); + if ( radioCount == 0 ) { + EventsAPI( 'novice' ); + } + if ( radioCount == 1 ) { + EventsAPI( 'intermediate' ); + } + if ( radioCount > 1 ) { + cy.wait( 5000 ); + EventsAPI( 'expert' ); + } radioCount += 1; } ); } );