-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbookmarks.test.js
More file actions
73 lines (68 loc) · 2.19 KB
/
bookmarks.test.js
File metadata and controls
73 lines (68 loc) · 2.19 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
70
71
72
73
import { describe, expect, test } from 'vitest';
import * as P from '@react-pdf/primitives';
import PDFDocument from '../../../pdfkit/lib/pdfkit';
import render from '../../src/index';
/**
* Original issue for this test was that all bookmarks incorrectly
* pointed to the last page rather than the page for which they were created.
*/
describe('operations bookmarks', () => {
test('should create 3 pages with unique bookmarks', () => {
const ctx = new PDFDocument({ autoFirstPage: false });
const BOOKMARK1 = 'Bookmark 1';
const BOOKMARK2 = 'Bookmark 2';
const BOOKMARK3 = 'Bookmark 3';
const p1 = { bookmark: { ref: 1, title: BOOKMARK1 } };
const p2 = { bookmark: { ref: 2, title: BOOKMARK2 } };
const p3 = { bookmark: { ref: 3, title: BOOKMARK3 } };
const box = { left: 0, top: 0, width: 100, height: 100, x: 0, y: 0 };
const makeLine = (pageNumber) => {
const line = {
ascent: 16.2,
box,
descent: 0,
height: 100,
overflowLeft: 0,
overflowRight: 0,
runs: [],
string: `Page ${pageNumber}`,
decorationLines: [],
};
return line;
};
const doc = {
type: P.Document,
children: [
{
children: [{ lines: [makeLine(1)], box, props: p1, type: P.Text }],
box,
type: P.Page,
},
{
children: [{ lines: [makeLine(2)], box, props: p2, type: P.Text }],
box,
type: P.Page,
},
{
children: [{ lines: [makeLine(3)], box, props: p3, type: P.Text }],
box,
type: P.Page,
},
],
};
render(ctx, doc);
const kids = ctx._root.data.Pages.data.Kids;
expect(kids).toHaveLength(3);
// We expect unique ids
expect(
kids[0].id !== kids[1].id &&
kids[0].id !== kids[2].id &&
kids[1].id !== kids[2].id,
).toBe(true);
const children = ctx._root.document.outline.children;
expect(children).toHaveLength(3);
expect(children[0].outlineData.Title.toString()).toBe(BOOKMARK1);
expect(children[1].outlineData.Title.toString()).toBe(BOOKMARK2);
expect(children[2].outlineData.Title.toString()).toBe(BOOKMARK3);
});
});