forked from facebook/lexical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tables): Add missing paragraph node when copying empty cells from…
… external resources (facebook#5670)
- Loading branch information
1 parent
0acc1f5
commit 9f84191
Showing
4 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/lexical-table/src/__tests__/unit/LexicalTableCellNode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import {$createTableCellNode, TableCellHeaderStates} from '@lexical/table'; | ||
import {initializeUnitTest} from 'lexical/src/__tests__/utils'; | ||
|
||
const editorConfig = Object.freeze({ | ||
namespace: '', | ||
theme: { | ||
tableCell: 'test-table-cell-class', | ||
}, | ||
}); | ||
|
||
describe('LexicalTableCellNode tests', () => { | ||
initializeUnitTest((testEnv) => { | ||
test('TableCellNode.constructor', async () => { | ||
const {editor} = testEnv; | ||
|
||
await editor.update(() => { | ||
const cellNode = $createTableCellNode(TableCellHeaderStates.NO_STATUS); | ||
|
||
expect(cellNode).not.toBe(null); | ||
}); | ||
|
||
expect(() => | ||
$createTableCellNode(TableCellHeaderStates.NO_STATUS), | ||
).toThrow(); | ||
}); | ||
|
||
test('TableCellNode.createDOM()', async () => { | ||
const {editor} = testEnv; | ||
|
||
await editor.update(() => { | ||
const cellNode = $createTableCellNode(TableCellHeaderStates.NO_STATUS); | ||
expect(cellNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<td class="${editorConfig.theme.tableCell}"></td>`, | ||
); | ||
|
||
const headerCellNode = $createTableCellNode(TableCellHeaderStates.ROW); | ||
expect(headerCellNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<th class="${editorConfig.theme.tableCell}"></th>`, | ||
); | ||
|
||
const colSpan = 2; | ||
const cellWithRowSpanNode = $createTableCellNode( | ||
TableCellHeaderStates.NO_STATUS, | ||
colSpan, | ||
); | ||
expect(cellWithRowSpanNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<td colspan="${colSpan}" class="${editorConfig.theme.tableCell}"></td>`, | ||
); | ||
|
||
const cellWidth = 200; | ||
const cellWithCustomWidthNode = $createTableCellNode( | ||
TableCellHeaderStates.NO_STATUS, | ||
undefined, | ||
cellWidth, | ||
); | ||
expect(cellWithCustomWidthNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<td style="width: ${cellWidth}px;" class="${editorConfig.theme.tableCell}"></td>`, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/lexical-table/src/__tests__/unit/LexicalTableRowNode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import {$createTableRowNode} from '@lexical/table'; | ||
import {initializeUnitTest} from 'lexical/src/__tests__/utils'; | ||
|
||
const editorConfig = Object.freeze({ | ||
namespace: '', | ||
theme: { | ||
tableRow: 'test-table-row-class', | ||
}, | ||
}); | ||
|
||
describe('LexicalTableRowNode tests', () => { | ||
initializeUnitTest((testEnv) => { | ||
test('TableRowNode.constructor', async () => { | ||
const {editor} = testEnv; | ||
|
||
await editor.update(() => { | ||
const rowNode = $createTableRowNode(); | ||
|
||
expect(rowNode).not.toBe(null); | ||
}); | ||
|
||
expect(() => $createTableRowNode()).toThrow(); | ||
}); | ||
|
||
test('TableRowNode.createDOM()', async () => { | ||
const {editor} = testEnv; | ||
|
||
await editor.update(() => { | ||
const rowNode = $createTableRowNode(); | ||
expect(rowNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<tr class="${editorConfig.theme.tableRow}"></tr>`, | ||
); | ||
|
||
const rowHeight = 36; | ||
const rowWithCustomHeightNode = $createTableRowNode(36); | ||
expect(rowWithCustomHeightNode.createDOM(editorConfig).outerHTML).toBe( | ||
`<tr style="height: ${rowHeight}px;" class="${editorConfig.theme.tableRow}"></tr>`, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |