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

test(e2e): Add coverage for recent user permission changes #2283

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,66 @@ test.describe("Navigation", () => {
await expect(nodes.getByText(noBranchNoticeText)).toBeVisible();
});

test("user data persists on page refresh @regression", async ({
browser,
}) => {
const page = await createAuthenticatedSession({
browser,
userId: context.user!.id!,
});

let getUserRequestCount = 0;
page.on("request", (req) => {
const isHasuraRequest = req.url().includes("/graphql");
const isGetUserRequest =
isHasuraRequest && req.postData()?.toString().includes("GetUserById");

if (isGetUserRequest) getUserRequestCount++;
});

await page.goto("/");
await page.waitForLoadState("networkidle");

// Get user data on initial page load
expect(getUserRequestCount).toBe(1);

const team = page.locator("h2", { hasText: context.team.name });
team.click();
await page.waitForLoadState("networkidle");

// User data not refetched on navigation to a new page
expect(getUserRequestCount).toBe(1);

// User data is refetched when page reloaded
await page.reload();
await page.waitForLoadState("networkidle");
expect(getUserRequestCount).toBe(2);
});

test("team data persists on page refresh @regression", async ({
browser,
}) => {
const page = await createAuthenticatedSession({
browser,
userId: context.user!.id!,
});

await page.goto("/");
const team = page.locator("h2", { hasText: context.team.name });
await team.click();

const teamSlugInHeader = page.getByRole("link", {
name: context.team.slug,
});
await expect(teamSlugInHeader).toBeVisible();

await page.reload();
await expect(teamSlugInHeader).toBeVisible();

await page.goBack();
await expect(teamSlugInHeader).toBeHidden();
});

test("Preview a created flow", async ({ browser }: { browser: Browser }) => {
const page = await createAuthenticatedSession({
browser,
Expand Down
24 changes: 12 additions & 12 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,6 @@
import { test, expect, Page, BrowserContext } from "@playwright/test";
import { addSessionToContext, modifyFlow } from "../helpers";
import inviteToPayFlow from "../flows/invite-to-pay-flow";
import inviteToPayFlow from "../mocks/flows/invite-to-pay-flow";
import {
Context,
contextDefaults,
Expand Down Expand Up @@ -52,16 +52,16 @@ test.describe("Agent journey @regression", async () => {
});
await expect(toggleInviteToPayButton).toBeVisible();
await toggleInviteToPayButton.click();
const inviteToPayFormHeader = await page.getByText(
const inviteToPayFormHeader = page.getByText(
"Invite someone else to pay for this application",
);
await expect(inviteToPayFormHeader).toBeVisible();

await answerInviteToPayForm(page);
await page.getByRole("button", { name: "Send invitation to pay" }).click();
await page.waitForLoadState("networkidle");
page.getByRole("button", { name: "Send invitation to pay" }).click();
await page.waitForResponse((res) => res.url().includes("invite-to-pay"));

const errorMessage = await page.getByText(
const errorMessage = page.getByText(
"Error generating payment request, please try again",
);
await expect(errorMessage).toBeHidden();
Expand All @@ -73,7 +73,7 @@ test.describe("Agent journey @regression", async () => {
expect(paymentRequest).toBeDefined();
expect(paymentRequest).toMatchObject(mockPaymentRequest);

const successMessage = await page.getByText("Payment invitation sent");
const successMessage = page.getByText("Payment invitation sent");
await expect(successMessage).toBeVisible();
});

Expand Down Expand Up @@ -108,15 +108,15 @@ test.describe("Agent journey @regression", async () => {
const secondPage = await browserContext.newPage();
await secondPage.goto(resumeLink);
await expect(
await secondPage.getByRole("heading", {
secondPage.getByRole("heading", {
name: "Resume your application",
}),
).toBeVisible();
await secondPage.getByLabel("Email address").fill(context.user.email);
await secondPage.getByTestId("continue-button").click();

await expect(
await secondPage.getByRole("heading", {
secondPage.getByRole("heading", {
name: "Sorry, you can't make changes to this application",
}),
).toBeVisible();
Expand All @@ -138,22 +138,22 @@ test.describe("Agent journey @regression", async () => {
const secondPage = await browserContext.newPage();
await secondPage.goto(resumeLink);
await expect(
await secondPage.getByRole("heading", {
secondPage.getByRole("heading", {
name: "Resume your application",
}),
).toBeVisible();
await secondPage.getByLabel("Email address").fill(context.user.email);
await secondPage.getByTestId("continue-button").click();

// Reconciliation ignored
const reconciliationText = await secondPage.getByText(
const reconciliationText = secondPage.getByText(
"This service has been updated since you last saved your application. We will ask you to answer any updated questions again when you continue.",
);
await expect(reconciliationText).toBeHidden();

// Locked application message displayed
await expect(
await secondPage.getByRole("heading", {
secondPage.getByRole("heading", {
name: "Sorry, you can't make changes to this application",
}),
).toBeVisible();
Expand All @@ -180,7 +180,7 @@ test.describe("Agent journey @regression", async () => {
sessionId,
adminGQLClient,
});
await expect(paymentRequest).toBeDefined();
expect(paymentRequest).toBeDefined();

// Attempt to make payment in tab 2...
await tab2.getByText("Pay now using GOV.UK Pay").click();
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/invite-to-pay/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export async function makePaymentRequest({
});
await toggleInviteToPayButton.click();
await answerInviteToPayForm(page);
await page.getByRole("button", { name: "Send invitation to pay" }).click();
await page.waitForLoadState("networkidle");
page.getByRole("button", { name: "Send invitation to pay" }).click();
await page.waitForResponse((res) => res.url().includes("invite-to-pay"));

return sessionId;
}
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/invite-to-pay/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PaymentRequest,
SessionData,
} from "@opensystemslab/planx-core/types";
import inviteToPayFlow from "../flows/invite-to-pay-flow";
import inviteToPayFlow from "../mocks/flows/invite-to-pay-flow";
import { TEST_EMAIL } from "../helpers";

export const mockPaymentRequest: Partial<PaymentRequest> = {
Expand Down
9 changes: 3 additions & 6 deletions e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, Page, APIRequestContext } from "@playwright/test";
import { v4 as uuidV4 } from "uuid";
import { fillGovUkCardDetails, cards } from "../helpers";
import inviteToPayFlow from "../flows/invite-to-pay-flow";
import inviteToPayFlow from "../mocks/flows/invite-to-pay-flow";
import {
Context,
contextDefaults,
Expand Down Expand Up @@ -47,7 +47,7 @@ test.describe("Nominee journey @regression", async () => {
await navigateToPaymentRequestPage(paymentRequest, page);

await expect(
await page.getByRole("heading", { name: "Pay for your application" }),
page.getByRole("heading", { name: "Pay for your application" }),
).toBeVisible();
await expect(
page.locator("#main-content").getByText("Invite to pay test"),
Expand All @@ -58,7 +58,7 @@ test.describe("Nominee journey @regression", async () => {
"Alteration of internal walls and addition or alteration of a deck";
await expect(page.getByText(formattedProjectType)).toBeVisible();

const payButton = await page.getByRole("button", {
const payButton = page.getByRole("button", {
name: "Pay using GOV.UK Pay",
});
await expect(payButton).toBeVisible();
Expand All @@ -71,9 +71,6 @@ test.describe("Nominee journey @regression", async () => {
await page.getByRole("button", { name: "Confirm payment" }).click();
await page.waitForURL("**/invite-to-pay-test/**");

// Wait for GovPay re-request to update paymentRequest status
await page.waitForLoadState("networkidle");

await expect(page.getByText("Payment received")).toBeVisible();
const updatedPaymentRequest = await getPaymentRequestBySessionId({
sessionId,
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/pay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
waitForPaymentResponse,
} from "./helpers";
import type { Page } from "@playwright/test";
import payFlow from "./flows/pay-flow.json";
import payFlow from "./mocks/flows/pay-flow.json";
import { gql, GraphQLClient } from "graphql-request";
import type { SessionData } from "@opensystemslab/planx-core/types";
import type { Context } from "./context";
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/save-and-return.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import {
simpleSendFlow,
modifiedSimpleSendFlow,
} from "./flows/save-and-return-flows";
} from "./mocks/flows/save-and-return-flows";
import {
contextDefaults,
setUpTestContext,
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/sections.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { flow, updatedQuestionAnswers } from "./flows/sections-flow";
import { flow, updatedQuestionAnswers } from "./mocks/flows/sections-flow";
import {
contextDefaults,
setUpTestContext,
Expand Down