Skip to content

Commit

Permalink
add e2e tests for MaxLength plugin (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya authored Jun 17, 2022
1 parent 0b7635a commit e5b574d
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions packages/lexical-playground/__tests__/e2e/MaxLength.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

import {
assertHTML,
assertSelection,
clearEditor,
focusEditor,
html,
initialize,
pasteFromClipboard,
test,
} from '../utils/index.mjs';

Expand All @@ -21,11 +24,17 @@ test.describe('MaxLength', () => {
);
test(`can restrict the text to specified length`, async ({page}) => {
await focusEditor(page);

await page.keyboard.type(
'lorem ipsum dolor sit amet, consectetuer adipiscing elit',
);

await assertSelection(page, {
anchorOffset: 30,
anchorPath: [0, 0, 0],
focusOffset: 30,
focusPath: [0, 0, 0],
});

await assertHTML(
page,
html`
Expand All @@ -38,7 +47,6 @@ test.describe('MaxLength', () => {
);

await page.keyboard.press('ArrowRight');

await page.keyboard.type('Some more text');

await assertHTML(
Expand All @@ -52,4 +60,69 @@ test.describe('MaxLength', () => {
`,
);
});

test(`can restrict pasted text to specified length`, async ({page}) => {
await focusEditor(page);
await pasteFromClipboard(page, {
'text/plain': 'lorem ipsum dolor sit amet, consectetuer adipiscing elit',
});

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">lorem ipsum dolor sit amet, co</span>
</p>
`,
);
});

test(`can restrict emojis on boundaries`, async ({page}) => {
await pasteFromClipboard(page, {
'text/plain': 'lorem ipsum dolor sit amet, consectetur adipiscing elit',
});
await page.keyboard.press('Backspace');
await page.keyboard.type('💏');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">lorem ipsum dolor sit amet, c</span>
</p>
`,
);

await page.keyboard.press('Backspace');
await page.keyboard.type('💏');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">lorem ipsum dolor sit amet, 💏</span>
</p>
`,
);

await clearEditor(page);
await page.keyboard.type('👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻</span>
</p>
`,
);
});
});

2 comments on commit e5b574d

@vercel
Copy link

@vercel vercel bot commented on e5b574d Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website-new

lexical-fbopensource.vercel.app
lexical.dev
lexical-git-main-fbopensource.vercel.app
www.lexical.dev
lexicaljs.org
lexicaljs.com

@vercel
Copy link

@vercel vercel bot commented on e5b574d Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground.vercel.app
lexical-playground-fbopensource.vercel.app
lexical-playground-git-main-fbopensource.vercel.app
playground.lexical.dev

Please sign in to comment.