Skip to content

Commit 341d537

Browse files
Merge pull request #671 from newfold-labs/enhance/clear-patterns-for-onboarding-restart
Clear Data for Onboarding Restart
2 parents 06587b9 + 6604f92 commit 341d537

File tree

6 files changed

+387
-5
lines changed

6 files changed

+387
-5
lines changed

includes/Services/StatusService.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
66
use NewfoldLabs\WP\Module\Onboarding\WP_Admin;
77
use NewfoldLabs\WP\Module\Onboarding\Data\Config;
8+
use NewfoldLabs\WP\Module\Onboarding\Data\Flows\Flows;
9+
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
810

911
/**
1012
* Tracks the Status of Onboarding.
@@ -90,6 +92,7 @@ public static function update_onboarding_restart_status(): void {
9092

9193
// Get flow data
9294
$flow_data = get_option( Options::get_option_name( 'flow' ) );
95+
$active_flow = $flow_data['activeFlow'];
9396

9497
if ( isset( $flow_data['onboardingRetries'] ) && ! empty( $flow_data['onboardingRetries'] ) ) {
9598
// Increment the total onboarding tries
@@ -104,6 +107,43 @@ public static function update_onboarding_restart_status(): void {
104107

105108
// Update the eligibility status in wp_option
106109
update_option( Options::get_option_name( 'can_restart' ), $can_restart );
110+
111+
if ( $can_restart ) {
112+
// Module AI prefix
113+
$prefix = 'nfd-ai-site-gen-';
114+
// Sitemeta Options
115+
$enabled_identifiers = array_keys( array_filter( SiteGenService::enabled_identifiers() ) );
116+
117+
// Delete enabled identifiers options
118+
foreach ( $enabled_identifiers as $identifier ) {
119+
delete_option( $prefix . SiteGenService::get_identifier_name( $identifier ) );
120+
}
121+
122+
// Extra NFD-AI Options
123+
$sitegen_identifiers = array(
124+
'keywords',
125+
'homepages',
126+
'generatedpatterns',
127+
'contentstructures',
128+
'siteclassificationmapping',
129+
'refinedsitedescription',
130+
);
131+
foreach ( $sitegen_identifiers as $identifier ) {
132+
delete_option( $prefix . $identifier );
133+
}
134+
135+
delete_option( Options::get_option_name( 'flow' ) );
136+
$flow_data_copy = Flows::get_data();
137+
$flow_data_copy['activeFlow'] = $active_flow;
138+
$flow_data_copy['onboardingRetries']['retryCount'] = $current_retry_count;
139+
140+
// Update the flow data with the incremented total onboarding tries count and add to db
141+
add_option( Options::get_option_name( 'flow' ), $flow_data_copy );
142+
143+
delete_option( Options::get_option_name( 'start_date' ) );
144+
delete_option( Options::get_option_name( 'status' ) );
145+
delete_option( Options::get_option_name( 'sitegen_regenerated_homepages' ) );
146+
}
107147
}
108148
}
109149

tests/cypress/fixtures/flow.json

Lines changed: 316 additions & 0 deletions
Large diffs are not rendered by default.

tests/cypress/integration/3-ecommerce-onboarding-flow/sitetype-primary.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe( 'Get Started Site Type Primary', function () {
4141
CheckHelpPanelLinks();
4242
} );
4343

44-
it( 'Check if Business category is pre-selected', () => {
44+
it.skip( 'Check if Business category is pre-selected', () => {
4545
cy.get( '.chosenPrimaryCategory' )
4646
.find( '.categName' )
4747
.should( 'have.text', 'Business' );

tests/cypress/integration/5-AI-SiteGen-onboarding-flow/6-preview.cy.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../wp-module-support/siteGen.cy';
99
import {
1010
apiList,
11+
flowMock,
1112
siteGenMockAll,
1213
homePagesMock,
1314
homePagesRegenerate,
@@ -18,14 +19,18 @@ describe( 'SiteGen Site Preview Step', function () {
1819
cy.visit(
1920
'wp-admin/index.php?page=nfd-onboarding#/sitegen/step/preview'
2021
);
22+
cy.intercept( apiList.flow, ( req ) => {
23+
flowMock( req );
24+
} ).as( 'flowCall' );
25+
2126
cy.intercept( apiList.sitegen, ( req ) => {
2227
siteGenMockAll( req );
2328
} ).as( 'sitegenCalls' );
2429

2530
cy.intercept( apiList.homepages, ( req ) => {
2631
homePagesMock( req );
2732
} ).as( 'homePageCall' );
28-
cy.wait( 20000 );
33+
cy.wait( 25000 );
2934
} );
3035

3136
it( 'Check for the header admin bar', () => {

tests/cypress/integration/5-AI-SiteGen-onboarding-flow/7-editor.cy.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// <reference types="Cypress" />
22
import {
33
apiList,
4+
flowMock,
45
customizeDataMock,
56
themeStyleMock,
67
} from '../wp-module-support/MockApi.cy';
@@ -16,7 +17,12 @@ describe( 'SiteGen Site Editor Step', function () {
1617
cy.visit(
1718
'wp-admin/index.php?page=nfd-onboarding#/sitegen/step/preview'
1819
);
19-
cy.wait( 10000 );
20+
21+
cy.intercept( apiList.flow, ( req ) => {
22+
flowMock( req );
23+
} ).as( 'flowCall' );
24+
25+
cy.wait( 30000 );
2026
} );
2127

2228
it( 'Select any theme and go forward to the next step', () => {
@@ -103,7 +109,7 @@ describe( 'SiteGen Site Editor Step', function () {
103109
'.nfd-onboarding-sidebar--sitegen-editor-patterns__header__tab-panel__versions-tab__preview-container'
104110
)
105111
.should( 'be.visible' )
106-
.should( 'have.length', 4 ); // Regenerating new themes
112+
.should( 'have.length', 3 ); // Regenerating new themes
107113
} );
108114

109115
it( 'Check for favoriting a theme and it appears everywhere', () => {
@@ -143,7 +149,7 @@ describe( 'SiteGen Site Editor Step', function () {
143149
'.nfd-onboarding-sidebar--sitegen-editor-patterns__header__tab-panel__versions-tab__preview-container'
144150
)
145151
.should( 'be.visible' )
146-
.should( 'have.length', 2 );
152+
.should( 'have.length', 1 );
147153
cy.get(
148154
'.components-button.nfd-onboarding-sidebar--sitegen-editor-patterns__header__icon'
149155
).should( 'be.visible' );

tests/cypress/integration/wp-module-support/MockApi.cy.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ const theme_style_mock = require( '../../fixtures/theme-style.json' );
1212
const customize_data_mock = require( '../../fixtures/customize-data.json' );
1313
const homepage_regenerate_mock = require( '../../fixtures/homepage-regenerate.json' );
1414
const migrate_connect_mock = require( '../../fixtures/migrate-connect.json' );
15+
const flow_mock = require( '../../fixtures/flow.json' );
1516

1617
export const apiList = {
18+
flow:
19+
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fflow&flow=sitegen&_locale=user',
1720
sitegen:
1821
'/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fsitegen%2Fgenerate&flow=sitegen&_locale=user',
1922
homepages:
@@ -28,6 +31,18 @@ export const apiList = {
2831
'/index.php?rest_route=%2Fnewfold-migration%2Fv1%2Fmigrate%2Fconnect&_locale=user',
2932
};
3033

34+
export const flowMock = ( req ) => {
35+
const requestBody = req.body;
36+
req.reply( {
37+
statusCode: 200,
38+
body: flow_mock,
39+
headers: {
40+
'content-type': 'application/json',
41+
},
42+
delay: 3000,
43+
} );
44+
};
45+
3146
export const siteGenMockAll = ( req ) => {
3247
const requestBody = req.body;
3348
const sitegen_identifiers = {

0 commit comments

Comments
 (0)