Skip to content

Commit

Permalink
add property.type to geospatial
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Dec 3, 2024
1 parent 110a373 commit b12147b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
25 changes: 23 additions & 2 deletions e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
} from "./helpers/context";
import { getTeamPage } from "./helpers/getPage";
import { createAuthenticatedSession } from "./helpers/globalHelpers";
import { answerFindProperty, clickContinue } from "./helpers/userActions";
import {
answerFindProperty,
answerQuestion,
clickContinue,
} from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";
import {
navigateToService,
Expand All @@ -17,6 +21,7 @@ import { TestContext } from "./helpers/types";
import { serviceProps } from "./helpers/serviceData";
import { mockMapGeoJson } from "./mocks/geoJsonMock";
import { checkGeoJsonContent } from "./helpers/geospatialChecks";
import { mockPropertyTypeOptions } from "./mocks/serviceComponentMocks";

test.describe("Flow creation, publish and preview", () => {
let context: TestContext = {
Expand Down Expand Up @@ -50,6 +55,14 @@ test.describe("Flow creation, publish and preview", () => {

await editor.createFindProperty();
await expect(editor.nodeList).toContainText(["Find property"]);
// Find property will automate past this question at first
await editor.createQuestionWithDataFieldOptions(
"Assign property type",
mockPropertyTypeOptions,
"property.type",
);
await expect(editor.nodeList).toContainText(["Assign property type"]);
// but property info "change" button will navigate back to it
await editor.createPropertyInformation();
await expect(editor.nodeList).toContainText(["About the property"]);
await editor.createInternalPortal();
Expand Down Expand Up @@ -103,6 +116,7 @@ test.describe("Flow creation, publish and preview", () => {
await page.goto(
`/${context.team.slug}/${serviceProps.slug}/published?analytics=false`,
);

await expect(
page.locator("h1", { hasText: "Find the property" }),
).toBeVisible();
Expand All @@ -125,7 +139,14 @@ test.describe("Flow creation, publish and preview", () => {

await changeButton.click();

await expect(page.getByText("Unknown")).toBeVisible();
// change button navigates the user back thro the service so we need to continue twice
await answerQuestion({
page: page,
title: "Assign property type",
answer: "Commercial",
});

await clickContinue({ page });
await clickContinue({ page });

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

const createBaseComponent = async (
page: Page,
Expand Down Expand Up @@ -156,6 +157,21 @@ export const createQuestionWithOptions = async (
);
};

export const createQuestionWithDataFieldOptions = async (
page: Page,
locatingNode: Locator,
questionText: string,
options: OptionWithDataValues[],
dataField: string,
) => {
await locatingNode.click();
await page.getByRole("dialog").waitFor();
await page.getByPlaceholder("Text").fill(questionText);
await page.getByPlaceholder("Data Field").fill(dataField);
await createComponentOptionsWithDataValues(page, options);
await page.locator('button[form="modal"][type="submit"]').click();
};

export const createNotice = async (
page: Page,
locatingNode: Locator,
Expand Down Expand Up @@ -345,6 +361,19 @@ async function createComponentOptions(
}
}

async function createComponentOptionsWithDataValues(
page: Page,
options: OptionWithDataValues[],
) {
let index = 0;
for (const option of options) {
await page.locator("button").filter({ hasText: "add new" }).click();
await page.getByPlaceholder("Option").nth(index).fill(option.optionText);
await page.getByPlaceholder("Data Value").nth(index).fill(option.dataValue);
index++;
}
}

export const createList = async (
page: Page,
locatingNode: Locator,
Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/ui-driven/src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export interface TestContext {
externalPortalFlow?: Flow;
sessionIds?: string[];
}

export type OptionWithDataValues = { optionText: string; dataValue: string };
6 changes: 6 additions & 0 deletions e2e/tests/ui-driven/src/mocks/serviceComponentMocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { OptionWithDataValues } from "../helpers/types";

export const mockPropertyTypeOptions: OptionWithDataValues[] = [
{ optionText: "Residential", dataValue: "residential" },
{ optionText: "Commercial", dataValue: "commercial" },
];
19 changes: 19 additions & 0 deletions e2e/tests/ui-driven/src/pages/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import {
createNumberInput,
createPlanningConstraints,
createPropertyInformation,
createQuestionWithDataFieldOptions,
createQuestionWithOptions,
createResult,
createReview,
createTaskList,
createTextInput,
createUploadAndLabel,
} from "../helpers/addComponent";
import { OptionWithDataValues } from "../helpers/types";

export class PlaywrightEditor {
readonly page: Page;
Expand Down Expand Up @@ -82,6 +84,23 @@ export class PlaywrightEditor {
).toBeVisible();
}

async createQuestionWithDataFieldOptions(
title: string,
answers: OptionWithDataValues[],
dataField: string,
) {
await createQuestionWithDataFieldOptions(
this.page,
this.getNextNode(),
title,
answers,
dataField,
);
await expect(
this.page.locator("a").filter({ hasText: title }),
).toBeVisible();
}

async createNoticeOnEachBranch() {
// Add a notice to the "Yes" path
await createNotice(
Expand Down

0 comments on commit b12147b

Please sign in to comment.