CYS Redirect to intro screen if theme is not modified (#43736)

* Redirect to intro screen if theme is not modified

* Add changefile(s) from automation for the following project(s): woocommerce

* Add and fix test for the redirection

* Redirect with the proper url 'intro'

* Remove only

* Avoid completing the cys task when switching themes

* Revert prev commit and reset `woocommerce_admin_customize_store_completed` before each test

* Set the `woocommerce_admin_customize_store_completed` to `no` before each test

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-01-23 11:15:19 +01:00 committed by GitHub
parent 4fd42aa7c5
commit a44a45b56a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 4 deletions

View File

@ -357,8 +357,32 @@ export const customizeStoreStateMachineDefinition = createMachine( {
},
},
assemblerHub: {
initial: 'preCheckAiStatus',
initial: 'fetchActiveThemeHasMods',
states: {
fetchActiveThemeHasMods: {
invoke: {
src: 'fetchIntroData',
onDone: {
target: 'checkActiveThemeHasMods',
actions: [ 'assignActiveThemeHasMods' ],
},
},
},
checkActiveThemeHasMods: {
always: [
{
cond: 'activeThemeIsNotModified',
actions: [
{ type: 'updateQueryStep', step: 'intro' },
],
target: '#customizeStore.intro',
},
{
cond: 'activeThemeHasMods',
target: 'preCheckAiStatus',
},
],
},
preCheckAiStatus: {
always: [
{
@ -493,6 +517,12 @@ export const CustomizeStoreController = ( {
},
isWooExpress: () => isWooExpress(),
isNotWooExpress: () => ! isWooExpress(),
activeThemeHasMods: ( _ctx ) => {
return _ctx.intro.activeThemeHasMods;
},
activeThemeIsNotModified: ( _ctx ) => {
return ! _ctx.intro.activeThemeHasMods;
},
},
} );
}, [ actionOverrides, servicesOverrides ] );

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Redirect to the CYS intro screen when accessing the assembled hub without going through the customizing process.

View File

@ -25,7 +25,7 @@ class CustomizeStore extends Task {
global $_GET;
$theme_switch_via_cys_ai_loader = isset( $_GET['theme_switch_via_cys_ai_loader'] ) ? 1 === absint( $_GET['theme_switch_via_cys_ai_loader'] ) : false;
if ( ! $theme_switch_via_cys_ai_loader ) {
add_action( 'switch_theme', array( $this, 'mark_task_as_complete' ) );
add_action( 'switch_theme', array( $this, 'mark_task_as_complete' ) );
}
// Hook to remove unwanted UI elements when users are viewing with ?cys-hide-admin-bar=true.

View File

@ -6,6 +6,8 @@ const { setOption } = require( '../../utils/options' );
const ASSEMBLER_HUB_URL =
'/wp-admin/admin.php?page=wc-admin&path=%2Fcustomize-store%2Fassembler-hub';
const CUSTOMIZE_STORE_URL =
'/wp-admin/admin.php?page=wc-admin&path=%2Fcustomize-store';
const skipTestIfUndefined = () => {
const skipMessage = `Skipping this test on daily run. Environment not compatible.`;
@ -46,6 +48,19 @@ test.describe( 'Store owner can view Assembler Hub for store customization', ()
await activateTheme( 'twentytwentythree' );
} );
test.beforeEach( async ( { baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_admin_customize_store_completed',
'no'
);
} catch ( error ) {
console.log( 'Store completed option not updated', error );
}
} );
test.afterAll( async ( { baseURL } ) => {
await features.resetFeatureFlags( request, baseURL );
@ -61,10 +76,25 @@ test.describe( 'Store owner can view Assembler Hub for store customization', ()
);
} );
test( 'Can view the Assembler Hub page', async ( { page } ) => {
test( 'Can not access the Assembler Hub page when the theme is not customized', async ( {
page,
} ) => {
await page.goto( ASSEMBLER_HUB_URL );
const locator = page.locator( 'h1:visible' );
await expect( locator ).toHaveText( "Let's get creative" );
await expect( locator ).not.toHaveText( 'Customize your store' );
} );
test( 'Can view the Assembler Hub page when the theme is already customized', async ( {
page,
} ) => {
await page.goto( CUSTOMIZE_STORE_URL );
await page.click( 'text=Start designing' );
await page.waitForURL( ASSEMBLER_HUB_URL );
await page.goto( ASSEMBLER_HUB_URL );
await expect( page.locator( "text=Let's get creative" ) ).toBeVisible();
} );
test( 'Visiting change header should show a list of block patterns to choose from', async ( {