Skip to content

Commit

Permalink
Merge pull request #561 from newfold-labs/add/migration-screen/tests
Browse files Browse the repository at this point in the history
PRESS0-1329 | Cypress tests for Migration initiation screen
  • Loading branch information
sangeetha-nayak authored May 14, 2024
2 parents 52e72f9 + 6182823 commit 33db773
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/cypress/fixtures/migrate-connect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"success": true,
"data": {
"message": "Connect plugin is installed and ready to start the migration.",
"response": true,
"redirect_url": "https:\/\/app.instawp.io\/migrate\/bluehost?d_id=1bb9623e-5208-40f7-9383-cd91df2fe58c"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DarkBGCheck,
LightBGCheck,
} from '../wp-module-support/siteGen.cy';
import { apiList, migrationConnection } from '../wp-module-support/MockApi.cy';

describe( 'SiteGen Fork Step', function () {
before( () => {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe( 'SiteGen Fork Step', function () {
arr.each( ( $element ) => {
const dataSlugText = $element.attr( 'data-flow' );
if ( dataSlugText == 'sitegen' ) {
$element.click();
$element.trigger( 'click' );
cy.url().should( 'include', 'sitegen/step/welcome', {
timeout: 10000,
} );
Expand All @@ -74,4 +75,54 @@ describe( 'SiteGen Fork Step', function () {
.should( 'exist' )
.should( 'contain', 'Already have a WordPress site' );
} );

it( 'Verify by default import your WP account leads to transfer site link' , () => {
cy.window().then( ( win ) => {
cy.spy( win, 'open', ( url ) => {
win.location.href =
'https://bluehost.com/my-account/hosting/details/sites/add/transfer';
} ).as( 'windowOpen' );
} );

cy.get( '.nfd-onboarding-step--site-gen__fork__importsite' )
.scrollIntoView()
.click();

cy.get( '@windowOpen' ).should( 'be.called' );
} );

it( 'Verify Import site leads to migration process initiation screen when can migrate capability is set' , () => {
cy.exec(
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasAISiteGen": true, "canAccessAI": true, "canMigrateSite": true}' --format=json`,
{ timeout: 20000 }
);
cy.reload()
cy.intercept( apiList.migrateConnect, ( req ) => {
migrationConnection( req );
} ).as( 'migrateCall' );
cy.get( '.nfd-onboarding-step--site-gen__fork__importsite' , {
timeout: 10000,
} )
.scrollIntoView()
.should( 'exist' )
.click();
cy.get( '.nfd-onboarding-step__heading__title', {
timeout: 10000,
} ).should( 'exist' );
cy.get(
'.nfd-onboarding-step--site-gen__migration--container__loader', { timeout : 10000 }
).should( 'exist' );
cy.get(
'.nfd-onboarding-step--site-gen__migration--container__importtext'
).should( 'exist' );

AdminBarCheck();
DarkBGCheck();
LightBGCheck();
cy.wait( '@migrateCall', { timeout: 10000 } );
} );

it( 'Verify migration connection request is successful and redirection happens' , () => {
cy.url().should( 'contain', 'app.instawp.io/migrate' );
} );
} );
12 changes: 12 additions & 0 deletions tests/cypress/integration/wp-module-support/MockApi.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const homepages_mock = require( '../../fixtures/homepages.json' );
const theme_style_mock = require( '../../fixtures/theme-style.json' );
const customize_data_mock = require( '../../fixtures/customize-data.json' );
const homepage_regenerate_mock = require( '../../fixtures/homepage-regenerate.json' );
const migrate_connect_mock = require( '../../fixtures/migrate-connect.json' );

export const apiList = {
sitegen:
Expand All @@ -23,6 +24,8 @@ export const apiList = {
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fthemes%2Fvariations&variations=false&flow=sitegen&_locale=user',
customizedata:
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fsitegen%2Fcustomize-data&flow=sitegen&_locale=user',
migrateConnect:
'/index.php?rest_route=%2Fnewfold-migration%2Fv1%2Fmigrate%2Fconnect&_locale=user',
};

export const siteGenMockAll = ( req ) => {
Expand Down Expand Up @@ -91,3 +94,12 @@ export const homePagesRegenerate = ( req ) => {
},
} );
};

export const migrationConnection = ( req ) => {
req.reply( {
method: 'GET',
statusCode: 200,
body: migrate_connect_mock,
delay: 8000,
} );
};

0 comments on commit 33db773

Please sign in to comment.