-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug that could cause auto formatting to fail for the last block.
Add tests for language auto detection and formatting.
- Loading branch information
Showing
4 changed files
with
90 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { HeynotePage } from "./test-utils.js"; | ||
|
||
let heynotePage | ||
|
||
test.beforeEach(async ({ page }) => { | ||
console.log("beforeEach") | ||
heynotePage = new HeynotePage(page) | ||
await heynotePage.goto() | ||
}) | ||
|
||
|
||
test("JSON formatting", async ({ page }) => { | ||
heynotePage.setContent(` | ||
∞∞∞json | ||
{"test": 1, "key2": "hey!"} | ||
`) | ||
expect(await page.locator("css=.status .status-block.lang")).toHaveText("JSON") | ||
await page.locator("css=.status-block.format").click() | ||
await page.waitForTimeout(100) | ||
expect(await heynotePage.getBlockContent(0)).toBe(`{ | ||
"test": 1, | ||
"key2": "hey!" | ||
} | ||
`) | ||
}) | ||
|
||
test("JSON formatting (cursor at start)", async ({ page }) => { | ||
heynotePage.setContent(` | ||
∞∞∞json | ||
{"test": 1, "key2": "hey!"} | ||
`) | ||
expect(await page.locator("css=.status .status-block.lang")).toHaveText("JSON") | ||
for (let i=0; i<5; i++) { | ||
await page.locator("body").press("ArrowUp") | ||
} | ||
await page.locator("css=.status-block.format").click() | ||
await page.waitForTimeout(100) | ||
expect(await heynotePage.getBlockContent(0)).toBe(`{ | ||
"test": 1, | ||
"key2": "hey!" | ||
} | ||
`) | ||
const block = (await heynotePage.getBlocks())[0] | ||
expect(await page.evaluate(() => window._heynote_editor.view.state.selection.main.from)).toBe(block.content.from) | ||
}) |
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,41 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { HeynotePage } from "./test-utils.js"; | ||
|
||
let heynotePage | ||
|
||
test.beforeEach(async ({ page }) => { | ||
console.log("beforeEach") | ||
heynotePage = new HeynotePage(page) | ||
await heynotePage.goto() | ||
}) | ||
|
||
|
||
test("test valid JSON detection", async ({ page }) => { | ||
page.locator("body").pressSequentially(` | ||
{"test": 1, "key2": "hey!"} | ||
`) | ||
await page.waitForTimeout(200); | ||
expect(await page.locator("css=.status .status-block.lang")).toHaveText("JSON (auto)") | ||
const block = (await heynotePage.getBlocks())[0] | ||
expect(block.language.name).toBe("json") | ||
expect(block.language.auto).toBeTruthy() | ||
}) | ||
|
||
|
||
test("python detection", async ({ page }) => { | ||
page.locator("body").pressSequentially(` | ||
# import complex math module | ||
import cmath | ||
# calculate the discriminant | ||
d = (b**2) - (4*a*c) | ||
# find two solutions | ||
sol1 = (-b-cmath.sqrt(d))/(2*a) | ||
sol2 = (-b+cmath.sqrt(d))/(2*a) | ||
print('The solution are {0} and {1}'.format(sol1,sol2)) | ||
`) | ||
await page.waitForTimeout(1000); | ||
expect(await page.locator("css=.status .status-block.lang")).toHaveText("Python (auto)") | ||
}) |
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