Skip to content

Commit

Permalink
Merge pull request #522 from newfold-labs/tests/site-features-event
Browse files Browse the repository at this point in the history
Cypress tests for Events in site-features page
  • Loading branch information
arunshenoy99 authored Mar 18, 2024
2 parents 274ee29 + 6c40c68 commit f139d22
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe( 'Basic Info Page', function () {
cy.get( socialTest7 ).type( 'https://www.tiktok.com/testTikTok' );

cy.wait( 2000 );
cy.intercept( APIList.basic_info ).as( 'events' );
cy.intercept( APIList.events_api_general_onb ).as( 'events' );
cy.get( '.navigation-buttons_next' ).click();
BasicInfoAPI( 'basic_info', label_keys, actual_values );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ describe( 'Start Setup WP Experience Page', function () {
.eq( radioCount )
.click( { force: true } );
if ( radioCount == 0 ) {
EventsAPI( 'experience_level', 'novice', APIList.get_started_experience );
EventsAPI( 'experience_level', 'novice', APIList.events_api_general_onb );
}
if ( radioCount == 1 ) {
EventsAPI( 'experience_level', 'intermediate', APIList.get_started_experience );
EventsAPI( 'experience_level', 'intermediate', APIList.events_api_general_onb );
}
if ( radioCount > 1 ) {
cy.wait( 5000 );
EventsAPI( 'experience_level', 'expert', APIList.get_started_experience );
EventsAPI( 'experience_level', 'expert', APIList.events_api_general_onb );
}
radioCount += 1;
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CheckInfoPanel,
CheckIntroPanel,
} from '../wp-module-support/sidebar.cy';
import { APIList, SiteFeaturesAPI } from '../wp-module-support/EventsApi.cy';

describe( 'Site Features', function () {
before( () => {
Expand All @@ -24,8 +25,8 @@ describe( 'Site Features', function () {

it( 'Check if Header has text `site` in it', () => {
cy.get( '.nfd-main-heading__title' )
.should('be.visible')
.contains('site');
.should( 'be.visible' )
.contains( 'site' );
} );

it( 'Check Drawer Activity', () => {
Expand All @@ -36,19 +37,18 @@ describe( 'Site Features', function () {
);
} );

if(GetPluginId()=='bluehost'){
it( 'Check to make sure sidebar opens, content is in place and close sidebar', () => {
CheckIntroPanel( '__site-features', 'Features' );
CheckIllustrationPanel();
CheckInfoPanel();
CheckHelpPanelLinks();
} );
}
else{
if ( GetPluginId() == 'bluehost' ) {
it( 'Check to make sure sidebar opens, content is in place and close sidebar', () => {
CheckIntroPanel( '__site-features', 'Features' );
CheckIllustrationPanel();
CheckInfoPanel();
CheckHelpPanelLinks();
} );
} else {
it( 'Check to make sure Sidebar opens', () => {
BasicSidebarCheck();
} );
};
}

it( 'Check if Site Features list exists and select them', () => {
let previewCount = 0;
Expand All @@ -65,4 +65,26 @@ describe( 'Site Features', function () {
previewCount += 1;
} );
} );

it( 'Check if site-features GA events are triggerred', () => {
const features = [
'jetpack',
'wpforms-lite',
'google-analytics-for-wordpress',
'wordpress-seo',
'creative-mail-by-constant-contact',
'optinmonster',
];

// Make sure if all site-features are selected
cy.get( '.components-checkbox-control__input' ).each( ( $checkbox ) => {
if ( ! $checkbox.is( ':checked' ) ) {
cy.wrap( $checkbox ).click();
}
} );

cy.intercept( APIList.events_api_general_onb ).as( 'events' );
cy.get( '.navigation-buttons_next' ).click();
SiteFeaturesAPI( 'feature', features );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe( 'Get Started Site Type Primary', function () {
if(num>=2){
cy.wait(4000);
}
EventsAPI('primary_type', dataSlugText, APIList.site_primary);
EventsAPI('primary_type', dataSlugText, APIList.events_api_general_onb);
num+=1;
});
categoryCount += 1;
Expand All @@ -68,7 +68,7 @@ describe( 'Get Started Site Type Primary', function () {
.scrollIntoView()
.should( 'be.visible' )
.type( 'Test' );
EventsAPI('primary_type', 'Test', APIList.site_primary);
EventsAPI('primary_type', 'Test', APIList.events_api_general_onb);
} );

it( 'Check different Categories exist and is selectable', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe( 'Get Started Site Type Secondary', function () {
if(num>=2){
cy.wait(5000);
}
EventsAPI('secondary_type', dataSlugText, APIList.site_secondary);
EventsAPI('secondary_type', dataSlugText, APIList.events_api_general_onb);
num+=1;
});
SubcategoryCount += 1;
Expand All @@ -68,7 +68,7 @@ describe( 'Get Started Site Type Secondary', function () {
.scrollIntoView()
.should( 'be.visible' )
.type( 'Test' );
EventsAPI('secondary_type', 'Test', APIList.site_secondary);
EventsAPI('secondary_type', 'Test', APIList.events_api_general_onb);
} );

it( 'Check different categories exist using `<` and `>`', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ describe( 'Top Priority Page', function () {
.should( 'be.visible' )
.click();
if ( previewCount == 0 ) {
EventsAPI( 'top_priority', 'content', APIList.top_priority );
EventsAPI( 'top_priority', 'content', APIList.events_api_general_onb );
}
if ( previewCount == 1 ) {
EventsAPI( 'top_priority', 'store', APIList.top_priority );
EventsAPI( 'top_priority', 'store', APIList.events_api_general_onb );
}
if ( previewCount > 1 ) {
cy.wait( 5000 );
EventsAPI( 'top_priority', 'design', APIList.top_priority );
EventsAPI( 'top_priority', 'design', APIList.events_api_general_onb );
}
previewCount += 1;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe( 'Basic Info Page', function () {
cy.get( socialTest7 ).type( 'https://www.tiktok.com/testTikTok' );

cy.wait( 2000 );
cy.intercept( APIList.basic_info_ecomm ).as( 'events' );
cy.intercept( APIList.events_api_ecomm ).as( 'events' );
cy.get( '.navigation-buttons_next' ).click();
BasicInfoAPI( 'basic_info_ecomm', label_keys, actual_values );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ describe( 'Start Setup WP Experience Page', function () {
.eq( radioCount )
.click( { force: true } );
if ( radioCount == 0 ) {
EventsAPI( 'experience_level', 'novice', APIList.get_started_experience_ecomm );
EventsAPI( 'experience_level', 'novice', APIList.events_api_ecomm );
}
if ( radioCount == 1 ) {
EventsAPI( 'experience_level', 'intermediate', APIList.get_started_experience_ecomm );
EventsAPI( 'experience_level', 'intermediate', APIList.events_api_ecomm );
}
if ( radioCount > 1 ) {
cy.wait( 5000 );
EventsAPI( 'experience_level', 'expert', APIList.get_started_experience_ecomm );
EventsAPI( 'experience_level', 'expert', APIList.events_api_ecomm );
}
radioCount += 1;
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CheckInfoPanel,
CheckIntroPanel,
} from '../wp-module-support/sidebar.cy';
import { APIList, SiteFeaturesAPI } from '../wp-module-support/EventsApi.cy';

describe( 'Site Features', function () {
before( () => {
Expand All @@ -30,20 +31,18 @@ describe( 'Site Features', function () {
);
} );

if(GetPluginId()=='bluehost'){
if ( GetPluginId() == 'bluehost' ) {
it( 'Check to make sure sidebar opens, content is in place and close sidebar', () => {
CheckIntroPanel( '__site-features', 'Features' );
CheckIllustrationPanel();
CheckInfoPanel();
CheckHelpPanelLinks();
} );
}
else{
} else {
it( 'Check to make sure Sidebar opens', () => {
BasicSidebarCheck();
} );
}


it( 'Check if Site Features list exists and select them', () => {
let previewCount = 0;
Expand All @@ -60,4 +59,26 @@ describe( 'Site Features', function () {
previewCount += 1;
} );
} );

it( 'Check if site-features GA events are triggerred', () => {
const features = [
'jetpack',
'wpforms-lite',
'google-analytics-for-wordpress',
'wordpress-seo',
'creative-mail-by-constant-contact',
'optinmonster',
];

// Make sure if all site-features are selected
cy.get( '.components-checkbox-control__input' ).each( ( $checkbox ) => {
if ( ! $checkbox.is( ':checked' ) ) {
cy.wrap( $checkbox ).click();
}
} );

cy.intercept( APIList.events_api_ecomm ).as( 'events' );
cy.get( '.navigation-buttons_next' ).click();
SiteFeaturesAPI( 'feature', features );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe( 'Get Started Site Type Primary', function () {
if(num>=2){
cy.wait(4000);
}
EventsAPI('primary_type', dataSlugText, APIList.site_primary_ecomm);
EventsAPI('primary_type', dataSlugText, APIList.events_api_ecomm);
num+=1;
});
categoryCount += 1;
Expand All @@ -80,7 +80,7 @@ describe( 'Get Started Site Type Primary', function () {
.scrollIntoView()
.should( 'be.visible' )
.type( 'Test' );
EventsAPI('primary_type', 'Test', APIList.site_primary_ecomm);
EventsAPI('primary_type', 'Test', APIList.events_api_ecomm);
} );

it( 'Check different Categories exist and is selectable', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe( 'Get Started Site Type Secondary', function () {
if(num>=2){
cy.wait(5000);
}
EventsAPI('secondary_type', dataSlugText, APIList.site_secondary_ecomm);
EventsAPI('secondary_type', dataSlugText, APIList.events_api_ecomm);
num+=1;
});
SubcategoryCount += 1;
Expand All @@ -82,7 +82,7 @@ describe( 'Get Started Site Type Secondary', function () {
.scrollIntoView()
.should( 'be.visible' )
.type( 'Test' );
EventsAPI('secondary_type', 'Test', APIList.site_secondary_ecomm);
EventsAPI('secondary_type', 'Test', APIList.events_api_ecomm);
} );

it( 'Check different subCategories exist and is selectable', () => {
Expand Down
40 changes: 20 additions & 20 deletions tests/cypress/integration/wp-module-support/EventsApi.cy.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { forEach } from 'lodash';

export const APIList = {
get_started_experience:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
get_started_experience_ecomm:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user',
top_priority:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
site_primary:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
site_primary_ecomm:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user',
site_secondary:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
site_secondary_ecomm:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user',
basic_info:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
basic_info_ecomm:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user'
events_api_general_onb: '/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user',
events_api_ecomm: '/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=ecommerce&_locale=user'
};

export const EventsAPI = ( events_name, card_val, api_name ) => {
Expand Down Expand Up @@ -101,3 +83,21 @@ export const BasicInfoAPI = (
} );
} );
};

export const SiteFeaturesAPI = ( label_key_value, features = [] ) => {
let index = 0;

cy.wait( '@events' ).then( ( requestObject ) => {
const requestBody = requestObject.request.body;
expect( requestBody[ index ].action ).to.eq( 'feature_added' );

requestBody.forEach( () => {
const requestBodyData = requestBody[ index ].data;
expect( requestBodyData.label_key ).to.eq( label_key_value );
expect( requestBodyData[ label_key_value ] ).to.eq(
features[ index ]
);
index += 1;
} );
} );
};

0 comments on commit f139d22

Please sign in to comment.