From 75fa5f424f3caf9687209d5f89977e244765a9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 11 Apr 2024 13:24:43 +0200 Subject: [PATCH 1/3] Blueprints: Support a landingPage value without initial slash Without this PR, a Blueprint like `{ "landingPage": "wp-admin/plugins.php" }` won't work as there is no initial slash. This PR adjusts the Playground API to prepend that slash as URLs without one should be relative to the document root anyway. ## Testing instructions Confirm the E2E tests passed --- packages/playground/blueprints/src/lib/compile.ts | 9 ++++++--- packages/playground/website/cypress/e2e/blueprints.cy.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/playground/blueprints/src/lib/compile.ts b/packages/playground/blueprints/src/lib/compile.ts index 74827f301d..c4f13bc851 100644 --- a/packages/playground/blueprints/src/lib/compile.ts +++ b/packages/playground/blueprints/src/lib/compile.ts @@ -241,6 +241,11 @@ export function compileBlueprint( throw e; } + let landingPage = blueprint.landingPage || '/'; + if (!landingPage.startsWith('/')) { + landingPage = '/' + landingPage; + } + const steps = (blueprint.steps || []) as StepDefinition[]; const totalProgressWeight = steps.reduce( (total, step) => total + (step.progress?.weight || 1), @@ -299,9 +304,7 @@ export function compileBlueprint( } } finally { try { - await (playground as any).goTo( - blueprint.landingPage || '/' - ); + await (playground as any).goTo(landingPage); } catch (e) { /* * NodePHP exposes no goTo method. diff --git a/packages/playground/website/cypress/e2e/blueprints.cy.ts b/packages/playground/website/cypress/e2e/blueprints.cy.ts index 1d104ca6c2..7ad1102b0b 100644 --- a/packages/playground/website/cypress/e2e/blueprints.cy.ts +++ b/packages/playground/website/cypress/e2e/blueprints.cy.ts @@ -33,6 +33,14 @@ describe('Blueprints', () => { cy.wordPressDocument().its('body').should('contain', 'Sample Page'); }); + it('Landing page without the initial slash should work', () => { + const blueprint: Blueprint = { + landingPage: 'wp-admin/plugins.php', + }; + cy.visit('/#' + JSON.stringify(blueprint)); + cy.wordPressDocument().its('body').should('contain.text', 'Plugins'); + }); + it('enableMultisite step should enable a multisite', () => { const blueprint: Blueprint = { landingPage: '/', From 27e811cd6d8fd13c0a636d418af340cb7dd558e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 11 Apr 2024 13:27:47 +0200 Subject: [PATCH 2/3] Remove dev artifact --- packages/playground/blueprints/src/lib/compile.ts | 9 +++------ .../playground/remote/src/lib/boot-playground-remote.ts | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/playground/blueprints/src/lib/compile.ts b/packages/playground/blueprints/src/lib/compile.ts index c4f13bc851..74827f301d 100644 --- a/packages/playground/blueprints/src/lib/compile.ts +++ b/packages/playground/blueprints/src/lib/compile.ts @@ -241,11 +241,6 @@ export function compileBlueprint( throw e; } - let landingPage = blueprint.landingPage || '/'; - if (!landingPage.startsWith('/')) { - landingPage = '/' + landingPage; - } - const steps = (blueprint.steps || []) as StepDefinition[]; const totalProgressWeight = steps.reduce( (total, step) => total + (step.progress?.weight || 1), @@ -304,7 +299,9 @@ export function compileBlueprint( } } finally { try { - await (playground as any).goTo(landingPage); + await (playground as any).goTo( + blueprint.landingPage || '/' + ); } catch (e) { /* * NodePHP exposes no goTo method. diff --git a/packages/playground/remote/src/lib/boot-playground-remote.ts b/packages/playground/remote/src/lib/boot-playground-remote.ts index 4b1e558d27..0ef0fc8a03 100644 --- a/packages/playground/remote/src/lib/boot-playground-remote.ts +++ b/packages/playground/remote/src/lib/boot-playground-remote.ts @@ -130,6 +130,9 @@ export async function bootPlaygroundRemote() { }); }, async goTo(requestedPath: string) { + if (!requestedPath.startsWith('/')) { + requestedPath = '/' + requestedPath; + } /** * People often forget to type the trailing slash at the end of * /wp-admin/ URL and end up with wrong relative hrefs. Let's From 55fe1ce3f1bbe9c768cee3602fe7eb86d4883b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 12 Apr 2024 00:04:33 +0200 Subject: [PATCH 3/3] Add login: true to the e2e test --- packages/playground/website/cypress/e2e/blueprints.cy.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/playground/website/cypress/e2e/blueprints.cy.ts b/packages/playground/website/cypress/e2e/blueprints.cy.ts index 7ad1102b0b..1a9a2db611 100644 --- a/packages/playground/website/cypress/e2e/blueprints.cy.ts +++ b/packages/playground/website/cypress/e2e/blueprints.cy.ts @@ -36,6 +36,7 @@ describe('Blueprints', () => { it('Landing page without the initial slash should work', () => { const blueprint: Blueprint = { landingPage: 'wp-admin/plugins.php', + login: true, }; cy.visit('/#' + JSON.stringify(blueprint)); cy.wordPressDocument().its('body').should('contain.text', 'Plugins');