-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathrenderTableRow.test.ts
More file actions
69 lines (60 loc) · 2.48 KB
/
renderTableRow.test.ts
File metadata and controls
69 lines (60 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { renderTableRow } from './renderTableRow.js';
const renderTableCellMock = vi.fn(() => ({ cellElement: document.createElement('div') }));
vi.mock('./renderTableCell.js', () => ({
renderTableCell: (args: unknown) => renderTableCellMock(args),
}));
describe('renderTableRow', () => {
let doc: Document;
let container: HTMLElement;
beforeEach(() => {
doc = document.implementation.createHTMLDocument('table-row');
container = doc.createElement('div');
renderTableCellMock.mockClear();
});
const createDeps = (overrides: Record<string, unknown> = {}) => ({
doc,
container,
rowIndex: 3,
y: 0,
rowMeasure: {
height: 20,
cells: [{ width: 100, height: 20, gridColumnStart: 0, colSpan: 1, rowSpan: 1 }],
},
row: {
id: 'row-1',
cells: [{ id: 'cell-1', blocks: [{ kind: 'paragraph', id: 'p1', runs: [] }] }],
},
totalRows: 10,
tableBorders: {
top: { style: 'single', width: 1, color: '#000000' },
bottom: { style: 'single', width: 1, color: '#000000' },
left: { style: 'single', width: 1, color: '#000000' },
right: { style: 'single', width: 1, color: '#000000' },
insideH: { style: 'single', width: 1, color: '#111111' },
insideV: { style: 'single', width: 1, color: '#222222' },
},
columnWidths: [100],
allRowHeights: [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
tableIndent: 0,
context: { sectionIndex: 0, pageIndex: 0, columnIndex: 0 },
renderLine: () => doc.createElement('div'),
applySdtDataset: () => {},
cellSpacingPx: 6,
...overrides,
});
it('does not draw insideH on top edge for continuation fragments with cell spacing', () => {
renderTableRow(createDeps({ continuesFromPrev: true }) as never);
expect(renderTableCellMock).toHaveBeenCalledTimes(1);
const call = renderTableCellMock.mock.calls[0][0] as { borders?: { top?: unknown; bottom?: unknown } };
expect(call.borders?.top).toBeUndefined();
expect(call.borders?.bottom).toBeDefined();
});
it('does not draw insideH on bottom edge before continuation with cell spacing', () => {
renderTableRow(createDeps({ continuesOnNext: true }) as never);
expect(renderTableCellMock).toHaveBeenCalledTimes(1);
const call = renderTableCellMock.mock.calls[0][0] as { borders?: { top?: unknown; bottom?: unknown } };
expect(call.borders?.top).toBeDefined();
expect(call.borders?.bottom).toBeUndefined();
});
});