Skip to content

Commit

Permalink
refine code and add navigation + publish helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 27, 2024
1 parent 2a87833 commit d890e4d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
45 changes: 8 additions & 37 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
createExternalPortal,
createQuestionWithOptions,
} from "./helpers/addComponent";
import { navigateToService, publishService, turnServiceOnline } from "./helpers/navigateAndPublish";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
Expand Down Expand Up @@ -126,8 +127,7 @@ test.describe("Flow creation, publish and preview", () => {

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();
await publishService(page)

const previewLink = page.getByRole("link", {
name: "Open published service",
Expand Down Expand Up @@ -162,15 +162,7 @@ test.describe("Flow creation, publish and preview", () => {

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

// Open flow settings
page.locator('[aria-label="Service settings"]').click();

// Toggle flow online
page.getByLabel("Offline").click();
page.getByRole("button", { name: "Save", disabled: false }).click();
await expect(
page.getByText("Service settings updated successfully"),
).toBeVisible();
await turnServiceOnline(page)

// Exit back to main Editor page
page.locator('[aria-label="Editor"]').click();
Expand Down Expand Up @@ -200,7 +192,7 @@ test.describe("Flow creation, publish and preview", () => {
);
await editor.addNewService();

// update context to allow flow to be torn down
// update context to allow new flow to be torn down
context.flows?.push({ ...externalPortalServiceProps });

await createQuestionWithOptions(
Expand All @@ -215,39 +207,18 @@ test.describe("Flow creation, publish and preview", () => {
externalPortalFlowData.answers[1],
]);

page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
await expect(
page.getByRole("heading", { name: "Check for changes to publish" }),
).toBeVisible();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();

// Open flow settings
page.locator('[aria-label="Service settings"]').click();

// Toggle flow online
page.getByLabel("Offline").click();
page.getByRole("button", { name: "Save", disabled: false }).click();
await expect(
page.getByText("Service settings updated successfully"),
).toBeVisible();

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);
await publishService(page)
await turnServiceOnline(page)

await expect(
page.getByRole("link", { name: serviceProps.slug }),
).toBeVisible();
navigateToService(page, serviceProps.slug)

await createExternalPortal(page, page.locator("li:nth-child(6)"));

await expect(
page.getByRole("link", { name: "E2E/an-external-portal-service" }),
).toBeVisible();

page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
await expect(
page.getByRole("heading", { name: "Check for changes to publish" }),
).toBeVisible();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();
await publishService(page)
});

test("Can preview a published flow", async ({
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/helpers/addComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const createBaseComponent = async (
await page.getByPlaceholder("Notice").fill(title || "");
break;
case ComponentType.Checklist:
await page.getByPlaceholder("Text").fill(title || "text");
await page.getByPlaceholder("Text").fill(title || "");
if (options) {
await createComponentOptions(options, "add new option", page);
}
Expand Down
16 changes: 8 additions & 8 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ export async function setUpTestContext(
}
if (
context.flows &&
context.flows![0].slug &&
context.flows![0].data &&
context.flows![0].name &&
context.flows[0].slug &&
context.flows[0].data &&
context.flows[0].name &&
context.team?.id &&
context.user?.id
) {
context.flows![0].id = await $admin.flow.create({
slug: context.flows![0].slug,
name: context.flows![0].name,
slug: context.flows[0].slug,
name: context.flows[0].name,
teamId: context.team.id,
data: context.flows![0]!.data!,
data: context.flows[0].data,
status: "online",
});
context.flows![0].publishedId = await $admin.flow.publish({
flow: {
id: context.flows![0].id,
data: context.flows![0]!.data!,
id: context.flows[0].id,
data: context.flows[0].data,
},
publisherId: context.user!.id!,
});
Expand Down
31 changes: 31 additions & 0 deletions e2e/tests/ui-driven/src/helpers/navigateAndPublish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, Page } from "@playwright/test";
import { contextDefaults } from "./context";

export const navigateToService = async (page: Page, slug:string) => {

await page.goto(`/${contextDefaults.team.slug}/${slug}`);

await expect(
page.getByRole("link", { name: slug }),
).toBeVisible();

return true
}

export const publishService = async (page:Page) => {
page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
await expect(
page.getByRole("heading", { name: "Check for changes to publish" }),
).toBeVisible();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();
}

export const turnServiceOnline = async (page: Page) =>{
page.locator('[aria-label="Service settings"]').click();
page.getByLabel("Offline").click();

page.getByRole("button", { name: "Save", disabled: false }).click();
await expect(
page.getByText("Service settings updated successfully"),
).toBeVisible();
}

0 comments on commit d890e4d

Please sign in to comment.