From 2aab564deac31b97cbe5449f487e60583770637e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 28 Nov 2023 19:10:32 +0000 Subject: [PATCH] test(e2e): Access sessionId via store, not URL --- e2e/tests/ui-driven/src/globalHelpers.ts | 22 +++++-------------- .../src/@planx/components/Pay/Public/Pay.tsx | 2 -- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/e2e/tests/ui-driven/src/globalHelpers.ts b/e2e/tests/ui-driven/src/globalHelpers.ts index ee9055fbd2..4c2def8e37 100644 --- a/e2e/tests/ui-driven/src/globalHelpers.ts +++ b/e2e/tests/ui-driven/src/globalHelpers.ts @@ -229,15 +229,6 @@ export async function expectSections({ await expect(pageStatuses).toContainText(sections.map((s) => s.status)); } -export async function getSessionId(page: Page): Promise { - // the session id is not available in the url so find it in a test utility component - const sessionId: string | null = await page - .getByTestId("sessionId") - .getAttribute("data-sessionid"); - if (!sessionId) throw new Error("Session ID not found on page"); - return sessionId!; -} - export async function fillGovUkCardDetails({ page, cardNumber, @@ -310,17 +301,16 @@ export async function setFeatureFlag(page: Page, featureFlag: string) { ); } -export async function getSessionIdFromURL(page: Page): Promise { - const url = await new URL(page.url()); - const sessionId = url.searchParams.get("sessionId"); - if (!sessionId) - throw Error("Session ID missing from page. URL " + url.toString()); +export async function getSessionId(page: Page): Promise { + // @ts-expect-error - Property api does not exist on type Window & typeof globalThis + const sessionId = page.evaluate(() => window.api.getState().sessionId); + if (!sessionId) throw Error("Session ID missing from window"); return sessionId; } export async function addSessionToContext(page: Page, context: Context) { - const sessionId = await getSessionIdFromURL(page); - await context.sessionIds!.push(sessionId); + const sessionId = await getSessionId(page); + context.sessionIds!.push(sessionId); return sessionId; } diff --git a/editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx b/editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx index 6925de00fd..9321eef069 100644 --- a/editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx +++ b/editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx @@ -303,8 +303,6 @@ function Component(props: Props) { ) : ( )} - {/* session id exposed for testing purposes */} - ); }