This commit is contained in:
evilchili
2026-06-19 17:11:10 -07:00
parent d23c3e7a67
commit fe405cb393
3 changed files with 308 additions and 173 deletions
+128 -1
View File
@@ -323,6 +323,40 @@ async function runTests() {
);
});
await test('bold followed by trailing space stays bold', async () => {
await resetEditor();
await typeString('**bold** ');
const html = await getHTML();
assert(html.includes('md-bold'), `Expected md-bold span to survive trailing space: ${html}`);
const markdown = await getMarkdown();
assert(
markdown === '**bold** ',
`Expected "**bold** ", got: "${markdown}"`
);
});
await test('heading prefix stays plain space, not nbsp, after rebuild', async () => {
await resetEditor();
await typeString('# Title');
const html = await getHTML();
// The delimiter span's text must be a literal space (U+0020),
// not a non-breaking space, or block classification breaks on
// the next keystroke read of textContent.
assert(
html.includes('<span class="md-delim"># </span>') ||
html.includes('class="md-delim">#&nbsp;'),
`Unexpected delim content: ${html}`
);
// The real check: typing more text after this should still
// classify as md-h1, not regress to md-paragraph.
await typeString(' more');
const classes = await getBlockClasses();
assert(
classes.some(c => c.includes('md-h1')),
`Lost md-h1 classification after additional typing: ${JSON.stringify(classes)}`
);
});
// ── getMarkdown round-trips ────────────────────────────────────────────────
console.log('\ngetMarkdown round-trips:');
@@ -359,6 +393,65 @@ async function runTests() {
console.log('\nEnter key behaviour:');
await test('double Enter exits list', async () => {
await resetEditor();
await typeString('- item');
await pressKey('Enter');
await pressKey('Enter');
const blocks = await getBlockClasses();
assert(
blocks.some(c => c.includes('md-paragraph')),
`Expected paragraph after double Enter, got: ${JSON.stringify(blocks)}`
);
});
await test('double Enter exits blockquote', async () => {
await resetEditor();
await typeString('> quote');
await pressKey('Enter');
await pressKey('Enter');
const blocks = await getBlockClasses();
assert(
blocks.some(c => c.includes('md-paragraph')),
`Expected paragraph after double Enter, got: ${JSON.stringify(blocks)}`
);
});
await test('ordered list increments', async () => {
await resetEditor();
await typeString('1. first');
await pressKey('Enter');
const markdown = await getMarkdown();
assert(
markdown.includes('2. '),
`Expected "2. " on second line, got: "${markdown}"`
);
});
await test('heading followed by Enter creates paragraph', async () => {
await resetEditor();
await typeString('# Title');
await pressKey('Enter');
await typeString('body');
const blocks = await getBlockClasses();
assert(blocks.some(c => c.includes('md-h1')), `No h1: ${blocks}`);
assert(blocks.some(c => c.includes('md-paragraph')), `No paragraph: ${blocks}`);
const markdown = await getMarkdown();
assert(markdown === '# Title\nbody', `Expected "# Title\\nbody", got: "${markdown}"`);
});
await test('heading renders correctly after typing', async () => {
await resetEditor();
await typeString('# foo');
const blocks = await getBlockClasses();
assert(
blocks.some(c => c.includes('md-h1')),
`Expected md-h1, got: ${JSON.stringify(blocks)}`
);
const markdown = await getMarkdown();
assert(markdown === '# foo', `Expected "# foo", got: "${markdown}"`);
});
await test('Enter splits current block into two blocks', async () => {
await resetEditor();
await typeString('hello');
@@ -418,6 +511,24 @@ async function runTests() {
console.log('\nBackspace key behaviour:');
await test('backspace on last empty block does not break editor', async () => {
await resetEditor();
await typeString('foo');
// Select all and delete
await page.keyboard.press('Control+a');
await page.keyboard.press('Backspace');
await page.keyboard.press('Backspace');
// Editor should still be functional
await typeString('# bar');
const blocks = await getBlockClasses();
assert(
blocks.some(c => c.includes('md-h1')),
`Editor broken after double backspace, got: ${JSON.stringify(blocks)}`
);
const markdown = await getMarkdown();
assert(markdown === '# bar', `Expected "# bar", got: "${markdown}"`);
});
await test('Backspace at start of block merges with previous block', async () => {
await resetEditor();
await typeString('foo');
@@ -531,7 +642,23 @@ async function runTests() {
assert(markdown === 'first\n\nsecond', `Expected "first\\n\\nsecond", got: "${markdown}"`);
});
//*/
await test('# space becomes md-h1', async () => {
await resetEditor();
await typeString('#');
let classes = await getBlockClasses();
assert(!classes.some(c => c.includes('md-h')), `Premature heading after just #: ${classes}`);
await typeString(' ');
const html = await page.evaluate(() => document.getElementById('ribbit').innerHTML);
classes = await getBlockClasses();
assert(classes.some(c => c.includes('md-h1')), `Expected md-h1 after "# ", got: ${classes}`);
await typeString('Title');
const markdown = await getMarkdown();
assert(markdown.includes('# Title'), `Expected "# Title" in markdown: ${markdown}`);
});
}