Skip to content

Commit

Permalink
Persist default mobile_redirect setting when it is not interacted with
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwatkins0 committed Jul 6, 2020
1 parent bd9c505 commit 7f997eb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
14 changes: 12 additions & 2 deletions assets/src/setup/components/options-context-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export function OptionsContextProvider( { children, optionsRestEndpoint } ) {
delete updatesToSave.reader_theme;
}

// If this is the first time running the wizard and mobile_redirect is not in updates, set mobile_redirect to true.
// We do this here instead of in the fetch effect to prevent the exit confirmation before the user has interacted.
if ( ! originalOptions.wizard_completed && ! ( 'mobile_redirect' in updatesToSave ) ) {
updatesToSave.mobile_redirect = true;
}

if ( ! originalOptions.wizard_completed ) {
updatesToSave.wizard_completed = true;
}

// Ensure this promise lasts at least a second so that the "Saving Options" load screen is
// visible long enough for the user to see it is happening.
const [ savedOptions ] = await Promise.all(
Expand All @@ -108,7 +118,7 @@ export function OptionsContextProvider( { children, optionsRestEndpoint } ) {
{
method: 'post',
url: optionsRestEndpoint,
data: { ...updates, wizard_completed: true },
data: updatesToSave,
},
),
waitASecond(),
Expand All @@ -127,7 +137,7 @@ export function OptionsContextProvider( { children, optionsRestEndpoint } ) {

setDidSaveOptions( true );
setSavingOptions( false );
}, [ optionsRestEndpoint, setError, updates ] );
}, [ optionsRestEndpoint, setError, originalOptions.wizard_completed, updates ] );

/**
* Updates options in state.
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions tests/e2e/specs/admin/mobile-redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* WordPress dependencies
*/
const { visitAdminPage } = require( '@wordpress/e2e-test-utils/build/visit-admin-page' );

/**
* Internal dependencies
*/
const { completeWizard, cleanUpWizard } = require( '../../utils/onboarding-wizard-utils' );

describe( 'Mobile redirect settings', () => {
afterEach( async () => {
await visitAdminPage( 'admin.php', 'page=amp-setup' );
await cleanUpWizard();
} );

it( 'persists the mobile redirect setting on', async () => {
await completeWizard( { mode: 'reader' } );
await visitAdminPage( 'admin.php', 'page=amp-options' );

await page.waitForSelector( '#mobile_redirect' );
await expect( page ).toMatchElement( '#mobile_redirect:checked' );
} );

it( 'persists the mobile redirect setting off', async () => {
await completeWizard( { mode: 'reader', mobileRedirect: false } );
await visitAdminPage( 'admin.php', 'page=amp-options' );

await page.waitForSelector( '#mobile_redirect' );
await expect( page ).not.toMatchElement( '#mobile_redirect:checked' );
} );
} );
19 changes: 17 additions & 2 deletions tests/e2e/utils/onboarding-wizard-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,23 @@ export async function moveToSummaryScreen( { technical = true, mode, readerTheme
await page.waitForSelector( '.summary' );
}

export async function completeWizard( { technical = true, mode, readerTheme = 'legacy' } ) {
await moveToSummaryScreen( { technical, mode, readerTheme } );
export async function completeWizard( { technical = true, mode, readerTheme = 'legacy', mobileRedirect = true } ) {
await moveToSummaryScreen( { technical, mode, readerTheme, mobileRedirect } );

if ( 'standard' !== mode ) {
await page.waitForSelector( '.redirect-toggle input' );

const selector = '.redirect-toggle input:checked';
const checkedMobileRedirect = await page.$( selector );

if ( checkedMobileRedirect && false === mobileRedirect ) {
await expect( page ).toClick( selector );
await page.waitForSelector( '.redirect-toggle input:not(:checked)' );
} else if ( ! checkedMobileRedirect && true === mobileRedirect ) {
await expect( page ).toClick( selector );
await page.waitForSelector( selector );
}
}

await clickNextButton();
await page.waitForSelector( '.done__preview-container' );
Expand Down

0 comments on commit 7f997eb

Please sign in to comment.