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.
9 import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical';
10 import {initializeUnitTest} from 'lexical/__tests__/utils';
12 export function $rootTextContent(): string {
13 const root = $getRoot();
15 return root.getTextContent();
18 export function $isRootTextContentEmpty(
19 isEditorComposing: boolean,
22 if (isEditorComposing) {
26 let text = $rootTextContent();
35 export function $isRootTextContentEmptyCurry(
36 isEditorComposing: boolean,
39 return () => $isRootTextContentEmpty(isEditorComposing, trim);
42 describe('LexicalRootHelpers tests', () => {
43 initializeUnitTest((testEnv) => {
44 it('textContent', async () => {
45 const editor = testEnv.editor;
47 expect(editor.getEditorState().read($rootTextContent)).toBe('');
49 await editor.update(() => {
50 const root = $getRoot();
51 const paragraph = $createParagraphNode();
52 const text = $createTextNode('foo');
53 root.append(paragraph);
54 paragraph.append(text);
56 expect($rootTextContent()).toBe('foo');
59 expect(editor.getEditorState().read($rootTextContent)).toBe('foo');
62 it('isBlank', async () => {
63 const editor = testEnv.editor;
68 .read($isRootTextContentEmptyCurry(editor.isComposing())),
71 await editor.update(() => {
72 const root = $getRoot();
73 const paragraph = $createParagraphNode();
74 const text = $createTextNode('foo');
75 root.append(paragraph);
76 paragraph.append(text);
78 expect($isRootTextContentEmpty(editor.isComposing())).toBe(false);
84 .read($isRootTextContentEmptyCurry(editor.isComposing())),