pdfkit/tests/unit/table.spec.js
Jake Holland 033ba3426b
Add support for tables (#1577)
* Add page size utilities

- Added page.contentWidth
- Added page.contentHeight

* Add table support

- Tables support cell customization (including colors)
- Tables also support rotatable text (with alignment support)
- Tables have accessibility support

* chore: fix code generation context

- code generation now respects the current document positioning to allow use of page dependent operations

* chore: remove comments from build

* removed unnecessary config optimisations

* Optimize table minification

* Performance improvements to tables

* Improve font handling in tables
2025-02-24 07:49:25 -03:00

38 lines
1.2 KiB
JavaScript

import PDFDocument from '../../lib/document';
import PDFTable from '../../lib/table';
import { deepMerge } from '../../lib/table/utils';
describe('table', () => {
test('created', () => {
const document = new PDFDocument();
expect(document.table()).toBeInstanceOf(PDFTable);
expect(document.table({ data: [] })).toBe(document);
});
test('row', () => {
const document = new PDFDocument();
const table = document.table();
table.row(['A', 'B', 'C']);
expect(table._columnWidths.length).toBe(3);
});
});
describe('utils', () => {
describe('deepMerge', () => {
test.each([
[{ a: 'hello' }, { b: 'world' }, { a: 'hello', b: 'world' }],
[{ a: 'hello' }, { a: 'world' }, { a: 'world' }],
[{}, { a: 'hello' }, { a: 'hello' }],
[{ a: 'hello' }, undefined, { a: 'hello' }],
[undefined, undefined, undefined],
[1, 2, 1],
[1, {}, 1],
[{ a: 'hello' }, { a: {} }, { a: 'hello' }],
[{ a: { b: 'hello' } }, { a: { b: 'world' } }, { a: { b: 'world' } }],
])('%o -> %o', function () {
const opts = Array.from(arguments);
const expected = opts.splice(-1, 1)[0];
expect(deepMerge(...opts)).toEqual(expected);
});
});
});