Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add manual_json and playwright-test #269

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions fake-snippets-api/lib/db/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
snippet: Omit<z.input<typeof snippetSchema>, "snippet_id">,
): Snippet => {
const newSnippetId = `snippet_${get().idCounter + 1}`
const manualEditsJsonTemplate = {
pcb_placements: [],
edit_events: [],
manual_trace_hints: [],
}

const newSnippet = snippetSchema.parse({
...snippet,
manual_edits_json: JSON.stringify(manualEditsJsonTemplate, null, 2),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep this object as null by default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is an issue with the default value, that should be handled on the frontend the first time it's selected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, sure..

snippet_id: newSnippetId,
})
set((state) => {
Expand Down
26 changes: 26 additions & 0 deletions playwright-tests/manual-edit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from "@playwright/test"

test("Manual edits test", async ({ page }) => {
await page.goto("http://127.0.0.1:5177/editor?snippet_id=snippet_4")

// Wait for network requests to complete
await page.waitForLoadState("networkidle")

await page.getByRole("button", { name: "Fake testuser Login" }).click()
await page.waitForTimeout(500)

await page.getByRole("combobox").click()
await page.getByText("manual-edits.json").click()
await expect(page).toHaveScreenshot("editor-manual-edits.png")
})

test("Manual edits test view", async ({ page }) => {
await page.goto("http://localhost:5177/seveibar/a555timer")

await page.waitForLoadState("networkidle")

await page.goto("http://localhost:5177/seveibar/a555timer")
await page.getByRole("link", { name: "Files" }).click()
await page.getByText("manual-edits.json").click()
await expect(page).toHaveScreenshot("manual-edits-view.png")
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions src/components/CodeAndPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ export function CodeAndPreview({ snippet }: Props) {

const { toast } = useToast()

useEffect(() => {
if (snippet?.manual_edits_json) {
setManualEditsFileContent(snippet.manual_edits_json)
}
}, [Boolean(snippet?.manual_edits_json)])

const userImports = useMemo(
() => ({
"./manual-edits.json": JSON.parse(manualEditsFileContent),
Expand Down
Loading