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
185 lines (161 loc) · 5.14 KB
/
Copy pathstandard.spec.js
File metadata and controls
185 lines (161 loc) · 5.14 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'use strict'
/* global describe, xit, it, jsPDF, comparePdf, jasmine, expect */
/**
* Standard spec tests
*
* These tests return the datauristring so that reference files can be generated.
* We compare the exact output.
*/
describe('jsPDF init options', () => {
/**
* @TODO: this document doesn't work, needs fixing, see #881
*/
it('should make a compressed document', () => {
const doc = jsPDF({
compress: true
})
doc.text(10, 10, 'This is a test')
doc.output()
// comparePdf(doc.output(), 'compress.pdf', 'init')
})
// @TODO: Make sure this is what we want
it('should silently fail compressing when adler32cs is not present', () => {
delete window.adler32cs
const doc = jsPDF({
compress: true
})
doc.text(10, 10, 'This is a test')
doc.output()
})
it('should make a landscape document', () => {
const doc = jsPDF({
orientation: 'landscape'
})
doc.text(10, 10, 'This is a test!')
comparePdf(doc.output(), 'landscape.pdf', 'init')
})
it('should set document properties', () => {
const doc = jsPDF()
doc.setProperties({
title: 'Title',
subject: 'This is the subject',
author: 'James Hall',
keywords: 'generated, javascript, parallax',
creator: 'jsPDF'
})
comparePdf(doc.output(), 'properties.pdf', 'init')
})
/**
* @TODO: Fix 'undefined' see #882
*/
it('should return font list', () => {
const doc = jsPDF()
const fontList = doc.getFontList()
expect(fontList).toEqual({
helvetica: ['normal', 'bold', 'italic', 'bolditalic'],
Helvetica: ['', 'Bold', 'Oblique', 'BoldOblique'],
courier: ['normal', 'bold', 'italic', 'bolditalic'],
Courier: ['', 'Bold', 'Oblique', 'BoldOblique'],
times: ['normal', 'bold', 'italic', 'bolditalic'],
Times: ['Roman', 'Bold', 'Italic', 'BoldItalic'],
zapfdingbats: ['undefined'],
ZapfDingbats: ['']
})
})
it('should return an ArrayBuffer', () => {
const doc = jsPDF()
expect(doc.output('arraybuffer')).toEqual(jasmine.any(ArrayBuffer))
})
it('should return a Blob', () => {
const doc = jsPDF()
expect(doc.output('blob')).toEqual(jasmine.any(window.Blob))
})
it('should return a bloburl', () => {
const doc = jsPDF()
expect(doc.output('bloburl')).toContain('blob:')
expect(doc.output('bloburi')).toContain('blob:')
})
it('should return a datauri', () => {
const doc = jsPDF()
expect(doc.output('datauristring')).toContain('data:')
expect(doc.output('dataurlstring')).toContain('data:')
})
// @TODO Figure out a way to test this
xit('should return a datauri', () => {
const doc = jsPDF()
doc.output('datauri')
window.stop()
doc.output('dataurl')
window.stop()
})
it('should open a new window', () => {
if (navigator.userAgent.indexOf('Trident') !== -1) {
console.warn('Skipping IE for new window test')
return
}
const doc = jsPDF()
doc.text(10, 10, 'This is a test')
doc.output('dataurlnewwindow')
// expect(doc.output('dataurlnewwindow').Window).toEqual(jasmine.any(Function))
})
const renderBoxes = (doc) => {
for (let i = 0; i < 100; i++) {
doc.rect(0, 0, i, i)
}
}
it('should render text 100pt away from the top left', () => {
const doc = jsPDF('portrait', 'pt')
renderBoxes(doc)
comparePdf(doc.output(), 'pt.pdf', 'init')
})
it('should render text 100pt away from the top left', () => {
const doc = jsPDF('portrait', 'mm')
renderBoxes(doc)
comparePdf(doc.output(), 'mm.pdf', 'init')
})
it('should render text 100pt away from the top left', () => {
const doc = jsPDF('portrait', 'cm')
renderBoxes(doc)
comparePdf(doc.output(), 'cm.pdf', 'init')
})
it('should render text 2in away from the top left', () => {
const doc = jsPDF('portrait', 'in')
renderBoxes(doc)
comparePdf(doc.output(), 'in.pdf', 'init')
})
it('should render text 2px away from the top left', () => {
const doc = jsPDF('portrait', 'px')
renderBoxes(doc)
comparePdf(doc.output(), 'px.pdf', 'init')
})
it('should render text 2px away from the top left', () => {
const doc = jsPDF('portrait', 'pc')
renderBoxes(doc)
comparePdf(doc.output(), 'pc.pdf', 'init')
})
it('should render text 2px away from the top left with alternative syntax', () => {
const doc = jsPDF({ unit: 'pc' })
renderBoxes(doc)
comparePdf(doc.output(), 'pc.pdf', 'init')
})
it('should render text 2em away from the top left with alternative syntax', () => {
const doc = jsPDF({ unit: 'em' })
renderBoxes(doc)
comparePdf(doc.output(), 'em.pdf', 'init')
})
it('should render text 2ex away from the top left with alternative syntax', () => {
const doc = jsPDF({ unit: 'ex' })
renderBoxes(doc)
comparePdf(doc.output(), 'ex.pdf', 'init')
})
it('should warn me about an invalid unit', () => {
expect(() => {
jsPDF({ unit: 'invalid' })
}).toThrow('Invalid unit: invalid')
})
it('should warn me about an invalid unit when passed as second argument', () => {
expect(() => {
jsPDF('portrait', 'invalid')
}).toThrow('Invalid unit: invalid')
})
})