|
1 | | -import { expect, type Page, test } from "@playwright/test"; |
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { fillAndSubmitCommand, getLastStd } from "./utils"; |
2 | 3 |
|
3 | | -async function getLastStd(page: Page, type: "stdin" | "stdout" | "stderr") { |
4 | | - return await page.locator(`[data-stdtype='${type}']`).last(); |
5 | | -} |
| 4 | +test("echo foo", async ({ page }) => { |
| 5 | + await page.goto("/#repl"); |
| 6 | + await fillAndSubmitCommand(page, "echo foo", { expectStdout: "foo" }); |
| 7 | +}); |
6 | 8 |
|
7 | | -test("echo foo - enter", async ({ page }) => { |
| 9 | +test("greet World", async ({ page }) => { |
8 | 10 | await page.goto("/#repl"); |
9 | | - const input = await page.getByPlaceholder("Type a command..."); |
10 | | - await input.fill("echo foo"); |
11 | | - await input.press("Enter"); |
12 | | - const stdin = await getLastStd(page, "stdin"); |
13 | | - await expect(stdin).toHaveText("echo foo"); |
14 | | - const stdout = await getLastStd(page, "stdout"); |
15 | | - await expect(stdout).toHaveText("foo"); |
| 11 | + await fillAndSubmitCommand(page, "greet World", { |
| 12 | + expectStdout: "Hello, World!", |
| 13 | + }); |
| 14 | +}); |
| 15 | + |
| 16 | +test("weather Paris", async ({ page }) => { |
| 17 | + await page.route("https://wttr.in/Paris?format=j1", (route) => { |
| 18 | + route.fulfill({ |
| 19 | + status: 200, |
| 20 | + body: JSON.stringify({ |
| 21 | + current_condition: [ |
| 22 | + { |
| 23 | + weatherDesc: [ |
| 24 | + { |
| 25 | + value: "Sunny", |
| 26 | + }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + ], |
| 30 | + }), |
| 31 | + }); |
| 32 | + }); |
| 33 | + await page.goto("/#repl"); |
| 34 | + await fillAndSubmitCommand(page, "weather Paris", { |
| 35 | + expectStdout: "Sunny", |
| 36 | + }); |
16 | 37 | }); |
17 | 38 |
|
18 | | -test("echo foo - run", async ({ page }) => { |
| 39 | +test("ls", async ({ page }) => { |
19 | 40 | await page.goto("/#repl"); |
20 | | - const input = await page.getByPlaceholder("Type a command..."); |
21 | | - await input.fill("echo foo"); |
22 | | - await page.getByRole("button", { name: "Run", exact: true }).click(); |
23 | | - const stdin = await getLastStd(page, "stdin"); |
24 | | - await expect(stdin).toHaveText("echo foo"); |
| 41 | + await fillAndSubmitCommand(page, "ls", { |
| 42 | + expectStdout: `D data |
| 43 | +D documents |
| 44 | +D logs |
| 45 | +F .config |
| 46 | +F .hidden_file |
| 47 | +F README.md`, |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +test("ls data", async ({ page }) => { |
| 52 | + await page.goto("/#repl"); |
| 53 | + await fillAndSubmitCommand(page, "ls data", { |
| 54 | + expectStdout: `D data/processed |
| 55 | +D data/raw |
| 56 | +F data/sample.csv |
| 57 | +F data/users.yaml`, |
| 58 | + }); |
| 59 | +}); |
| 60 | + |
| 61 | +test("ls data/users.yaml - should handle files", async ({ page }) => { |
| 62 | + await page.goto("/#repl"); |
| 63 | + await fillAndSubmitCommand(page, "ls data/users.yaml", { |
| 64 | + expectStdout: "F data/users.yaml", |
| 65 | + }); |
| 66 | +}); |
| 67 | + |
| 68 | +test("cat data", async ({ page }) => { |
| 69 | + await page.goto("/#repl"); |
| 70 | + await fillAndSubmitCommand(page, "cat data", { |
| 71 | + expectStderr: "cat: data: Is a directory", |
| 72 | + }); |
| 73 | +}); |
| 74 | + |
| 75 | +test("cat README.md", async ({ page }) => { |
| 76 | + await page.goto("/#repl"); |
| 77 | + await fillAndSubmitCommand(page, "cat README.md"); |
25 | 78 | const stdout = await getLastStd(page, "stdout"); |
26 | | - await expect(stdout).toHaveText("foo"); |
| 79 | + await expect(stdout).toContainText(`# filesystem |
| 80 | +
|
| 81 | +You are interacting with a virtual filesystem, in your browser!`); |
27 | 82 | }); |
0 commit comments