-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e for latex feature (#1618)
* test: add e2e for latex feature * chore: fix latex to markdown syntax * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2c558d6
commit 18db4dc
Showing
9 changed files
with
135 additions
and
0 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,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Crepe</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/crepe/main.ts"></script> | ||
</body> | ||
</html> |
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,4 @@ | ||
export const crepe = { | ||
title: 'Crepe', | ||
link: '/crepe/', | ||
} |
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,13 @@ | ||
import { Crepe } from '@milkdown/crepe' | ||
import '@milkdown/crepe/theme/common/style.css' | ||
import '@milkdown/crepe/theme/frame.css' | ||
|
||
import { setup } from '../utils' | ||
|
||
setup(async () => { | ||
const crepe = new Crepe({ | ||
root: '#app', | ||
}) | ||
await crepe.create() | ||
return crepe.editor | ||
}) |
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,74 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { focusEditor, getMarkdown } from 'tests/misc' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/crepe/') | ||
}) | ||
|
||
test('latex block preview toggle', async ({ page }) => { | ||
await focusEditor(page) | ||
await page.keyboard.type('$$') | ||
await page.keyboard.press('Enter') | ||
|
||
const codeBlock = page.locator('milkdown-code-block') | ||
const codemirror = codeBlock.locator('.codemirror-host') | ||
const preview = codeBlock.locator('.preview') | ||
const codeTools = codeBlock.locator('.tools') | ||
const previewToggleButton = codeTools.locator('.preview-toggle-button') | ||
|
||
await expect(codeBlock).toBeVisible() | ||
|
||
// when code block is empty, preview toggle button is not visible | ||
await codeTools.hover() | ||
await expect(previewToggleButton).not.toBeVisible() | ||
|
||
await page.keyboard.press('ArrowUp') | ||
await page.keyboard.type('E=mc^2') | ||
|
||
await expect(preview).toBeVisible() | ||
const markdown = await getMarkdown(page) | ||
expect(markdown.trim()).toEqual('$$\nE=mc^2\n$$') | ||
|
||
await codeTools.hover() | ||
await expect(previewToggleButton).toBeVisible() | ||
|
||
await expect(codemirror).toBeVisible() | ||
await previewToggleButton.click() | ||
await expect(codemirror).not.toBeVisible() | ||
|
||
await previewToggleButton.click() | ||
await expect(codemirror).toBeVisible() | ||
}) | ||
|
||
test('latex inline', async ({ page }) => { | ||
await focusEditor(page) | ||
await page.keyboard.type('$E=mc^2$') | ||
|
||
const inlineLatex = page.locator('span[data-type="math_inline"]') | ||
const inlineLatexInput = page.locator('milkdown-latex-inline-edit') | ||
const inlineLatexInputConfirm = inlineLatexInput.locator('button') | ||
|
||
await expect(inlineLatex).toBeVisible() | ||
|
||
let markdown = await getMarkdown(page) | ||
expect(markdown.trim()).toEqual('$E=mc^2$') | ||
|
||
await page.keyboard.press('ArrowLeft') | ||
await expect(inlineLatexInput).toBeVisible() | ||
|
||
await inlineLatexInput.click() | ||
await page.keyboard.press('Backspace') | ||
await page.keyboard.type('3') | ||
await page.keyboard.press('Enter') | ||
|
||
markdown = await getMarkdown(page) | ||
expect(markdown.trim()).toEqual('$E=mc^3$') | ||
|
||
await inlineLatexInput.click() | ||
await page.keyboard.press('Backspace') | ||
await page.keyboard.type('4') | ||
await inlineLatexInputConfirm.click() | ||
|
||
markdown = await getMarkdown(page) | ||
expect(markdown.trim()).toEqual('$E=mc^4$') | ||
}) |
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,25 @@ | ||
import { codeBlockSchema } from '@milkdown/kit/preset/commonmark' | ||
|
||
export const blockLatexSchema = codeBlockSchema.extendSchema((prev) => { | ||
return (ctx) => { | ||
const baseSchema = prev(ctx) | ||
return { | ||
...baseSchema, | ||
toMarkdown: { | ||
match: baseSchema.toMarkdown.match, | ||
runner: (state, node) => { | ||
const language = node.attrs.language | ||
if (language.toLowerCase() === 'latex') { | ||
state.addNode( | ||
'math', | ||
undefined, | ||
node.content.firstChild?.text || '' | ||
) | ||
} else { | ||
return baseSchema.toMarkdown.runner(state, node) | ||
} | ||
}, | ||
}, | ||
} | ||
} | ||
}) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.