Skip to content

Commit

Permalink
Test without monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Jul 10, 2024
1 parent cb7d7ab commit 0b4777d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
6 changes: 3 additions & 3 deletions e2e/chip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ test.describe("chip", () => {
});

test("simple chip", async ({ page, monaco }) => {
await page.goto("chip");
await page.goto("chip?monaco=false");
await page.getByRole("button", { name: "Accept" }).click();
await page.getByTestId("project-picker").selectOption("Project 1");
await page.getByTestId("chip-picker").selectOption("Not");

await monaco.write(NOT);
await page.screenshot({ path: "not.png" });
await monaco.toggleMonaco();
await monaco.write(NOT, "hdl");
await expect(page.getByText("HDL code: No syntax errors")).toBeVisible();

await page.getByRole("button", { name: "Run ️⏩" }).click();
Expand Down
38 changes: 29 additions & 9 deletions e2e/util/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@ import type { Locator, Page } from "@playwright/test";
import { test as base } from "@playwright/test";

export class MonacoPage {
private usingMonaco = true;
public readonly monacoEditor: Locator;
constructor(readonly page: Page) {
this.monacoEditor = page.locator(".monaco-editor").nth(0);
}

async clearEditor() {
await this.monacoEditor.click();
await this.page.keyboard.press("ControlOrMeta+KeyA");
await this.page.keyboard.press("Backspace");
await this.page.keyboard.press("ControlOrMeta+KeyA");
await this.page.keyboard.press("Backspace");
async toggleMonaco() {
await this.page.getByText("settings", { exact: true }).click();
await this.page.getByText("Use Monaco Editor").click();
await this.page
.locator("header")
.filter({ hasText: /^Settings$/ })
.getByRole("link")
.click();
this.usingMonaco = !this.usingMonaco;
}

async write(text: string) {
await this.clearEditor();
await this.monacoEditor.click();
async clearEditor(editor: string) {
if (this.usingMonaco) {
await this.monacoEditor.click();
await this.page.keyboard.press("ControlOrMeta+KeyA");
await this.page.keyboard.press("Backspace");
await this.page.keyboard.press("ControlOrMeta+KeyA");
await this.page.keyboard.press("Backspace");
} else {
await this.page.getByTestId(`editor-${editor}`).clear();
}
}

async write(text: string, editor: string) {
await this.clearEditor(editor);
if (this.usingMonaco) {
await this.monacoEditor.click();
} else {
await this.page.getByTestId(`editor-${editor}`);
}
for (const line of text.split("\n")) {
await this.page.keyboard.type(`${line}\n`);
}
Expand Down

0 comments on commit 0b4777d

Please sign in to comment.