Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions packages/core/src/api/blockManipulation/tables/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,140 @@ const tableWithColspansAndRowspans = {
any
>;

const invalidTableShape = {
type: "table",
id: "table-0",
props: {
textColor: "default",
},
content: {
type: "tableContent",
columnWidths: [100, 100],
rows: [
{
cells: [
{
type: "tableCell",
content: [
{
type: "text",
text: "Table Cell",
styles: {},
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
},
{
cells: [
{
type: "tableCell",
content: [
{
type: "text",
text: "Table Cell",
styles: {},
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
},
{
cells: [
{
type: "tableCell",
content: [
{
type: "text",
text: "Table Cell",
styles: {},
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
{
type: "tableCell",
content: [
{
type: "text",
text: "Table Cell",
styles: {},
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
props: {
colspan: 2,
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
{
type: "tableCell",
content: [
{
type: "text",
text: "Table x",
styles: {},
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
props: {
backgroundColor: "default",
textColor: "default",
textAlignment: "left",
},
},
],
},
],
},
children: [],
} satisfies Block<
{
table: DefaultBlockSchema["table"];
},
any,
any
>;

/**
* Normal table
* | 1-1 | 1-2 | 1-3 | 1-4 |
Expand Down Expand Up @@ -882,6 +1016,12 @@ describe("Test getAbsoluteTableCellIndices", () => {
cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[2],
});
});

it("should not crash at an invalid table shape", () => {
expect(() =>
getAbsoluteTableCells({ row: 2, col: 2 }, invalidTableShape),
).not.toThrow();
});
});

describe("Test getRelativeTableCellIndices", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/blockManipulation/tables/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ export function getAbsoluteTableCells(
} {
for (let r = 0; r < occupancyGrid.length; r++) {
for (let c = 0; c < occupancyGrid[r].length; c++) {
// console.log(r, c, occupancyGrid);
const cell = occupancyGrid[r][c];
if (
cell &&
cell.row === relativeCellIndices.row &&
cell.col === relativeCellIndices.col
) {
Expand Down
Loading