|
1 | 1 | import { expect, type Page } from "@playwright/test"; |
2 | 2 |
|
| 3 | +/** |
| 4 | + * Get the last std output of the given type |
| 5 | + */ |
3 | 6 | export async function getLastStd( |
4 | 7 | page: Page, |
5 | 8 | type: "stdin" | "stdout" | "stderr", |
6 | 9 | ) { |
7 | 10 | return await page.locator(`[data-stdtype='${type}']`).last(); |
8 | 11 | } |
9 | 12 |
|
| 13 | +/** |
| 14 | + * Fill the input with the command and submit it |
| 15 | + * Pass the expected stdin, stdout and stderr to check the results |
| 16 | + */ |
10 | 17 | export async function fillAndSubmitCommand( |
11 | 18 | page: Page, |
12 | 19 | command: string, |
@@ -34,3 +41,37 @@ export async function fillAndSubmitCommand( |
34 | 41 | await expect(stderr).toHaveText(expectStderr); |
35 | 42 | } |
36 | 43 | } |
| 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