-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: import circuit json * patch: naming * chore: removed caps as per review * fix: json badge color * chore: format * patch: json crd type badge * feat: Allow them to paste or upload circuit json, not a url * test: broken tests because playwright not working on my device * tests: sad * wtf * add 4 tests * tests: circuit json import modal full tests * chore: deleted debug file * chore: remove unused dep * validCircuitJson -> exampleCircuitJson
- Loading branch information
Showing
6 changed files
with
859 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { test, expect } from "@playwright/test" | ||
import { exampleCircuitJson } from "./exampleCircuitJson" | ||
|
||
async function loginToSite(page) { | ||
const loginButton = page.getByRole("button", { name: "Log in" }) | ||
if (await loginButton.isVisible()) { | ||
await loginButton.click() | ||
await page.waitForLoadState("networkidle") | ||
} | ||
} | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://127.0.0.1:5177/quickstart") | ||
await page.waitForTimeout(3000) | ||
await loginToSite(page).catch(() => {}) | ||
}) | ||
|
||
test("should open and close the Circuit Json Import Dialog", async ({ | ||
page, | ||
}) => { | ||
const importButton = page.locator('button:has-text("Import Circuit JSON")') | ||
await importButton.click() | ||
|
||
const dialog = page.getByRole("dialog") | ||
await expect(dialog).toBeVisible() | ||
|
||
const closeButton = dialog.getByRole("button", { name: "Close" }) | ||
await closeButton.click() | ||
|
||
await expect(dialog).not.toBeVisible() | ||
}) | ||
|
||
test("should handle valid Circuit JSON input", async ({ page }) => { | ||
const importButton = page.getByRole("button", { name: "Import Circuit JSON" }) | ||
await importButton.click() | ||
const textarea = page.locator( | ||
'textarea[placeholder="Paste the Circuit JSON."]', | ||
) | ||
await textarea.fill(JSON.stringify(exampleCircuitJson)) | ||
|
||
const importDialogButton = page.getByRole("button", { name: "Import" }) | ||
await importDialogButton.click() | ||
|
||
const successToast = page.locator( | ||
'div.text-sm.font-semibold:has-text("Import Successful")', | ||
) | ||
await successToast.waitFor({ state: "visible", timeout: 5000 }) | ||
await expect(successToast).toBeVisible() | ||
}) | ||
|
||
test("should handle valid Circuit JSON file upload", async ({ page }) => { | ||
const importButton = page.locator('button:has-text("Import Circuit JSON")') | ||
await importButton.click() | ||
|
||
const fileInput = page.locator('input[type="file"]') | ||
|
||
await fileInput.setInputFiles({ | ||
name: "circuit.json", | ||
mimeType: "application/json", | ||
// @ts-expect-error didnt add node types to tsconfig | ||
buffer: Buffer.from(JSON.stringify(exampleCircuitJson)), | ||
}) | ||
|
||
const importDialogButton = page.getByRole("button", { name: "Import" }) | ||
await importDialogButton.click() | ||
const successToast = page.locator( | ||
'div.text-sm.font-semibold:has-text("Import Successful")', | ||
) | ||
await successToast.waitFor({ state: "visible", timeout: 5000 }) | ||
await expect(successToast).toBeVisible() | ||
}) | ||
|
||
test("should handle invalid Circuit JSON input", async ({ page }) => { | ||
const importButton = page.locator('button:has-text("Import Circuit JSON")') | ||
await importButton.click() | ||
|
||
const textarea = page.locator( | ||
'textarea[placeholder="Paste the Circuit JSON."]', | ||
) | ||
await textarea.fill("invalid json content") | ||
|
||
const importDialogButton = page.getByRole("button", { name: "Import" }) | ||
await importDialogButton.click() | ||
|
||
const errorToast = page.locator( | ||
'div.text-sm.font-semibold:has-text("Invalid Input")', | ||
) | ||
await errorToast.waitFor({ state: "visible", timeout: 5000 }) | ||
await expect(errorToast).toBeVisible() | ||
}) | ||
|
||
test("should handle invalid Circuit JSON file upload", async ({ page }) => { | ||
const importButton = page.locator('button:has-text("Import Circuit JSON")') | ||
await importButton.click() | ||
|
||
const fileInput = page.locator('input[type="file"]') | ||
await fileInput.setInputFiles({ | ||
name: "circuit.json", | ||
mimeType: "application/json", | ||
// @ts-expect-error didnt add node types to tsconfig | ||
buffer: Buffer.from(JSON.stringify({})), | ||
}) | ||
|
||
const importDialogButton = page.getByRole("button", { name: "Import" }) | ||
await importDialogButton.click() | ||
|
||
const errorToast = page.locator( | ||
'div.text-sm.font-semibold:has-text("Import Failed")', | ||
) | ||
await errorToast.waitFor({ state: "visible", timeout: 5000 }) | ||
await expect(errorToast).toBeVisible() | ||
}) | ||
|
||
test("should handle non-JSON file upload", async ({ page }) => { | ||
const importButton = page.locator('button:has-text("Import Circuit JSON")') | ||
await importButton.click() | ||
|
||
const fileInput = page.locator('input[type="file"]') | ||
await fileInput.setInputFiles({ | ||
name: "circuit.txt", | ||
mimeType: "application/text", | ||
// @ts-expect-error didnt add node types to tsconfig | ||
buffer: Buffer.from(""), | ||
}) | ||
|
||
const importDialogButton = page.getByRole("button", { name: "Import" }) | ||
await importDialogButton.click() | ||
|
||
const errorToast = page.locator( | ||
'div.pb-4 > p:has-text("Please select a valid JSON file.")', | ||
) | ||
await expect(errorToast).toBeVisible() | ||
}) |
Oops, something went wrong.