|
| 1 | +import { test, expect, Page } from "@playwright/test"; |
| 2 | +import { |
| 3 | + switchMode, |
| 4 | + clearEditor, |
| 5 | + editorSelector, |
| 6 | + enterTextAsMarkdown, |
| 7 | +} from "../e2e-helpers"; |
| 8 | + |
| 9 | +test.describe.serial("roundtrip tests", () => { |
| 10 | + let page: Page; |
| 11 | + test.beforeAll(async ({ browser }) => { |
| 12 | + page = await browser.newPage(); |
| 13 | + await page.goto("/empty.html"); |
| 14 | + await switchMode(page, "markdown"); |
| 15 | + }); |
| 16 | + |
| 17 | + test.afterAll(async () => { |
| 18 | + await page.close(); |
| 19 | + }); |
| 20 | + |
| 21 | + for (const [markdown] of [ |
| 22 | + //Basic commonmark |
| 23 | + ["plain"], |
| 24 | + ["*italic*"], |
| 25 | + ["_italic_"], |
| 26 | + ["**bold**"], |
| 27 | + ["__bold__"], |
| 28 | + ["# H1"], |
| 29 | + ["## H2"], |
| 30 | + ["[link](http://www.example.com)"], |
| 31 | + [""], |
| 32 | + ["> blockquote"], |
| 33 | + ["* List Item"], |
| 34 | + ["- List Item"], |
| 35 | + ["1. List Item"], |
| 36 | + ["2) List Item"], |
| 37 | + ["lol\n\n---\n\nlmao"], |
| 38 | + ["lol\n\n***\n\nlmao"], |
| 39 | + ["`code`"], |
| 40 | + //TODO: Codeblock does weird things roundtripping: Adds an extra space |
| 41 | + //['```javascript\ncodeblock\n```' ], |
| 42 | + |
| 43 | + //Escape character |
| 44 | + [String.raw`\# not a header`], |
| 45 | + [String.raw`- \# list item (not header)`], |
| 46 | + ] as const) { |
| 47 | + test(`should make markdown -> richtext -> markdown round trip '${JSON.stringify(markdown)}'`, async () => { |
| 48 | + await clearEditor(page); |
| 49 | + await enterTextAsMarkdown(page, markdown); |
| 50 | + await switchMode(page, "markdown"); |
| 51 | + |
| 52 | + const text = await page.innerText(editorSelector); |
| 53 | + expect(text).toBe(markdown); |
| 54 | + }); |
| 55 | + } |
| 56 | +}); |
0 commit comments