Skip to content

Commit

Permalink
test: add more regression tests from lexical
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed May 7, 2024
1 parent b7ad501 commit 3720379
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from '../utils/index.mjs';

test.describe('Regression test #1083', () => {
test.fixme();
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test(`Backspace with ElementNode at the front of the paragraph`, async ({
page,
Expand All @@ -33,6 +32,7 @@ test.describe('Regression test #1083', () => {
await page.keyboard.type('Hello');
await selectAll(page);
await click(page, '.link');
await click(page, '.link-confirm');

await moveToLineEnd(page);
await page.keyboard.type('World');
Expand All @@ -45,7 +45,7 @@ test.describe('Regression test #1083', () => {
dir="ltr">
<a
href="https://"
rel="noopener"
rel="noreferrer"
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Hello</span>
Expand Down Expand Up @@ -78,6 +78,7 @@ test.describe('Regression test #1083', () => {
await page.keyboard.type('Hello');
await selectCharacters(page, 'left', 'Hello'.length);
await click(page, '.link');
await click(page, '.link-confirm');

await moveToLineEnd(page);
await page.keyboard.type('World');
Expand All @@ -91,7 +92,7 @@ test.describe('Regression test #1083', () => {
<span data-lexical-text="true">Say</span>
<a
href="https://"
rel="noopener"
rel="noreferrer"
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Hello</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ import {

test.describe('Regression test #1384', () => {
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test.fixme(
`Properly pastes in code blocks`,
async ({page, isPlainText, isCollab}) => {
test.skip(isPlainText || isCollab);
await focusEditor(page);
await page.keyboard.type('``` alert(1);');
await page.keyboard.press('Enter');
await page.keyboard.type('alert(2);');
await page.keyboard.press('Enter');
await page.keyboard.type('alert(3);');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowLeft');
await selectCharacters(page, 'left', 8);
const clipboard = await copyToClipboard(page);
await page.keyboard.press('ArrowLeft');
await pasteFromClipboard(page, clipboard);
await assertHTML(
page,
`<code class="PlaygroundEditorTheme__code PlaygroundEditorTheme__ltr" spellcheck="false" dir="ltr" data-gutter="123" data-highlight-language="javascript"><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">1</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">1</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span><br><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">2</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span><br><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">3</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span></code>`,
);
},
);
test(`Properly pastes in code blocks`, async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText || isCollab);
await focusEditor(page);
await page.keyboard.type('``` alert(1);');
await page.keyboard.press('Enter');
await page.keyboard.type('alert(2);');
await page.keyboard.press('Enter');
await page.keyboard.type('alert(3);');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowLeft');
await selectCharacters(page, 'left', 8);
const clipboard = await copyToClipboard(page);
await page.keyboard.press('ArrowLeft');
await pasteFromClipboard(page, clipboard);
await assertHTML(
page,
`<code class="PlaygroundEditorTheme__code PlaygroundEditorTheme__ltr" spellcheck="false" dir="ltr" data-gutter="123" data-highlight-language="javascript"><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">1</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">1</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span><br><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">2</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span><br><span class="PlaygroundEditorTheme__tokenFunction" data-lexical-text="true">alert</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">(</span><span class="PlaygroundEditorTheme__tokenProperty" data-lexical-text="true">3</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">)</span><span class="PlaygroundEditorTheme__tokenPunctuation" data-lexical-text="true">;</span></code>`,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '../utils/index.mjs';

test.describe('Regression test #221', () => {
test.fixme();
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test(`Can handle space in hashtag`, async ({page}) => {
await focusEditor(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,33 @@ import {

test.describe('Regression test #230', () => {
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test.fixme(
`Is able to right arrow before hashtag after inserting text node`,
async ({page}) => {
await focusEditor(page);
await page.keyboard.type('#foo');
await waitForSelector(page, '.PlaygroundEditorTheme__hashtag');
await moveLeft(page, 4);
await page.keyboard.type('a');
await page.keyboard.press('Backspace');
await page.keyboard.press('ArrowRight');
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span
class="PlaygroundEditorTheme__hashtag"
data-lexical-text="true">
#foo
</span>
</p>
`,
);
await assertSelection(page, {
anchorOffset: 1,
anchorPath: [0, 0, 0],
focusOffset: 1,
focusPath: [0, 0, 0],
});
},
);
test(`Is able to right arrow before hashtag after inserting text node`, async ({
page,
}) => {
await focusEditor(page);
await page.keyboard.type('#foo');
await waitForSelector(page, '.PlaygroundEditorTheme__hashtag');
await moveLeft(page, 4);
await page.keyboard.type('a');
await page.keyboard.press('Backspace');
await page.keyboard.press('ArrowRight');
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="PlaygroundEditorTheme__hashtag" data-lexical-text="true">
#foo
</span>
</p>
`,
);
await assertSelection(page, {
anchorOffset: 1,
anchorPath: [0, 0, 0],
focusOffset: 1,
focusPath: [0, 0, 0],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,28 @@ import {

test.describe('Regression test #231', () => {
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test.fixme(
`Does not generate segment error when editing empty text nodes`,
async ({page}) => {
await focusEditor(page);
await page.keyboard.type('#foo');
await waitForSelector(page, '.PlaygroundEditorTheme__hashtag');
await moveLeft(page, 4);
await page.keyboard.type('a');
await page.keyboard.press('Backspace');
await moveRight(page, 5);
await pressBackspace(page, 5);
await assertHTML(
page,
html`
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
`,
);
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [0],
focusOffset: 0,
focusPath: [0],
});
},
);
test(`Does not generate segment error when editing empty text nodes`, async ({
page,
}) => {
await focusEditor(page);
await page.keyboard.type('#foo');
await waitForSelector(page, '.PlaygroundEditorTheme__hashtag');
await moveLeft(page, 4);
await page.keyboard.type('a');
await page.keyboard.press('Backspace');
await moveRight(page, 5);
await pressBackspace(page, 5);
await assertHTML(
page,
html`
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
`,
);
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [0],
focusOffset: 0,
focusPath: [0],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from '../utils/index.mjs';

test.describe('Regression test #3136', () => {
test.fixme();
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test('Correctly pastes rich content when the selection is followed by an inline element', async ({
isPlainText,
Expand All @@ -39,6 +38,7 @@ test.describe('Regression test #3136', () => {
await page.keyboard.type('link');
await selectCharacters(page, 'left', 'link'.length);
await click(page, '.link');
await click(page, '.link-confirm');

// Select non-link text so that selection ends just before the link
await moveLeft(page, 5);
Expand All @@ -59,7 +59,7 @@ test.describe('Regression test #3136', () => {
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr"
href="https://"
rel="noopener">
rel="noreferrer">
<span data-lexical-text="true">link</span>
</a>
</p>
Expand All @@ -79,6 +79,7 @@ test.describe('Regression test #3136', () => {
await page.keyboard.type('link');
await selectCharacters(page, 'left', 'link'.length);
await click(page, '.link');
await click(page, '.link-confirm');

// Non-link text
await moveRight(page, 1);
Expand All @@ -102,7 +103,7 @@ test.describe('Regression test #3136', () => {
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr"
href="https://"
rel="noopener">
rel="noreferrer">
<span data-lexical-text="true">link</span>
</a>
<span data-lexical-text="true">replaced</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '../utils/index.mjs';

test.describe('Regression test #3433', () => {
test.fixme();
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test('can merge markdown lists created immediately before existing lists', async ({
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ test.describe('Regression test #379', () => {
`Is able to correctly handle backspace press at the line boundary`,
async ({page}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await waitForSelector(page, '#typeahead-menu ul li');
await page.keyboard.type('@Luke');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');
await assertHTML(
page,
Expand Down
Loading

0 comments on commit 3720379

Please sign in to comment.