From 4645603474885697963d4a21227f1f08d897a8c9 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Mon, 2 Dec 2024 15:59:30 +0000 Subject: [PATCH 1/7] add in Filter component to tests and check for flags --- e2e/tests/ui-driven/src/create-flow.spec.ts | 7 ++++--- e2e/tests/ui-driven/src/helpers/addComponent.ts | 1 + e2e/tests/ui-driven/src/helpers/globalHelpers.ts | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index f681ad01de..1774704a6b 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -5,7 +5,7 @@ import { tearDownTestContext, } from "./helpers/context"; import { getTeamPage } from "./helpers/getPage"; -import { createAuthenticatedSession } from "./helpers/globalHelpers"; +import { createAuthenticatedSession, planningPermissionFlags } from "./helpers/globalHelpers"; import { answerAddressInput, answerChecklist, @@ -79,7 +79,7 @@ test.describe("Flow creation, publish and preview", () => { await editor.createList(); await editor.createTaskList(); await editor.createContent(); - + await editor.createFilter(); await editor.createResult(); await editor.createNextSteps(); await editor.createReview(); @@ -99,6 +99,7 @@ test.describe("Flow creation, publish and preview", () => { "A list title", "What you should do next", "Some content", + ...planningPermissionFlags, "Planning permission", // default result flag "Next steps", "Check your answers before sending your application", @@ -216,7 +217,7 @@ test.describe("Flow creation, publish and preview", () => { await navigateToService(page, serviceProps.slug); // Add our ext portal to the middle of the service - await createExternalPortal(page, page.locator("li:nth-child(6)")); + await createExternalPortal(page, page.locator("li:nth-child(6)").first()); await expect( page.getByRole("link", { name: "E2E/an-external-portal-service" }), diff --git a/e2e/tests/ui-driven/src/helpers/addComponent.ts b/e2e/tests/ui-driven/src/helpers/addComponent.ts index d6d523b0fa..bced771a1d 100644 --- a/e2e/tests/ui-driven/src/helpers/addComponent.ts +++ b/e2e/tests/ui-driven/src/helpers/addComponent.ts @@ -123,6 +123,7 @@ const createBaseComponent = async ( .fill(options?.[0] || ""); break; case ComponentType.Filter: + break; case ComponentType.Feedback: break; case ComponentType.InternalPortal: diff --git a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts index f580449673..55236be4ed 100644 --- a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts +++ b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts @@ -1,8 +1,9 @@ import { FlowGraph } from "@opensystemslab/planx-core/types"; -import type { Browser, Page, Request } from "@playwright/test"; +import { type Browser, type Page, type Request } from "@playwright/test"; import { gql } from "graphql-request"; import { generateAuthenticationToken, getGraphQLClient } from "./context"; import { TestContext } from "./types"; +import { flatFlags } from "@opensystemslab/planx-core/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 @@ -80,6 +81,8 @@ export async function setFeatureFlag(page: Page, featureFlag: string) { ); } +export const planningPermissionFlags = flatFlags.filter((flag) => flag.category === "Planning permission").map((flag) => flag.text) + 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); From 010d810ed3710a116cb54e18760536b6be9aa8ad Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 13:09:05 +0000 Subject: [PATCH 2/7] switch filter and check for automations --- e2e/tests/ui-driven/src/create-flow.spec.ts | 16 +++++++++++++-- .../ui-driven/src/helpers/addComponent.ts | 20 +++++++++++++++++++ .../ui-driven/src/helpers/globalHelpers.ts | 5 ++++- e2e/tests/ui-driven/src/pages/Editor.ts | 12 +++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index 1774704a6b..6fcfc002c7 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -5,7 +5,11 @@ import { tearDownTestContext, } from "./helpers/context"; import { getTeamPage } from "./helpers/getPage"; -import { createAuthenticatedSession, planningPermissionFlags } from "./helpers/globalHelpers"; +import { + createAuthenticatedSession, + filterFlags, + selectedFlag, +} from "./helpers/globalHelpers"; import { answerAddressInput, answerChecklist, @@ -99,7 +103,7 @@ test.describe("Flow creation, publish and preview", () => { "A list title", "What you should do next", "Some content", - ...planningPermissionFlags, + ...filterFlags, "Planning permission", // default result flag "Next steps", "Check your answers before sending your application", @@ -337,6 +341,14 @@ test.describe("Flow creation, publish and preview", () => { await expect(page.locator("p", { hasText: "Some content" })).toBeVisible(); await clickContinue({ page }); + // this is the content placed in the permission needed branch + await expect( + page.locator("p", { + hasText: `This is the ${selectedFlag.toLowerCase()} filter`, + }), + ).toBeVisible(); + await clickContinue({ page }); + await expect(page.locator("h1", { hasText: "No result" })).toBeVisible(); await clickContinue({ page }); diff --git a/e2e/tests/ui-driven/src/helpers/addComponent.ts b/e2e/tests/ui-driven/src/helpers/addComponent.ts index bced771a1d..09e2cd95ad 100644 --- a/e2e/tests/ui-driven/src/helpers/addComponent.ts +++ b/e2e/tests/ui-driven/src/helpers/addComponent.ts @@ -3,6 +3,7 @@ import { expect, Locator, Page } from "@playwright/test"; import { contextDefaults } from "./context"; import { externalPortalServiceProps } from "./serviceData"; import { OptionWithDataValues } from "./types"; +import { selectedFlag } from "./globalHelpers"; const createBaseComponent = async ( page: Page, @@ -123,6 +124,9 @@ const createBaseComponent = async ( .fill(options?.[0] || ""); break; case ComponentType.Filter: + await page + .getByTestId("flagset-category-select") + .selectOption(selectedFlag); break; case ComponentType.Feedback: break; @@ -360,6 +364,22 @@ async function createComponentOptions( await page.getByPlaceholder("Option").nth(index).fill(option); index++; } + + await page.getByPlaceholder("Flags (up to one per category)").nth(1).click(); + await page.getByRole("option", { name: selectedFlag, exact: true }).click(); +} + +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++; + } } async function createComponentOptionsWithDataValues( diff --git a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts index 55236be4ed..ec39631eae 100644 --- a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts +++ b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts @@ -81,7 +81,10 @@ export async function setFeatureFlag(page: Page, featureFlag: string) { ); } -export const planningPermissionFlags = flatFlags.filter((flag) => flag.category === "Planning permission").map((flag) => flag.text) +export const selectedFlag = "Material change of use"; +export const filterFlags = flatFlags + .filter((flag) => flag.category === selectedFlag) + .map((flag) => flag.text); export async function getSessionId(page: Page): Promise { // @ts-expect-error - Property api does not exist on type Window & typeof globalThis diff --git a/e2e/tests/ui-driven/src/pages/Editor.ts b/e2e/tests/ui-driven/src/pages/Editor.ts index 0439cd71ce..6d248df024 100644 --- a/e2e/tests/ui-driven/src/pages/Editor.ts +++ b/e2e/tests/ui-driven/src/pages/Editor.ts @@ -30,6 +30,7 @@ import { createUploadAndLabel, } from "../helpers/addComponent"; import { OptionWithDataValues } from "../helpers/types"; +import { selectedFlag } from "../helpers/globalHelpers"; export class PlaywrightEditor { readonly page: Page; @@ -246,6 +247,17 @@ export class PlaywrightEditor { async createFilter() { await createFilter(this.page, this.getNextNode()); + // select the branch filter and add some content + const permissionNeededNode = this.page + .locator("li") + .filter({ hasText: /Material change of use$/ }) + .getByRole("listitem") + .getByRole("link"); + await createContent( + this.page, + permissionNeededNode, + `This is the ${selectedFlag.toLowerCase()} filter`, + ); } async createInternalPortal() { From 2100b560708ebb523810dec053af70b3efcf63d8 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 13:09:30 +0000 Subject: [PATCH 3/7] comment refinement --- e2e/tests/ui-driven/src/create-flow.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index 6fcfc002c7..ad246d5ab9 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -341,7 +341,7 @@ test.describe("Flow creation, publish and preview", () => { await expect(page.locator("p", { hasText: "Some content" })).toBeVisible(); await clickContinue({ page }); - // this is the content placed in the permission needed branch + // this is the content placed in the filtered branch await expect( page.locator("p", { hasText: `This is the ${selectedFlag.toLowerCase()} filter`, From 3c18332a697ff1bf75c3840d8df12cdf3f6651a5 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 13:17:51 +0000 Subject: [PATCH 4/7] revert ext portal change --- e2e/tests/ui-driven/src/create-flow.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index ad246d5ab9..07cef65624 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -221,7 +221,7 @@ test.describe("Flow creation, publish and preview", () => { await navigateToService(page, serviceProps.slug); // Add our ext portal to the middle of the service - await createExternalPortal(page, page.locator("li:nth-child(6)").first()); + await createExternalPortal(page, page.locator("li:nth-child(6)")); await expect( page.getByRole("link", { name: "E2E/an-external-portal-service" }), From 730f95dbbc8c26c7b39878d59f246fbe9dbf5aec Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 13:20:57 +0000 Subject: [PATCH 5/7] refine content text --- e2e/tests/ui-driven/src/create-flow.spec.ts | 2 +- e2e/tests/ui-driven/src/pages/Editor.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index 07cef65624..921e2a54a9 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -344,7 +344,7 @@ test.describe("Flow creation, publish and preview", () => { // this is the content placed in the filtered branch await expect( page.locator("p", { - hasText: `This is the ${selectedFlag.toLowerCase()} filter`, + hasText: `This is the ${selectedFlag} filter`, }), ).toBeVisible(); await clickContinue({ page }); diff --git a/e2e/tests/ui-driven/src/pages/Editor.ts b/e2e/tests/ui-driven/src/pages/Editor.ts index 6d248df024..95d7b7a66c 100644 --- a/e2e/tests/ui-driven/src/pages/Editor.ts +++ b/e2e/tests/ui-driven/src/pages/Editor.ts @@ -256,7 +256,7 @@ export class PlaywrightEditor { await createContent( this.page, permissionNeededNode, - `This is the ${selectedFlag.toLowerCase()} filter`, + `This is the ${selectedFlag} filter`, ); } From 26fab545d8cce5c701c8d4b41748556175274af1 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 16:12:36 +0000 Subject: [PATCH 6/7] revert filter tests written in geospatial --- e2e/tests/ui-driven/src/pages/Editor.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/e2e/tests/ui-driven/src/pages/Editor.ts b/e2e/tests/ui-driven/src/pages/Editor.ts index 95d7b7a66c..779304e23d 100644 --- a/e2e/tests/ui-driven/src/pages/Editor.ts +++ b/e2e/tests/ui-driven/src/pages/Editor.ts @@ -248,14 +248,15 @@ export class PlaywrightEditor { async createFilter() { await createFilter(this.page, this.getNextNode()); // select the branch filter and add some content - const permissionNeededNode = this.page + const filteredBranch = this.page .locator("li") .filter({ hasText: /Material change of use$/ }) .getByRole("listitem") .getByRole("link"); + await createContent( this.page, - permissionNeededNode, + filteredBranch, `This is the ${selectedFlag} filter`, ); } From 3e9cd6e300be9ff9e9f84cdd59f5c7343a2475b5 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 3 Dec 2024 19:06:18 +0000 Subject: [PATCH 7/7] revert duplicate fn --- e2e/tests/ui-driven/src/helpers/addComponent.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/e2e/tests/ui-driven/src/helpers/addComponent.ts b/e2e/tests/ui-driven/src/helpers/addComponent.ts index 09e2cd95ad..0ad8f252d1 100644 --- a/e2e/tests/ui-driven/src/helpers/addComponent.ts +++ b/e2e/tests/ui-driven/src/helpers/addComponent.ts @@ -364,7 +364,7 @@ async function createComponentOptions( await page.getByPlaceholder("Option").nth(index).fill(option); index++; } - + await page.getByPlaceholder("Flags (up to one per category)").nth(1).click(); await page.getByRole("option", { name: selectedFlag, exact: true }).click(); } @@ -382,19 +382,6 @@ async function createComponentOptionsWithDataValues( } } -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,