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 {$createTableCellNode, TableCellHeaderStates} from '@lexical/table';
10 import {initializeUnitTest} from 'lexical/src/__tests__/utils';
12 const editorConfig = Object.freeze({
15 tableCell: 'test-table-cell-class',
19 describe('LexicalTableCellNode tests', () => {
20 initializeUnitTest((testEnv) => {
21 test('TableCellNode.constructor', async () => {
22 const {editor} = testEnv;
24 await editor.update(() => {
25 const cellNode = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
27 expect(cellNode).not.toBe(null);
31 $createTableCellNode(TableCellHeaderStates.NO_STATUS),
35 test('TableCellNode.createDOM()', async () => {
36 const {editor} = testEnv;
38 await editor.update(() => {
39 const cellNode = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
40 expect(cellNode.createDOM(editorConfig).outerHTML).toBe(
41 `<td class="${editorConfig.theme.tableCell}"></td>`,
44 const headerCellNode = $createTableCellNode(TableCellHeaderStates.ROW);
45 expect(headerCellNode.createDOM(editorConfig).outerHTML).toBe(
46 `<th class="${editorConfig.theme.tableCell}"></th>`,
50 const cellWithRowSpanNode = $createTableCellNode(
51 TableCellHeaderStates.NO_STATUS,
54 expect(cellWithRowSpanNode.createDOM(editorConfig).outerHTML).toBe(
55 `<td colspan="${colSpan}" class="${editorConfig.theme.tableCell}"></td>`,
58 const cellWidth = 200;
59 const cellWithCustomWidthNode = $createTableCellNode(
60 TableCellHeaderStates.NO_STATUS,
64 expect(cellWithCustomWidthNode.createDOM(editorConfig).outerHTML).toBe(
65 `<td style="width: ${cellWidth}px;" class="${editorConfig.theme.tableCell}"></td>`,