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