Skip to content

Commit

Permalink
separate out types and service data
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 29, 2024
1 parent 6f70225 commit 0e0374e
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 109 deletions.
24 changes: 6 additions & 18 deletions e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect, test } from "@playwright/test";
import type { Context } from "./helpers/context";
import {
contextDefaults,
setUpTestContext,
Expand All @@ -9,15 +8,14 @@ import { getTeamPage } from "./helpers/getPage";
import { createAuthenticatedSession } from "./helpers/globalHelpers";
import { answerFindProperty, clickContinue } from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";
import { publishService, turnServiceOnline } from "./helpers/navigateAndPublish";
import { TestContext } from "./helpers/types";
import { serviceProps } from "./helpers/serviceData";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
let context: TestContext = {
...contextDefaults,
};
const serviceProps = {
name: "A Test Service",
slug: "a-test-service",
};

test.beforeAll(async () => {
try {
Expand All @@ -44,9 +42,6 @@ test.describe("Flow creation, publish and preview", () => {
page.on("dialog", (dialog) => dialog.accept(serviceProps.name));
await editor.addNewService();

// update context to allow flow to be torn down
context.flow = { ...serviceProps };

await editor.createFindProperty();
await expect(editor.nodeList).toContainText(["Find property"]);
await editor.createInternalPortal();
Expand Down Expand Up @@ -79,8 +74,7 @@ test.describe("Flow creation, publish and preview", () => {
});
// publish flow
await page.goto(`/${context.team.slug}/${serviceProps.slug}`);
page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();
publishService(page)

let previewLink = page.getByRole("link", {
name: "Open published service",
Expand All @@ -89,13 +83,7 @@ test.describe("Flow creation, publish and preview", () => {

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

// Toggle flow online
page.locator('[aria-label="Service settings"]').click();
page.getByLabel("Offline").click();
page.getByRole("button", { name: "Save", disabled: false }).click();
await expect(
page.getByText("Service settings updated successfully"),
).toBeVisible();
turnServiceOnline(page)

// Exit back to main Editor page
page.locator('[aria-label="Editor"]').click();
Expand Down
32 changes: 13 additions & 19 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Browser, expect, test } from "@playwright/test";
import type { Context } from "./helpers/context";
import {
contextDefaults,
externalPortalFlowData,
externalPortalServiceProps,
setUpTestContext,
tearDownTestContext,
} from "./helpers/context";
Expand All @@ -23,16 +20,17 @@ import {
import { PlaywrightEditor } from "./pages/Editor";
import {
createExternalPortal,
createQuestionWithOptions,
} from "./helpers/addComponent";
import {
navigateToService,
publishService,
turnServiceOnline,
} from "./helpers/navigateAndPublish";
import { TestContext } from "./helpers/types";
import { externalPortalFlowData, externalPortalServiceProps } from "./helpers/serviceData";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
let context: TestContext = {
...contextDefaults,
};
const serviceProps = {
Expand Down Expand Up @@ -131,8 +129,7 @@ test.describe("Flow creation, publish and preview", () => {
userId: context.user!.id!,
});

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

await navigateToService(page, serviceProps.slug)
await publishService(page);

const previewLink = page.getByRole("link", {
Expand Down Expand Up @@ -166,8 +163,7 @@ test.describe("Flow creation, publish and preview", () => {
userId: context.user!.id!,
});

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

await navigateToService(page, serviceProps.slug)
await turnServiceOnline(page);

// Exit back to main Editor page
Expand Down Expand Up @@ -201,22 +197,20 @@ test.describe("Flow creation, publish and preview", () => {
// update context to allow new flow to be torn down
context.externalPortalFlow = { ...externalPortalServiceProps };

await createQuestionWithOptions(
page,
editor.firstNode,
externalPortalFlowData.title,
externalPortalFlowData.answers,
);
const {title, answers} = externalPortalFlowData

await editor.createQuestionWithOptions(title, answers)

await expect(editor.nodeList).toContainText([
externalPortalFlowData.title,
externalPortalFlowData.answers[0],
externalPortalFlowData.answers[1],
title,
answers[0],
answers[1],
]);

await publishService(page);
await turnServiceOnline(page);

navigateToService(page, serviceProps.slug);
await navigateToService(page, serviceProps.slug);

await createExternalPortal(page, page.locator("li:nth-child(6)"));

Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/ui-driven/src/helpers/addComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { expect, Locator, Page } from "@playwright/test";
import { contextDefaults, externalPortalServiceProps } from "./context";
import { contextDefaults } from "./context";
import { externalPortalServiceProps } from "./serviceData";

const createBaseComponent = async (
page: Page,
Expand Down
51 changes: 10 additions & 41 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@ import { sign } from "jsonwebtoken";
import assert from "node:assert";
import { log } from "./globalHelpers";
import { $admin } from "../../../api-driven/src/client";
import { Flow, TestContext } from "./types";

type NewTeam = Parameters<CoreDomainClient["team"]["create"]>[0];

export interface Flow {
id?: string;
publishedId?: number;
slug: string;
name: string;
data?: object;
}

export interface Context {
user: {
id?: number;
firstName: string;
lastName: string;
email: string;
isPlatformAdmin: boolean;
};
team: { id?: number } & NewTeam;
flow?: Flow;
externalPortalFlow?:Flow;
sessionIds?: string[];
}

export const contextDefaults: Context = {
export const contextDefaults: TestContext = {
user: {
id: 0,
firstName: "Test",
lastName: "Test",
email: "[email protected]",
Expand All @@ -51,10 +30,10 @@ export const contextDefaults: Context = {
};

export async function setUpTestContext(
initialContext: Context,
): Promise<Context> {
initialContext: TestContext,
): Promise<TestContext> {
const $admin = getCoreDomainClient();
const context: Context = { ...initialContext };
const context: TestContext = { ...initialContext };
if (context.user) {
context.user.id = await $admin.user.create(context.user);
}
Expand Down Expand Up @@ -96,17 +75,7 @@ export async function setUpTestContext(
return context;
}

export const externalPortalServiceProps = {
name: "An External Portal Service",
slug: "an-external-portal-service",
};

export const externalPortalFlowData = {
title: "Is this an External Portal?",
answers: ["It is an external portal", "No it is not an External Portal"],
};

export async function tearDownTestContext(context: Context) {
export async function tearDownTestContext(context: TestContext) {
const adminGQLClient = getGraphQLClient();
if (context.flow || context.externalPortalFlow) {
await $admin.flow._destroyAll()
Expand Down Expand Up @@ -268,7 +237,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, flow: Flow) {
}
}

async function deleteUser(adminGQLClient: GraphQLClient, context: Context) {
async function deleteUser(adminGQLClient: GraphQLClient, context: TestContext) {
if (context.user?.id) {
log(`deleting user ${context.user?.id}`);
await adminGQLClient.request(
Expand Down Expand Up @@ -305,7 +274,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) {
}
}

async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) {
async function deleteTeam(adminGQLClient: GraphQLClient, context: TestContext) {
if (context.team?.id) {
log(`deleting team ${context.team?.id}`);
await adminGQLClient.request(
Expand Down Expand Up @@ -342,7 +311,7 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) {
}
}

async function setupGovPaySecret($admin: CoreDomainClient, context: Context) {
async function setupGovPaySecret($admin: CoreDomainClient, context: TestContext) {
try {
await $admin.client.request(
gql`
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/ui-driven/src/helpers/globalHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FlowGraph } from "@opensystemslab/planx-core/types";
import type { Browser, Page, Request } from "@playwright/test";
import { gql } from "graphql-request";
import type { Context } from "./context";
import { generateAuthenticationToken, getGraphQLClient } from "./context";
import { TestContext } from "./types";

// Test card numbers to be used in gov.uk sandbox environment
// reference: https://docs.payments.service.gov.uk/testing_govuk_pay/#if-you-39-re-using-a-test-39-sandbox-39-account
Expand Down Expand Up @@ -87,15 +87,15 @@ export async function getSessionId(page: Page): Promise<string> {
return sessionId;
}

export async function addSessionToContext(page: Page, context: Context) {
export async function addSessionToContext(page: Page, context: TestContext) {
const sessionId = await getSessionId(page);
context.sessionIds!.push(sessionId);
return sessionId;
}

export async function waitForPaymentResponse(
page: Page,
context: Context,
context: TestContext,
): Promise<{ paymentId: string; state?: { status: string } }> {
const { payment_id: paymentId, state } = await page
.waitForResponse((response) => {
Expand All @@ -110,7 +110,7 @@ export async function modifyFlow({
context,
modifiedFlow,
}: {
context: Context;
context: TestContext;
modifiedFlow: FlowGraph;
}) {
const adminGQLClient = getGraphQLClient();
Expand Down
2 changes: 0 additions & 2 deletions e2e/tests/ui-driven/src/helpers/navigateAndPublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export const navigateToService = async (page: Page, slug: string) => {
await page.goto(`/${contextDefaults.team.slug}/${slug}`);

await expect(page.getByRole("link", { name: slug })).toBeVisible();

return true;
};

export const publishService = async (page: Page) => {
Expand Down
15 changes: 15 additions & 0 deletions e2e/tests/ui-driven/src/helpers/serviceData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export const serviceProps = {
name: "A Test Service",
slug: "a-test-service",
};

export const externalPortalServiceProps = {
name: "An External Portal Service",
slug: "an-external-portal-service",
};

export const externalPortalFlowData = {
title: "Is this an External Portal?",
answers: ["It is an external portal", "No it is not an External Portal"],
};
22 changes: 22 additions & 0 deletions e2e/tests/ui-driven/src/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CoreDomainClient } from "@opensystemslab/planx-core";
import { User } from "@opensystemslab/planx-core/dist/types";


type NewTeam = Parameters<CoreDomainClient["team"]["create"]>[0];

export interface Flow {
id?: string;
publishedId?: number;
slug: string;
name: string;
data?: object;
}


export interface TestContext {
user: Omit<User, "teams">;
team: { id?: number } & NewTeam;
flow?: Flow;
externalPortalFlow?:Flow;
sessionIds?: string[];
}
9 changes: 4 additions & 5 deletions e2e/tests/ui-driven/src/helpers/userActions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Locator, Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { setupOSMockResponse } from "../mocks/osPlacesResponse";
import type { Context } from "./context";
import { findSessionId, getGraphQLClient } from "./context";
import { TEST_EMAIL, log, waitForDebugLog } from "./globalHelpers";
import exp from "node:constants";
import { TestContext } from "./types";

export async function saveSession({
page,
context,
}: {
page: Page;
context: Context;
context: TestContext;
}): Promise<string | undefined> {
const pageResponsePromise = page.waitForResponse((response) => {
return response.url().includes("/send-email/save");
Expand All @@ -32,7 +31,7 @@ export async function returnToSession({
shouldContinue = true,
}: {
page: Page;
context: Context;
context: TestContext;
sessionId: string;
shouldContinue?: boolean;
}) {
Expand Down Expand Up @@ -82,7 +81,7 @@ export async function fillInEmail({
context,
}: {
page: Page;
context: Context;
context: TestContext;
}) {
await page.locator("#email").fill(context.user.email);
await page.locator("#confirmEmail").fill(context.user.email);
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BrowserContext, Page, expect, test } from "@playwright/test";
import {
Context,
contextDefaults,
getGraphQLClient,
setUpTestContext,
Expand All @@ -20,8 +19,9 @@ import {
navigateToPayComponent,
} from "./helpers";
import { mockPaymentRequest, modifiedInviteToPayFlow } from "./mocks";
import { TestContext } from "../helpers/types";

let context: Context = {
let context: TestContext = {
...contextDefaults,
flow:
{
Expand Down
Loading

0 comments on commit 0e0374e

Please sign in to comment.