Skip to content

Commit 8595286

Browse files
committed
test(web-host): check history kept while navigating + wand button
1 parent d08953e commit 8595286

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

packages/web-host/tests/navigation.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, test } from "@playwright/test";
2+
import { clickWandButton } from "./utils";
23

34
test("start REPL link", async ({ page }) => {
45
await page.goto("/");
@@ -51,3 +52,31 @@ test("back button", async ({ page }) => {
5152
}),
5253
).toBeVisible();
5354
});
55+
56+
test("history should be preserved + wand button", async ({ page }) => {
57+
await page.goto("/");
58+
await page
59+
.getByRole("button", { name: "✨ Start REPL ✨" })
60+
.click({ force: true });
61+
await expect(page).toHaveURL(
62+
"/webassembly-component-model-experiments/#repl",
63+
);
64+
await clickWandButton(page, "echo foo", { expectStdout: "foo" });
65+
await clickWandButton(page, "echo bar", { expectStdout: "bar" });
66+
await clickWandButton(page, "echo baz", { expectStdout: "baz" });
67+
await page.goBack();
68+
await expect(
69+
page.getByRole("heading", {
70+
name: "WebAssembly Component Model Experiments",
71+
}),
72+
).toBeVisible();
73+
await page
74+
.getByRole("button", { name: "✨ Start REPL ✨" })
75+
.click({ force: true });
76+
await expect(page).toHaveURL(
77+
"/webassembly-component-model-experiments/#repl",
78+
);
79+
await expect(
80+
page.getByText("echo foofooecho barbarecho bazbaz"),
81+
).toBeVisible();
82+
});

packages/web-host/tests/utils.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { expect, type Page } from "@playwright/test";
22

3+
/**
4+
* Get the last std output of the given type
5+
*/
36
export async function getLastStd(
47
page: Page,
58
type: "stdin" | "stdout" | "stderr",
69
) {
710
return await page.locator(`[data-stdtype='${type}']`).last();
811
}
912

13+
/**
14+
* Fill the input with the command and submit it
15+
* Pass the expected stdin, stdout and stderr to check the results
16+
*/
1017
export async function fillAndSubmitCommand(
1118
page: Page,
1219
command: string,
@@ -34,3 +41,37 @@ export async function fillAndSubmitCommand(
3441
await expect(stderr).toHaveText(expectStderr);
3542
}
3643
}
44+
45+
/**
46+
* Click the wand button and check the results
47+
* Pass the expected stdin, stdout and stderr to check the results
48+
*/
49+
export async function clickWandButton(
50+
page: Page,
51+
command: string,
52+
{
53+
expectStdin = command,
54+
expectStdout,
55+
expectStderr,
56+
}: {
57+
expectStdin?: string;
58+
expectStdout?: string;
59+
expectStderr?: string;
60+
} = {},
61+
) {
62+
await page
63+
.getByRole("button", { name: "Run example command" })
64+
.click({ force: true });
65+
const input = await page.getByPlaceholder("Type a command...");
66+
await expect(input).toHaveValue(expectStdin);
67+
const stdin = await getLastStd(page, "stdin");
68+
await expect(stdin).toHaveText(expectStdin);
69+
if (expectStdout) {
70+
const stdout = await getLastStd(page, "stdout");
71+
await expect(stdout).toHaveText(expectStdout);
72+
}
73+
if (expectStderr) {
74+
const stderr = await getLastStd(page, "stderr");
75+
await expect(stderr).toHaveText(expectStderr);
76+
}
77+
}

0 commit comments

Comments
 (0)