forked from parallax/jsPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard.spec.js
More file actions
106 lines (92 loc) · 3.12 KB
/
Copy pathstandard.spec.js
File metadata and controls
106 lines (92 loc) · 3.12 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict'
/* global describe, it, expect, jsPDF, comparePdf */
/**
* Standard spec tests
*
* These tests return the datauristring so that reference files can be generated.
* We compare the exact output.
*/
describe('Standard Text', () => {
it('should load', () => {
// assertions here]
expect(typeof jsPDF).toBe('function')
})
it('should generate blank page', () => {
const doc = jsPDF()
comparePdf(doc.output(), 'blank.pdf', 'text')
})
it('should allow text insertion', () => {
const doc = jsPDF()
doc.text(10, 10, 'This is a test!')
comparePdf(doc.output(), 'standard.pdf', 'text')
})
it('should allow text insertion at an angle', () => {
const doc = jsPDF()
doc.text(20, 20, 'This is a test!', null, 20)
comparePdf(doc.output(), 'angle.pdf', 'text')
})
it('should render different font faces', () => {
const doc = jsPDF()
doc.text(20, 20, 'This is the default font.')
doc.setFont('courier')
doc.setFontType('normal')
doc.text(20, 30, 'This is courier normal.')
doc.setFont('times')
doc.setFontType('italic')
doc.text(20, 40, 'This is times italic.')
doc.setFont('helvetica')
doc.setFontType('bold')
doc.text(20, 50, 'This is helvetica bold.')
doc.setFont('courier')
doc.setFontType('bolditalic')
doc.text(20, 60, 'This is courier bolditalic.')
comparePdf(doc.output(), 'font-faces.pdf', 'text')
})
it('should support multiple pages', () => {
const doc = jsPDF()
doc.text(20, 20, 'Hello world!')
doc.text(20, 30, 'This is client-side JavaScript, pumping out a PDF.')
doc.addPage()
doc.text(20, 20, 'Do you like that?')
comparePdf(doc.output(), 'two-page.pdf', 'text')
})
it('should support different size fonts', () => {
const doc = jsPDF()
doc.setFontSize(22)
doc.text(20, 20, 'This is a title')
doc.setFontSize(16)
doc.text(20, 30, 'This is some normal sized text underneath.')
comparePdf(doc.output(), 'different-sizes.pdf', 'text')
})
it('should support multiline text', () => {
const doc = jsPDF()
doc.text(20, 20, `This is a line
break`)
comparePdf(doc.output(), 'line-break.pdf', 'text')
})
it('should support multiline text', () => {
const doc = jsPDF()
doc.text('Stroke on', 20, 20, { stroke: true })
doc.text('Stroke on', 20, 40, { stroke: true })
doc.text('Stroke off', 20, 60, { stroke: false })
doc.text('Stroke on', 20, 80, { stroke: true })
comparePdf(doc.output(), 'stroke.pdf', 'text')
})
it('should support multiline text', () => {
const doc = jsPDF()
doc.text('Stroke on', 20, 20, { stroke: true })
doc.text('Stroke on', 20, 40, { stroke: true })
doc.text('Stroke off', 20, 60, { stroke: false })
doc.text('Stroke on', 20, 80, { stroke: true })
comparePdf(doc.output(), 'stroke.pdf', 'text')
})
// @TODO: Implement passing color as a name
it('should display two red lines of text', () => {
const doc = jsPDF()
doc.setTextColor('#FF0000')
doc.text('Red on', 20, 20)
doc.setTextColor(255, 0, 0)
doc.text('Red on', 20, 40)
comparePdf(doc.output(), 'color.pdf', 'text')
})
})