2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
8 import {ListItemNode, ListNode} from '@lexical/list';
9 import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
10 import {ContentEditable} from '@lexical/react/LexicalContentEditable';
11 import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
12 import {ListPlugin} from '@lexical/react/LexicalListPlugin';
13 import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin';
15 INDENT_CONTENT_COMMAND,
17 OUTDENT_CONTENT_COMMAND,
23 } from 'lexical/src/__tests__/utils';
24 import {createRoot, Root} from 'react-dom/client';
25 import * as ReactTestUtils from 'lexical/shared/react-test-utils';
28 INSERT_UNORDERED_LIST_COMMAND,
30 } from '../../../../lexical-list/src/index';
32 describe('@lexical/list tests', () => {
33 let container: HTMLDivElement;
37 container = document.createElement('div');
38 reactRoot = createRoot(container);
39 document.body.appendChild(container);
47 jest.restoreAllMocks();
50 // Shared instance across tests
51 let editor: LexicalEditor;
53 function Test(): JSX.Element {
54 function TestPlugin() {
55 // Plugin used just to get our hands on the Editor object
56 [editor] = useLexicalComposerContext();
61 <TestComposer config={{nodes: [ListNode, ListItemNode], theme: {}}}>
63 contentEditable={<ContentEditable />}
65 <div className="editor-placeholder">Enter some text...</div>
67 ErrorBoundary={LexicalErrorBoundary}
75 test('Toggle an empty list on/off', async () => {
76 ReactTestUtils.act(() => {
77 reactRoot.render(<Test key="MegaSeeds, Morty!" />);
80 await ReactTestUtils.act(async () => {
81 await editor.update(() => {
83 editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
91 contenteditable="true"
94 style="user-select: text; white-space: pre-wrap; word-break: break-word;"
95 data-lexical-editor="true">
105 await ReactTestUtils.act(async () => {
106 await editor.update(() => {
108 editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
116 contenteditable="true"
119 style="user-select: text; white-space: pre-wrap; word-break: break-word;"
120 data-lexical-editor="true">
125 <div class="editor-placeholder">Enter some text...</div>
130 test('Can create a list and indent/outdent it', async () => {
131 ReactTestUtils.act(() => {
132 reactRoot.render(<Test key="MegaSeeds, Morty!" />);
135 await ReactTestUtils.act(async () => {
136 await editor.update(() => {
138 editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
146 contenteditable="true"
149 style="user-select: text; white-space: pre-wrap; word-break: break-word;"
150 data-lexical-editor="true">
160 await ReactTestUtils.act(async () => {
161 await editor.update(() => {
163 editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
171 contenteditable="true"
174 style="user-select: text; white-space: pre-wrap; word-break: break-word;"
175 data-lexical-editor="true">
179 <li value="1"><br /></li>
187 await ReactTestUtils.act(async () => {
188 await editor.update(() => {
190 editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
198 contenteditable="true"
201 style="user-select: text; white-space: pre-wrap; word-break: break-word;"
202 data-lexical-editor="true">