Skip to content

Commit a1aee5c

Browse files
authored
Graduate file editing from experimental (#599)
1 parent dfdd267 commit a1aee5c

File tree

9 files changed

+6041
-42
lines changed

9 files changed

+6041
-42
lines changed

e2e-tests/edit_code.spec.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { test } from "./helpers/test_helper";
2+
import { expect } from "@playwright/test";
3+
import fs from "fs";
4+
import path from "path";
5+
6+
test("edit code", async ({ po }) => {
7+
const editedFilePath = path.join("src", "components", "made-with-dyad.tsx");
8+
await po.sendPrompt("foo");
9+
const appPath = await po.getCurrentAppPath();
10+
11+
await po.clickTogglePreviewPanel();
12+
13+
await po.selectPreviewMode("code");
14+
await po.page.getByText("made-with-dyad.tsx").click();
15+
await po.page
16+
.getByRole("code")
17+
.locator("div")
18+
.filter({ hasText: "export const" })
19+
.nth(4)
20+
.click();
21+
await po.page
22+
.getByRole("textbox", { name: "Editor content" })
23+
.fill("export const MadeWithDyad = ;");
24+
25+
// Save the file
26+
await po.page.getByTestId("save-file-button").click();
27+
28+
// Expect toast to be visible
29+
await expect(po.page.getByText("File saved")).toBeVisible();
30+
31+
// We are NOT snapshotting the app files because the Monaco UI edit
32+
// is not deterministic.
33+
const editedFile = fs.readFileSync(
34+
path.join(appPath, editedFilePath),
35+
"utf8",
36+
);
37+
expect(editedFile).toContain("export const MadeWithDyad = ;");
38+
});
39+
40+
test("edit code edits the right file", async ({ po }) => {
41+
const editedFilePath = path.join("src", "components", "made-with-dyad.tsx");
42+
const robotsFilePath = path.join("public", "robots.txt");
43+
await po.sendPrompt("foo");
44+
const appPath = await po.getCurrentAppPath();
45+
const originalRobotsFile = fs.readFileSync(
46+
path.join(appPath, robotsFilePath),
47+
"utf8",
48+
);
49+
50+
await po.clickTogglePreviewPanel();
51+
52+
await po.selectPreviewMode("code");
53+
await po.page.getByText("made-with-dyad.tsx").click();
54+
await po.page
55+
.getByRole("code")
56+
.locator("div")
57+
.filter({ hasText: "export const" })
58+
.nth(4)
59+
.click();
60+
await po.page
61+
.getByRole("textbox", { name: "Editor content" })
62+
.fill("export const MadeWithDyad = ;");
63+
64+
// Save the file by switching files
65+
await po.page.getByText("robots.txt").click();
66+
67+
// Expect toast to be visible
68+
await expect(po.page.getByText("File saved")).toBeVisible();
69+
70+
// We are NOT snapshotting the app files because the Monaco UI edit
71+
// is not deterministic.
72+
const editedFile = fs.readFileSync(
73+
path.join(appPath, editedFilePath),
74+
"utf8",
75+
);
76+
expect(editedFile).toContain("export const MadeWithDyad = ;");
77+
78+
// Make sure the robots.txt file is not edited
79+
const editedRobotsFile = fs.readFileSync(
80+
path.join(appPath, robotsFilePath),
81+
"utf8",
82+
);
83+
expect(editedRobotsFile).toEqual(originalRobotsFile);
84+
});

0 commit comments

Comments
 (0)