From df3acc9c9b12b98a9660ae9ffdd47cb6d16d1174 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Mon, 4 Nov 2024 08:42:34 +0000 Subject: [PATCH] setup cucumber demo tests add new scenarios to feature file revert ui-driven test changes update feature with new tests add step structure and helper --- .../src/demo-workspace/demoUser.feature | 95 +++++++++++++++++++ .../api-driven/src/demo-workspace/helper.ts | 0 .../demo-workspace/steps/background_steps.ts | 22 +++++ .../demo-workspace/steps/navigation_steps.ts | 26 +++++ .../steps/verification_steps.ts | 47 +++++++++ .../src/demo-space/demo-login.spec.ts | 74 --------------- e2e/tests/ui-driven/src/helpers/context.ts | 22 ----- .../ui-driven/src/helpers/globalHelpers.ts | 27 ------ 8 files changed, 190 insertions(+), 123 deletions(-) create mode 100644 e2e/tests/api-driven/src/demo-workspace/demoUser.feature create mode 100644 e2e/tests/api-driven/src/demo-workspace/helper.ts create mode 100644 e2e/tests/api-driven/src/demo-workspace/steps/background_steps.ts create mode 100644 e2e/tests/api-driven/src/demo-workspace/steps/navigation_steps.ts create mode 100644 e2e/tests/api-driven/src/demo-workspace/steps/verification_steps.ts delete mode 100644 e2e/tests/ui-driven/src/demo-space/demo-login.spec.ts diff --git a/e2e/tests/api-driven/src/demo-workspace/demoUser.feature b/e2e/tests/api-driven/src/demo-workspace/demoUser.feature new file mode 100644 index 0000000000..679fd1a845 --- /dev/null +++ b/e2e/tests/api-driven/src/demo-workspace/demoUser.feature @@ -0,0 +1,95 @@ + Feature: Demo user access + + Background: + Given I am a user with a demoUser role + And I have two users in the database: + | id | first_name | last_name | email | + | 1 | Demo | User | demo.user@email.com | + | 2 | Nota | Demo | nota.demo@email.com | + + And I have the following teams in the database: + | id | name | slug | + | 1 | Open Systems Lab | open-systems-lab | + | 29 | Templates | templates | + | 30 | Open Digital Planning | open-digital-planning | + | 32 | Demo | demo | + | 45 | Other Team | other-team | + + And I have the following flows in the database: + | id | creator_id | name | team_id | + | 1 | 1 | Test Flow 1 | 32 | + | 2 | 1 | Test Flow 2 | 32 | + | 3 | 2 | Other Flow | 45 | + +@demo-user-permissions +Scenario: I can only view my own flows + When I am in the Demo team + Then I should only see flows with ids "1, 2" + And I should not see flow with id "3" + + @demo-user-permissions + Scenario Outline: I can only view specific teams + When I am on the Teams page + Then I can only see team with id: "" + + Examples: + | ID | + | 1 | + | 29 | + | 30 | + | 32 | + + @demo-user-permissions + Scenario: Creating a new flow in the Demo team + When I am in the Demo team + Then I should be able to create a flow + + @demo-user-permissions + Scenario Outline: Creating a new flow in other teams + When I am in the "" team + Then I should not be able to create a flow + + Examples: + | TEAM | + | templates | + | open-systems-lab | + | open-digital-planning | + + @demo-user-permissions + Scenario Outline: Actioning my own flows + When I am in the Demo team + And I am on my own flow + Then I should be able to "" the flow + + Examples: + | ACTION | + | update | + | delete | + + @demo-user-permissions + Scenario Outline: Actioning flows in other teams + When I am in the "" team + And I want to edit a flow that I did not create + Then I should not have access to modify the flow + + Examples: + | TEAM | + | templates | + | open-systems-lab | + | open-digital-planning | + + @demo-user-permissions + Scenario: Accessing flow settings + When I am on my own flow + Then I should have access to flow settings + + @demo-user-permissions + Scenario Outline: Editing team settings + When I am in the "" team + Then I should not have access to team settings + + Examples: + | TEAM | + | templates | + | open-systems-lab | + | open-digital-planning | \ No newline at end of file diff --git a/e2e/tests/api-driven/src/demo-workspace/helper.ts b/e2e/tests/api-driven/src/demo-workspace/helper.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/e2e/tests/api-driven/src/demo-workspace/steps/background_steps.ts b/e2e/tests/api-driven/src/demo-workspace/steps/background_steps.ts new file mode 100644 index 0000000000..c199e8eb2a --- /dev/null +++ b/e2e/tests/api-driven/src/demo-workspace/steps/background_steps.ts @@ -0,0 +1,22 @@ +import { Given } from "@cucumber/cucumber"; + +Given('I am a user with a demoUser role', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + Given('I have two users in the database:', async function (dataTable) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + Given('I have the following teams in the database:', async function (dataTable) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + + Given('I have the following flows in the database:', async function (dataTable) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); diff --git a/e2e/tests/api-driven/src/demo-workspace/steps/navigation_steps.ts b/e2e/tests/api-driven/src/demo-workspace/steps/navigation_steps.ts new file mode 100644 index 0000000000..6c967d933e --- /dev/null +++ b/e2e/tests/api-driven/src/demo-workspace/steps/navigation_steps.ts @@ -0,0 +1,26 @@ +import { When } from "@cucumber/cucumber"; + +When('I am on the Teams page', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + +When('I am in the Demo team', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + When('I am in the {string} team', async function (string) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + When('I am on my own flow', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + When('I want to edit a flow that I did not create', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); diff --git a/e2e/tests/api-driven/src/demo-workspace/steps/verification_steps.ts b/e2e/tests/api-driven/src/demo-workspace/steps/verification_steps.ts new file mode 100644 index 0000000000..0e9134c203 --- /dev/null +++ b/e2e/tests/api-driven/src/demo-workspace/steps/verification_steps.ts @@ -0,0 +1,47 @@ +import { Then } from "@cucumber/cucumber"; + +Then('I should be able to create a flow', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + +Then('I should not be able to create a flow', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; +}); + +Then('I should have access to flow settings', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + + Then('I should not have access to team settings', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + Then('I should not have access to modify the flow', async function () { + // Write code here that turns the phrase above into concrete actions + return 'pending'}); + + Then('I should be able to {string} the flow', async function (string) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + Then('I can only see team with id: {string}', async function (string) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + Then('I should only see flows with ids {string}', async function (string) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); + + + Then('I should not see flow with id {string}', async function (string) { + // Write code here that turns the phrase above into concrete actions + return 'pending'; + }); \ No newline at end of file diff --git a/e2e/tests/ui-driven/src/demo-space/demo-login.spec.ts b/e2e/tests/ui-driven/src/demo-space/demo-login.spec.ts deleted file mode 100644 index dbc4333d5e..0000000000 --- a/e2e/tests/ui-driven/src/demo-space/demo-login.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { expect, test } from "@playwright/test"; -import type { Context } from "../helpers/context"; -import { - contextDefaults, - setUpTestContext, - tearDownTestContext, -} from "../helpers/context"; -import { createAuthenticatedSession } from "../helpers/globalHelpers"; - -test.describe("Login", () => { - let context: Context = { - ...contextDefaults, - }; - - test.beforeAll(async () => { - try { - context = await setUpTestContext(context); - } catch (error) { - // ensure proper teardown if setup fails - await tearDownTestContext(context); - throw error; - } - }); - - test.afterAll(async () => { - await tearDownTestContext(context); - }); - - test("setting a cookie bypasses login", async ({ browser }) => { - const page = await createAuthenticatedSession({ - browser, - userId: context.user!.id!, - }); - - await page.goto("/"); - await page.waitForResponse((response) => { - return response.url().includes("/graphql"); - }); - - const team = page.locator("h3", { hasText: context.team.name }); - await expect(team).toBeVisible(); - }); - - test("shows error toast when there is a network error and removes it when a retry is successful", async ({ - browser, - }) => { - const page = await createAuthenticatedSession({ - browser, - userId: context.user!.id!, - }); - await page.goto("/"); - - const teamLink = page.locator("h3").filter({ hasText: context.team.name }); - await teamLink.waitFor(); // wait for this to be visible - - // drop graphql requests - await page.route("**/graphql", (route) => { - route.abort("connectionfailed"); - }); - - await teamLink.click(); - const toastText = "Network error, attempting to reconnect…"; - await expect(page.getByText(toastText)).toBeVisible(); - - // resume graphql requests - await page.route("**/graphql", (route) => { - route.continue(); - }); - await expect( - page.locator("h1").filter({ hasText: "Services" }), - ).toBeVisible(); - await expect(page.getByText(toastText)).toBeHidden(); - }); -}); diff --git a/e2e/tests/ui-driven/src/helpers/context.ts b/e2e/tests/ui-driven/src/helpers/context.ts index 9011cf9277..a68edf78f5 100644 --- a/e2e/tests/ui-driven/src/helpers/context.ts +++ b/e2e/tests/ui-driven/src/helpers/context.ts @@ -46,28 +46,6 @@ export const contextDefaults: Context = { }, }; -export const demoContext: Context = { - user: { - firstName: "Demo", - lastName: "demo", - email: "simulate-delivered@notifications.service.gov.uk", - isPlatformAdmin: false, - }, - team: { - name: "E2E Test Team", - slug: "E2E", - theme: { - logo: "https://raw.githubusercontent.com/theopensystemslab/planx-team-logos/main/planx-testing.svg", - primaryColour: "#444444", - }, - settings: { - homepage: "planx.uk", - submissionEmail: "simulate-delivered@notifications.service.gov.uk", - }, - }, -}; - - export async function setUpTestContext( initialContext: Context, ): Promise { diff --git a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts index fb19baaab3..ff112000dd 100644 --- a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts +++ b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts @@ -69,33 +69,6 @@ export async function createAuthenticatedSession({ return page; } -export async function createAuthenticatedDemoSession({ - browser, - userId, -}: { - browser: Browser; - userId: number; -}): Promise { - const browserContext = await browser.newContext(); - const page = await browserContext.newPage(); - const token = generateAuthenticationDemoToken(`${userId}`); - await browserContext.addCookies([ - { - name: "jwt", - domain: "localhost", - path: "/", - value: token, - }, - { - name: "auth", - domain: "localhost", - path: "/", - value: JSON.stringify({ loggedIn: true }), - }, - ]); - return page; -} - export async function setFeatureFlag(page: Page, featureFlag: string) { await page.addInitScript( (featureFlag: string) =>