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

fix: Failing regression E2E tests #2337

Merged
merged 6 commits into from
Oct 25, 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
5 changes: 4 additions & 1 deletion api.planx.uk/send/uniform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ async function authenticate({
throw Error("Failed to authenticate to Uniform - no access token returned");
}

if (!response.data["organisation-name"] || response.data["organisation-id"]) {
if (
!response.data["organisation-name"] ||
!response.data["organisation-id"]
) {
Comment on lines +228 to +231
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing ! here is my schoolboy error here that caused the latest Uniform submission to fail sorry!

If I can't progress this PR by later today I'll cherry-pick this commit into a new PR to get to prod for re-submission to take place.

throw Error(
"Failed to authenticate to Uniform - no organisation details returned",
);
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@playwright/test": "^1.35.1",
"@playwright/test": "^1.39.0",
"@types/node": "18.16.1",
"eslint-plugin-playwright": "^0.12.0"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const config: PlaywrightTestConfig = {
webServer: {
command: `pnpm ui`,
port: 3000,
reuseExistingServer: false,
reuseExistingServer: !process.env.CI,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to run the React app at localhost:3000 when running Playwright tests and makes for a much better feedback loop than make change → build → re-run tests.

},
/* Configure projects for major browsers */
projects: [
Expand Down
27 changes: 17 additions & 10 deletions e2e/tests/ui-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 56 additions & 56 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,62 +35,6 @@ test.describe("Navigation", () => {
await tearDownTestContext(context);
});

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

page.on("dialog", (dialog) => dialog.accept(serviceProps.name));
await page.locator("button", { hasText: "Add a new service" }).click();

// update context to allow flow to be torn down
context.flow = { ...serviceProps };

await page.locator("li.hanger > a").click();
await page.getByRole("dialog").waitFor();

const questionText = "Is this a test?";
await page.getByPlaceholder("Text").fill(questionText);

await page.locator("button").filter({ hasText: "add new" }).click();
await page.getByPlaceholder("Option").fill("Yes");

await page.locator("button").filter({ hasText: "add new" }).click();
await page.getByPlaceholder("Option").nth(1).fill("No");

await page.locator("button").filter({ hasText: "Create question" }).click();
await expect(
page.locator("a").filter({ hasText: questionText }),
).toBeVisible();

// Add a notice to the "Yes" path
const yesBranch = page.locator("#flow .card .options .option").nth(0);
await yesBranch.locator(".hanger > a").click();
await page.getByRole("dialog").waitFor();

await page.locator("select").selectOption({ label: "Notice" });
const yesBranchNoticeText = "Yes! this is a test";
await page.getByPlaceholder("Notice").fill(yesBranchNoticeText);
await page.locator("button").filter({ hasText: "Create notice" }).click();

// Add a notice to the "No" path
const noBranch = page.locator("#flow .card .options .option").nth(1);
await noBranch.locator(".hanger > a").click();
await page.getByRole("dialog").waitFor();

await page.locator("select").selectOption({ label: "Notice" });
const noBranchNoticeText = "Sorry, this is a test";
await page.getByPlaceholder("Notice").fill(noBranchNoticeText);
await page.locator("button").filter({ hasText: "Create notice" }).click();

const nodes = page.locator(".card");
await expect(nodes.getByText(questionText)).toBeVisible();
await expect(nodes.getByText(yesBranchNoticeText)).toBeVisible();
await expect(nodes.getByText(noBranchNoticeText)).toBeVisible();
});

test("user data persists on page refresh @regression", async ({
browser,
}) => {
Expand Down Expand Up @@ -151,6 +95,62 @@ test.describe("Navigation", () => {
await expect(teamSlugInHeader).toBeHidden();
});

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

page.on("dialog", (dialog) => dialog.accept(serviceProps.name));
await page.locator("button", { hasText: "Add a new service" }).click();

// update context to allow flow to be torn down
context.flow = { ...serviceProps };

await page.locator("li.hanger > a").click();
await page.getByRole("dialog").waitFor();

const questionText = "Is this a test?";
await page.getByPlaceholder("Text").fill(questionText);

await page.locator("button").filter({ hasText: "add new" }).click();
await page.getByPlaceholder("Option").fill("Yes");

await page.locator("button").filter({ hasText: "add new" }).click();
await page.getByPlaceholder("Option").nth(1).fill("No");

await page.locator("button").filter({ hasText: "Create question" }).click();
await expect(
page.locator("a").filter({ hasText: questionText }),
).toBeVisible();

// Add a notice to the "Yes" path
const yesBranch = page.locator("#flow .card .options .option").nth(0);
await yesBranch.locator(".hanger > a").click();
await page.getByRole("dialog").waitFor();

await page.locator("select").selectOption({ label: "Notice" });
const yesBranchNoticeText = "Yes! this is a test";
await page.getByPlaceholder("Notice").fill(yesBranchNoticeText);
await page.locator("button").filter({ hasText: "Create notice" }).click();

// Add a notice to the "No" path
const noBranch = page.locator("#flow .card .options .option").nth(1);
await noBranch.locator(".hanger > a").click();
await page.getByRole("dialog").waitFor();

await page.locator("select").selectOption({ label: "Notice" });
const noBranchNoticeText = "Sorry, this is a test";
await page.getByPlaceholder("Notice").fill(noBranchNoticeText);
await page.locator("button").filter({ hasText: "Create notice" }).click();

const nodes = page.locator(".card");
await expect(nodes.getByText(questionText)).toBeVisible();
await expect(nodes.getByText(yesBranchNoticeText)).toBeVisible();
await expect(nodes.getByText(noBranchNoticeText)).toBeVisible();
});

test("Preview a created flow", async ({ browser }: { browser: Browser }) => {
const page = await createAuthenticatedSession({
browser,
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"scroll-into-view-if-needed": "^2.2.31",
"sharedb": "^3.3.1",
"striptags": "^3.2.0",
"swr": "^2.2.0",
"swr": "^2.2.4",
"tippy.js": "^6.3.7",
"uuid": "^9.0.0",
"wkt": "^0.1.1",
Expand Down
13 changes: 9 additions & 4 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { WarningContainer } from "@planx/components/shared/Preview/WarningContai
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator";
import { useFormik } from "formik";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { useCurrentRoute, useNavigation } from "react-navi";
import { isPreviewOnlyDomain } from "routes/utils";
import useSWRMutation from "swr/mutation";
import { ApplicationPath } from "types";
import ErrorWrapper from "ui/ErrorWrapper";
import Input from "ui/Input";
Expand Down Expand Up @@ -88,6 +87,8 @@ const InviteToPayForm: React.FC<InviteToPayFormProps> = ({
paymentStatus,
}) => {
const [sessionId, path] = useStore((state) => [state.sessionId, state.path]);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(false);
const isSaveReturn = path === ApplicationPath.SaveAndReturn;
const navigation = useNavigation();
const {
Expand All @@ -99,38 +100,39 @@ const InviteToPayForm: React.FC<InviteToPayFormProps> = ({
window.scrollTo(0, 0);
}, []);

const postRequest = async (
url: string,
{ arg }: { arg: CreatePaymentRequest },
) => {
const postRequest = async (createPaymentRequest: CreatePaymentRequest) => {
setIsLoading(true);
const url = `${process.env.REACT_APP_API_URL}/invite-to-pay/${sessionId}`;
const response = await fetch(url, {
method: "POST",
body: JSON.stringify(arg),
body: JSON.stringify(createPaymentRequest),
headers: {
"Content-Type": "application/json",
},
});
setIsLoading(false);
if (!response.ok) {
setError(true);
throw new Error(
`Error generating payment request for session ${sessionId}: ${error}`,
`Error generating payment request for session ${sessionId}: ${response.body}`,
);
}
return response.json();
};

const { trigger, isMutating, error } = useSWRMutation(
`${process.env.REACT_APP_API_URL}/invite-to-pay/${sessionId}`,
postRequest,
);

const onSubmit = async (values: FormValues) => {
const createPaymentRequest: CreatePaymentRequest = {
...values,
sessionPreviewKeys: SESSION_PREVIEW_KEYS,
};
const paymentRequest: PaymentRequest = await trigger(createPaymentRequest);
if (!error && paymentRequest.id)
redirectToConfirmationPage(paymentRequest.id);
try {
const paymentRequest: PaymentRequest = await postRequest(
createPaymentRequest,
);
if (paymentRequest.id) redirectToConfirmationPage(paymentRequest.id);
} catch (error) {
console.error(error);
}
};

const redirectToConfirmationPage = (paymentRequestId: string) => {
Expand All @@ -153,7 +155,7 @@ const InviteToPayForm: React.FC<InviteToPayFormProps> = ({
validationSchema,
});

return isMutating ? (
return isLoading ? (
<DelayedLoadingIndicator />
) : (
<Card>
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/components/DelayedLoadingIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const DelayedLoadingIndicator: React.FC<{
>
<CircularProgress aria-label="Loading" />
<Typography variant="body2" sx={{ ml: "1rem" }}>
{text ?? "Loading"}
{text ?? "Loading..."}
</Typography>
</Root>
) : null;
Expand Down
1 change: 0 additions & 1 deletion editor.planx.uk/src/pages/Pay/MakePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ function computePaymentState(govUkPayment: GovUKPayment | null): PaymentState {
) {
return PaymentState.Pending;
}
// PaymentStatus.cancelled, PaymentStatus.error, PaymentStatus.failed,
return PaymentState.Failed;
}

Expand Down
Loading