Skip to content

Commit

Permalink
test(e2e): Access sessionId via store, not URL (#2494)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Nov 29, 2023
1 parent 385970d commit 0547118
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
22 changes: 6 additions & 16 deletions e2e/tests/ui-driven/src/globalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ export async function expectSections({
await expect(pageStatuses).toContainText(sections.map((s) => s.status));
}

export async function getSessionId(page: Page): Promise<string> {
// 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,
Expand Down Expand Up @@ -310,17 +301,16 @@ export async function setFeatureFlag(page: Page, featureFlag: string) {
);
}

export async function getSessionIdFromURL(page: Page): Promise<string> {
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<string> {
// @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;
}

Expand Down
2 changes: 0 additions & 2 deletions editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ function Component(props: Props) {
) : (
<DelayedLoadingIndicator text={state.displayText || state.status} />
)}
{/* session id exposed for testing purposes */}
<span data-testid="sessionId" data-sessionid={sessionId}></span>
</>
);
}
Expand Down

0 comments on commit 0547118

Please sign in to comment.