Skip to content

Commit 66e60a6

Browse files
committed
fix: extend test cases and remove unused code
1 parent f119af4 commit 66e60a6

2 files changed

Lines changed: 35 additions & 20 deletions

File tree

packages/layout-engine/painters/dom/src/table/renderTableCell.test.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,23 +1112,6 @@ describe('renderTableCell', () => {
11121112
});
11131113

11141114
describe('spacing.before margin-top rendering', () => {
1115-
const baseMeasure: ParagraphMeasure = {
1116-
kind: 'paragraph',
1117-
lines: [
1118-
{
1119-
fromRun: 0,
1120-
fromChar: 0,
1121-
toRun: 0,
1122-
toChar: 10,
1123-
width: 100,
1124-
ascent: 12,
1125-
descent: 4,
1126-
lineHeight: 20,
1127-
},
1128-
],
1129-
totalHeight: 20,
1130-
};
1131-
11321115
it('applies margin-top only for positive spacing.before', () => {
11331116
const para1: ParagraphBlock = {
11341117
kind: 'paragraph',
@@ -1152,7 +1135,7 @@ describe('renderTableCell', () => {
11521135
};
11531136

11541137
const cellMeasure: TableCellMeasure = {
1155-
blocks: [baseMeasure, baseMeasure, baseMeasure],
1138+
blocks: [paragraphMeasure, paragraphMeasure, paragraphMeasure],
11561139
width: 120,
11571140
height: 80,
11581141
gridColumnStart: 0,
@@ -1250,6 +1233,40 @@ describe('renderTableCell', () => {
12501233
const fullWrapper = (fullCell.firstElementChild as HTMLElement).firstElementChild as HTMLElement;
12511234
expect(fullWrapper.style.marginTop).toBe('11px');
12521235
});
1236+
1237+
it('applies both margin-top and margin-bottom when paragraph has spacing.before and spacing.after', () => {
1238+
const para: ParagraphBlock = {
1239+
kind: 'paragraph',
1240+
id: 'para-before-and-after',
1241+
runs: [{ text: 'Both spacing', fontFamily: 'Arial', fontSize: 16 }],
1242+
attrs: { spacing: { before: 12, after: 18 } },
1243+
};
1244+
1245+
const cellMeasure: TableCellMeasure = {
1246+
blocks: [paragraphMeasure],
1247+
width: 120,
1248+
height: 60,
1249+
gridColumnStart: 0,
1250+
colSpan: 1,
1251+
rowSpan: 1,
1252+
};
1253+
1254+
const cell: TableCell = {
1255+
id: 'cell-before-and-after',
1256+
blocks: [para],
1257+
attrs: {},
1258+
};
1259+
1260+
const { cellElement } = renderTableCell({
1261+
...createBaseDeps(),
1262+
cellMeasure,
1263+
cell,
1264+
});
1265+
1266+
const paraWrapper = (cellElement.firstElementChild as HTMLElement).firstElementChild as HTMLElement;
1267+
expect(paraWrapper.style.marginTop).toBe('12px');
1268+
expect(paraWrapper.style.marginBottom).toBe('18px');
1269+
});
12531270
});
12541271

12551272
describe('list marker rendering', () => {

packages/layout-engine/painters/dom/src/table/renderTableCell.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,6 @@ export const renderTableCell = (deps: TableCellRenderDependencies): TableCellRen
11121112
const effectiveCellWidth = cellWidth ?? cellMeasure.width;
11131113
const contentWidthPx = Math.max(0, effectiveCellWidth - paddingLeft - paddingRight);
11141114
const contentHeightPx = Math.max(0, rowHeight - paddingTop - paddingBottom);
1115-
const paragraphTopById = new Map<string, number>();
11161115
let flowCursorY = 0;
11171116
const anchoredBlocks: Array<{ block: ImageBlock | DrawingBlock; measure: ImageMeasure | DrawingMeasure }> = [];
11181117
const renderedLines: RenderedLineInfo[] = [];
@@ -1350,7 +1349,6 @@ export const renderTableCell = (deps: TableCellRenderDependencies): TableCellRen
13501349
paraWrapper.style.marginTop = `${spacingBefore}px`;
13511350
flowCursorY += spacingBefore;
13521351
}
1353-
paragraphTopById.set(block.id, flowCursorY);
13541352

13551353
// Calculate height of rendered content for proper block accumulation
13561354
let renderedHeight = 0;

0 commit comments

Comments
 (0)