Skip to content

Commit

Permalink
Refactor continue and expectedQuestion into helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion committed Sep 17, 2024
1 parent 0aadb8b commit 6a992f9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
45 changes: 23 additions & 22 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,37 +202,41 @@ test.describe("Flow creation, publish and preview", () => {
page.locator("h1", { hasText: "Sorry, this is a test" }),
).toBeVisible();
await clickContinue({ page });

await answerChecklist({
page,
title: "A checklist title",
answers: ["Checklist item 1", "Second checklist item"],
});
await clickContinue({ page });
await expect(
page.locator("p", { hasText: "Tell us about your trees." }),
).toBeVisible();
await answerTextInput(page, { answer: "My trees are lovely" });
await clickContinue({ page });
await expect(
page.locator("p", { hasText: "How old are you?" }),
).toBeVisible();
await answerNumberInput(page, { answer: 30 });
await clickContinue({ page });
await expect(
page.locator("h1", { hasText: "When is your birthday?" }),
).toBeVisible();
await answerDateInput(page, { day: 30, month: 12, year: 1980 });
await clickContinue({ page });

await expect(
page.locator("h1", { hasText: "What is your address?" }),
).toBeVisible();
await answerTextInput(page, {
expectedQuestion: "Tell us about your trees.",
answer: "My trees are lovely",
continueToNext: true,
});

await answerNumberInput(page, {
expectedQuestion: "How old are you?",
answer: 30,
continueToNext: true,
});

await answerDateInput(page, {
expectedQuestion: "When is your birthday?",
day: 30,
month: 12,
year: 1980,
continueToNext: true,
});

await answerAddressInput(page, {
expectedQuestion: "What is your address?",
addressLineOne: "1 Silver Street",
town: "Bamburgh",
postcode: "BG1 2SS",
continueToNext: true,
});
await clickContinue({ page });

await expect(
page.locator("h1", { hasText: "What is your contact info?" }),
Expand All @@ -256,9 +260,6 @@ test.describe("Flow creation, publish and preview", () => {
).toBeVisible();
await clickContinue({ page });

await expect(
page.locator("h1", { hasText: "Find the property" }),
).toBeVisible();
await answerFindProperty(page);
await clickContinue({ page });
});
Expand Down
40 changes: 40 additions & 0 deletions e2e/tests/ui-driven/src/helpers/userActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export async function submitCardDetails(page: Page) {

export async function answerFindProperty(page: Page) {
await setupOSMockResponse(page);
await expect(
page.locator("h1", { hasText: "Find the property" }),
).toBeVisible();
await page.getByLabel("Postcode").fill("SW1 1AA");
await page.getByLabel("Select an address").click();
await page.getByRole("option").first().click();
Expand Down Expand Up @@ -236,55 +239,92 @@ export async function answerContactInput(
export async function answerTextInput(
page: Page,
{
expectedQuestion,
answer,
continueToNext,
}: {
expectedQuestion: string;
answer: string;
continueToNext: boolean;
},
) {
await expect(page.locator("p", { hasText: expectedQuestion })).toBeVisible();
await page.locator("label div input[type='text']").fill(answer);
if (continueToNext) {
await clickContinue({ page });
}
}

export async function answerNumberInput(
page: Page,
{
expectedQuestion,
answer,
continueToNext,
}: {
expectedQuestion: string;
answer: number;
continueToNext: boolean;
},
) {
await expect(page.locator("p", { hasText: expectedQuestion })).toBeVisible();
await page.locator("label div input[type='number']").fill(answer.toString());
if (continueToNext) {
await clickContinue({ page });
}
}

export async function answerDateInput(
page: Page,
{
expectedQuestion,

day,
month,
year,
continueToNext,
}: {
expectedQuestion: string;

day: number;
month: number;
year: number;
continueToNext: boolean;
},
) {
await expect(page.locator("h1", { hasText: expectedQuestion })).toBeVisible();
await page.getByLabel("Day").fill(day.toString());
await page.getByLabel("Month").fill(month.toString());
await page.getByLabel("Year").fill(year.toString());

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

export async function answerAddressInput(
page: Page,
{
expectedQuestion,

addressLineOne,
town,
postcode,
continueToNext,
}: {
expectedQuestion: string;

addressLineOne: string;
town: string;
postcode: string;
continueToNext: boolean;
},
) {
await expect(page.locator("h1", { hasText: expectedQuestion })).toBeVisible();
await page.getByLabel("Address line 1").fill(addressLineOne);
await page.getByLabel("Town").fill(town);
await page.getByLabel("Postcode").fill(postcode);
if (continueToNext) {
await clickContinue({ page });
}
}

0 comments on commit 6a992f9

Please sign in to comment.