Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production deploy #3733

Merged
merged 10 commits into from
Sep 26, 2024
112 changes: 112 additions & 0 deletions e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { expect, test } from "@playwright/test";
import type { Context } from "./helpers/context";
import {
contextDefaults,
setUpTestContext,
tearDownTestContext,
} from "./helpers/context";
import { getTeamPage } from "./helpers/getPage";
import { createAuthenticatedSession } from "./helpers/globalHelpers";
import { answerFindProperty, clickContinue } from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";

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

test.beforeAll(async () => {
try {
context = await setUpTestContext(context);
} catch (error) {
await tearDownTestContext(context);
throw error;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
});

test("Create a flow", async ({ browser }) => {
const page = await getTeamPage({
browser,
userId: context.user!.id!,
teamName: context.team.name,
});

const editor = new PlaywrightEditor(page);

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 editor.createUploadAndLabel();
// TODO: editor.createPropertyInfo()
await editor.createDrawBoundary();
await editor.createPlanningConstraints();
// await editor.createFileUpload();

await expect(editor.nodeList).toContainText([
"Find property",
"Upload and label",
"Confirm your location plan",
"Planning constraints",
// "File upload",
]);
});

test("Publish and preview flow with geospatial components", async ({
browser,
}) => {
const page = await createAuthenticatedSession({
browser,
userId: context.user!.id!,
});
// 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();

let previewLink = page.getByRole("link", {
name: "Open published service",
});
await expect(previewLink).toBeVisible();

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();

// Exit back to main Editor page
page.locator('[aria-label="Editor"]').click();
previewLink = page.getByRole("link", {
name: "Open published service",
});
await expect(previewLink).toBeVisible();

// view published flow
await page.goto(
`/${context.team.slug}/${serviceProps.slug}/published?analytics=false`,
);
await expect(
page.locator("h1", { hasText: "Find the property" }),
).toBeVisible();
await answerFindProperty(page);
await clickContinue({ page });
// TODO: answer uploadAndLabel
// TODO: answerPropertyInfo, answerDrawBoundary, answerPlanningConstraints
});
});
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { Browser, expect, test } from "@playwright/test";
import type { Context } from "../helpers/context";
import type { Context } from "./helpers/context";
import {
contextDefaults,
setUpTestContext,
tearDownTestContext,
} from "../helpers/context";
import { getTeamPage } from "../helpers/getPage";
import { createAuthenticatedSession } from "../helpers/globalHelpers";
} from "./helpers/context";
import { getTeamPage } from "./helpers/getPage";
import { createAuthenticatedSession } from "./helpers/globalHelpers";
import {
answerAddressInput,
answerChecklist,
answerContactInput,
answerDateInput,
answerFindProperty,
answerListInput,
answerNumberInput,
answerQuestion,
answerTextInput,
clickContinue,
} from "../helpers/userActions";
import { PlaywrightEditor } from "../pages/Editor";
} from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
Expand Down Expand Up @@ -60,37 +59,37 @@ test.describe("Flow creation, publish and preview", () => {

await editor.createQuestion();
await editor.createNoticeOnEachBranch();
await editor.createChecklist();
// await editor.createChecklist();
await editor.createTextInput();
await editor.createNumberInput();
await editor.createDateInput();
await editor.createAddressInput();
await editor.createContactInput();
await editor.createList();
await editor.createTaskList();
await editor.createFindProperty();
await editor.createDrawBoundary();
await editor.createPlanningConstraints();
await editor.createFileUpload();
await editor.createContent();
await editor.createResult();
await editor.createNextSteps();
await editor.createReview();
await editor.createConfirmation();

await expect(editor.nodeList).toContainText([
"Is this a test?",
"Yes! this is a test",
"Sorry, this is a test",
"Checklist item 1",
// "Checklist item 1",
"Tell us about your trees.",
"How old are you?",
"When is your birthday?",
"What is your address?",
"What is your contact info?",
"A list title",
"What you should do next",
"Find property",
"Confirm your location plan",
"Planning constraints",
"File upload",
"Some content",
"Planning permission", // default result flag
"Next steps",
"Check your answers before sending your application",
"Confirmation",
]);
});

Expand Down Expand Up @@ -203,12 +202,12 @@ test.describe("Flow creation, publish and preview", () => {
).toBeVisible();
await clickContinue({ page });

await answerChecklist({
page,
title: "A checklist title",
answers: ["Checklist item 1", "Second checklist item"],
});
await clickContinue({ page });
// await answerChecklist({
// page,
// title: "A checklist title",
// answers: ["Checklist item 1", "Second checklist item"],
// });
// await clickContinue({ page });

await answerTextInput(page, {
expectedQuestion: "Tell us about your trees.",
Expand Down Expand Up @@ -249,6 +248,14 @@ test.describe("Flow creation, publish and preview", () => {
});
await clickContinue({ page });

await answerListInput(page, {
unitType: "House",
tenure: "Market housing",
numBedrooms: 4,
numUnits: 3,
continueToNext: true,
});

await expect(
page.locator("h1", { hasText: "What you should do next" }),
).toBeVisible();
Expand All @@ -260,10 +267,29 @@ test.describe("Flow creation, publish and preview", () => {
).toBeVisible();
await clickContinue({ page });

await expect(page.locator("p", { hasText: "Some content" })).toBeVisible();
await clickContinue({ page });

await expect(page.locator("h1", { hasText: "No result" })).toBeVisible();
await clickContinue({ page });

await expect(
page.locator("h1", { hasText: "What would you like to do next?" }),
).toBeVisible();
const nextStepButton = page.getByRole("button", {
name: "A possible next step",
});
nextStepButton.click();

await expect(
page.locator("h1", { hasText: "Find the property" }),
page.locator("h1", {
hasText: "Check your answers before sending your application",
}),
).toBeVisible();
await answerFindProperty(page);
await clickContinue({ page });

await expect(
page.locator("h1", { hasText: "Application sent" }),
).toBeVisible();
});
});
70 changes: 70 additions & 0 deletions e2e/tests/ui-driven/src/helpers/addComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const createBaseComponent = async (
case ComponentType.TextInput:
await page.getByPlaceholder("Title").fill(title || "");
break;

case ComponentType.NumberInput:
await page.getByPlaceholder("Title").fill(title || "");
await page.getByPlaceholder("eg square metres").fill(options?.[0] || "");
Expand Down Expand Up @@ -79,6 +80,10 @@ const createBaseComponent = async (
break;
case ComponentType.DrawBoundary:
break;
case ComponentType.Result:
break;
case ComponentType.Confirmation:
break;
case ComponentType.NextSteps:
if (options) {
let index = 0;
Expand All @@ -94,6 +99,19 @@ const createBaseComponent = async (
break;
case ComponentType.FileUpload:
await page.getByPlaceholder("Data Field").fill(options?.[0] || "");
break;
case ComponentType.FileUploadAndLabel:
await page.getByPlaceholder("File type").fill(options?.[0] || "");
await page.getByPlaceholder("Data Field").fill(options?.[1] || "");
break;
case ComponentType.List:
await page.getByPlaceholder("Title").fill(title || "");
await page.getByPlaceholder("Data Field").fill(options?.[0] || "");
break;
case ComponentType.Content:
await page
.locator("p[data-placeholder='Content']")
.fill(options?.[0] || "");

break;
default:
Expand Down Expand Up @@ -295,3 +313,55 @@ async function createComponentOptions(
index++;
}
}

export const createList = async (
page: Page,
locatingNode: Locator,
inputTitle: string,
inputDataField: string,
) => {
await createBaseComponent(
page,
locatingNode,
ComponentType.List,
inputTitle,
[inputDataField],
);
};

export const createResult = async (page: Page, locatingNode: Locator) => {
await createBaseComponent(page, locatingNode, ComponentType.Result);
};

export const createConfirmation = async (page: Page, locatingNode: Locator) => {
await createBaseComponent(page, locatingNode, ComponentType.Confirmation);
};

export const createUploadAndLabel = async (
page: Page,
locatingNode: Locator,
fileType: string,
dataField: string,
) => {
await createBaseComponent(
page,
locatingNode,
ComponentType.FileUploadAndLabel,
undefined,
[fileType, dataField],
);
};

export const createContent = async (
page: Page,
locatingNode: Locator,
content: string,
) => {
await createBaseComponent(
page,
locatingNode,
ComponentType.Content,
undefined,
[content],
);
};
Loading
Loading