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

PRESS0-1329 | Cypress tests for Migration initiation screen #561

Merged
merged 17 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
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 migate_connect_mock = require( '../../fixtures/migrate-connect.json' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you could change it to *migrate_connect_mock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


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: migate_connect_mock,
delay: 8000,
} );
};
Loading