Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions e2e/fixtures/chip.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ type ChipFixtures = {

export const test = base.extend<ChipFixtures>({
chipPage: async ({ page }, use) => {
await page.goto("chip?monaco=0");
await use(new ChipPage(page));
await page.goto("chip");
const chipPage = new ChipPage(page);
await chipPage.editor.disableMonaco();
await use(chipPage);
},
});
7 changes: 4 additions & 3 deletions e2e/src/pages/ChipPage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { expect, type Page } from "@playwright/test";
import { EditorPanel } from "./EditorPanel";
import { TestPanel } from "./TestPanel";

export class ChipPage {
editor: EditorPanel;
testPanel: TestPanel;

constructor(private _page: Page) {
this.editor = new EditorPanel(_page);
this.testPanel = new TestPanel(_page);
}

Expand Down Expand Up @@ -107,8 +110,6 @@ export class ChipPage {
}

async fillHdlEditor(content: string): Promise<void> {
const textarea = this._page.locator('[data-testid="editor-hdl"]');
await expect(textarea).toBeEnabled();
await textarea.fill(content);
await this.editor.write(content, "hdl");
}
}
57 changes: 57 additions & 0 deletions e2e/src/pages/EditorPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect, type Locator, type Page } from "@playwright/test";

export class EditorPanel {
readonly monacoEditor: Locator;
private usingMonaco = true;

constructor(private page: Page) {
this.monacoEditor = page.locator(".monaco-editor").nth(0);
}

async enableMonaco(): Promise<void> {
await this.setMonaco(true);
}

async disableMonaco(): Promise<void> {
await this.setMonaco(false);
}

private async setMonaco(enabled: boolean): Promise<void> {
await this.page.locator('[data-tooltip="Settings"]').click();
const monacoSwitch = this.page.getByRole("switch", {
name: "Use Monaco Editor",
});
if ((await monacoSwitch.isChecked()) !== enabled) {
await monacoSwitch.click();
}
if (enabled) {
await expect(monacoSwitch).toBeChecked();
} else {
await expect(monacoSwitch).not.toBeChecked();
}
const closeButton = this.page.locator(".settings-dialog a.close");
await expect(closeButton).toBeVisible();
await closeButton.click();
this.usingMonaco = enabled;
}

async clearEditor(editor: string): Promise<void> {
if (this.usingMonaco) {
await this.monacoEditor.click();
await this.page.keyboard.press("Control+A");
await this.page.keyboard.press("Backspace");
await this.page.keyboard.press("Backspace");
} else {
await this.page.getByTestId(`editor-${editor}`).clear();
}
}

async write(text: string, editor: string): Promise<void> {
await this.clearEditor(editor);
if (this.usingMonaco) {
await this.page.keyboard.type(text);
} else {
await this.page.getByTestId(`editor-${editor}`).fill(text);
}
}
}
49 changes: 49 additions & 0 deletions e2e/tests/chip/editor-panel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect, test as base } from "@playwright/test";
import { ChipPage } from "../../src/pages/ChipPage";

const test = base.extend<{ chipPage: ChipPage }>({
chipPage: async ({ page }, use) => {
await page.goto("chip");
const chipPage = new ChipPage(page);
await chipPage.editor.disableMonaco();
await use(chipPage);
},
});

const AND_HDL = `CHIP And {
IN a, b;
OUT out;

PARTS:
Nand(a=a, b=b, out=x);
Not(in=x, out=out);
}`;

test("fillHdlEditor works after fixture disables Monaco via settings UI", async ({
chipPage,
}) => {
await chipPage.selectProject("01");
await chipPage.selectChip("And");

await expect(chipPage.editor.monacoEditor).not.toBeVisible();

await chipPage.fillHdlEditor(AND_HDL);
await chipPage.testPanel.runTest();

expect(await chipPage.testPanel.getFailureCount()).toBe(0);
});

test("toggleMonaco re-enables Monaco editor for tests that need it", async ({
chipPage,
}) => {
await chipPage.selectProject("01");
await chipPage.selectChip("And");

await chipPage.editor.enableMonaco();
await expect(chipPage.editor.monacoEditor).toBeVisible();

await chipPage.editor.write(AND_HDL, "hdl");
await chipPage.testPanel.runTest();

expect(await chipPage.testPanel.getFailureCount()).toBe(0);
});
Loading