Skip to content

Commit ec7e835

Browse files
authored
Merge pull request #3047 from HackbrettXXX/fix-instable-encryption-tests
Fix instable tests
2 parents 7403adb + 6e9ce29 commit ec7e835

File tree

2 files changed

+70
-83
lines changed

2 files changed

+70
-83
lines changed

test/specs/encryption.spec.js

+10-21
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,37 @@
99
describe("Core: Standard Encryption", () => {
1010
beforeAll(loadGlobals);
1111
it("should allow text insertion", () => {
12-
const doc = jsPDF({
12+
const doc = jsPDF({
1313
floatPrecision: 2,
1414
encryption: {
1515
userPassword: "password"
1616
}
1717
});
1818
doc.__private__.setFileId("0000000000000000000000000BADFACE");
19+
doc.__private__.setCreationDate("D:19871210000000+00'00'");
1920
doc.text(10, 10, "This is a test!");
2021
comparePdf(doc.output(), "encrypted_standard.pdf", "encryption");
21-
doc.internal.encryption = null;
22-
doc.internal.encryptionOptions = null;
2322
});
2423
it("should be printable", () => {
25-
const doc = jsPDF({
24+
const doc = jsPDF({
2625
floatPrecision: 2,
2726
encryption: {
2827
userPassword: "password",
2928
userPermissions: ["print"]
3029
}
3130
});
3231
doc.__private__.setFileId("0000000000000000000000000BADFACE");
32+
doc.__private__.setCreationDate("D:19871210000000+00'00'");
3333
doc.text(10, 10, "This is a test!");
3434
comparePdf(doc.output(), "encrypted_printable.pdf", "encryption");
35-
doc.internal.encryption = null;
36-
doc.internal.encryptionOptions = null;
3735
});
3836
it("should display forms properly", () => {
3937
var doc = new jsPDF({
4038
floatPrecision: 2,
4139
encryption: {}
4240
});
4341
doc.__private__.setFileId("0000000000000000000000000BADFACE");
42+
doc.__private__.setCreationDate("D:19871210000000+00'00'");
4443
var {
4544
ComboBox,
4645
ListBox,
@@ -49,7 +48,7 @@ describe("Core: Standard Encryption", () => {
4948
TextField,
5049
PasswordField,
5150
RadioButton,
52-
Appearance,
51+
Appearance
5352
} = jsPDF.AcroForm;
5453

5554
doc.setFontSize(12);
@@ -112,14 +111,9 @@ describe("Core: Standard Encryption", () => {
112111
var radioButton3 = radioGroup.createOption("Test3");
113112
radioButton3.Rect = [50, 190, 20, 10];
114113
radioGroup.setAppearance(Appearance.RadioButton.Cross);
115-
116-
comparePdf(
117-
doc.output(),
118-
"encrypted_withAcroForm.pdf",
119-
"encryption"
120-
);
121114

122-
})
115+
comparePdf(doc.output(), "encrypted_withAcroForm.pdf", "encryption");
116+
});
123117
it("colortype_3_indexed_single_colour_alpha_4_bit_png", () => {
124118
var colortype_3_indexed_single_colour_alpha_4_bit_png =
125119
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAG1BMVEX/////AAD/pQD//wAA/wAAgAAAgIAAAP+BAIC08EFzAAAAAXRSTlMAQObYZgAAAJtJREFUCB0BkABv/wAREQAAAAAAAAAiIhEQAAAAAAAzMyIhEAAAAABERDMyIQAAAABVVUQzIhAAAABmZlVEMyEAAAB3d2ZVQzIQAACIh3dlVDIhAAAACId2VUMhAAAAAAiHZUMyEAAAAACHdlQyEAAAAAAIdlQyEAAAAAAId2VDIQAAAAAAh2VDIQAAAAAAh2VDIQAAAAAAh2VDIWfgFTHZzlYNAAAAAElFTkSuQmCC";
@@ -134,6 +128,7 @@ describe("Core: Standard Encryption", () => {
134128
}
135129
});
136130
doc.__private__.setFileId("0000000000000000000000000BADFACE");
131+
doc.__private__.setCreationDate("D:19871210000000+00'00'");
137132
doc.addImage(
138133
colortype_3_indexed_single_colour_alpha_4_bit_png,
139134
"PNG",
@@ -144,12 +139,6 @@ describe("Core: Standard Encryption", () => {
144139
undefined,
145140
undefined
146141
);
147-
comparePdf(
148-
doc.output(),
149-
"encrypted_withImage.pdf",
150-
"encryption"
151-
);
152-
doc.internal.encryption = null;
153-
doc.internal.encryptionOptions = null;
142+
comparePdf(doc.output(), "encrypted_withImage.pdf", "encryption");
154143
});
155144
});

test/specs/putTotalPages.spec.js

+60-62
Original file line numberDiff line numberDiff line change
@@ -41,91 +41,89 @@ describe("Module: putTotalPages", () => {
4141

4242
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
4343
});
44-
});
45-
46-
it("customfont with encoding without passing fontWeight", () => {
47-
var PTSans = loadBinaryResource("reference/PTSans.ttf");
48-
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
49-
var totalPagesExp = "{totalPages}";
5044

51-
doc.addFileToVFS("PTSans.ttf", PTSans);
52-
doc.addFont("PTSans.ttf", "PTSans", "normal", "Identity-H");
53-
54-
doc.setFont("PTSans");
45+
it("customfont with encoding without passing fontWeight", () => {
46+
var PTSans = loadBinaryResource("reference/PTSans.ttf");
47+
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
48+
var totalPagesExp = "{totalPages}";
5549

56-
doc.text(10, 10, "Page 1 of {totalPages}");
57-
doc.addPage();
50+
doc.addFileToVFS("PTSans.ttf", PTSans);
51+
doc.addFont("PTSans.ttf", "PTSans", "normal", "Identity-H");
5852

59-
doc.text(10, 10, "Page 2 of {totalPages}");
53+
doc.setFont("PTSans");
6054

61-
if (typeof doc.putTotalPages === "function") {
62-
doc.putTotalPages(totalPagesExp);
63-
}
55+
doc.text(10, 10, "Page 1 of {totalPages}");
56+
doc.addPage();
6457

65-
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
66-
});
58+
doc.text(10, 10, "Page 2 of {totalPages}");
6759

60+
if (typeof doc.putTotalPages === "function") {
61+
doc.putTotalPages(totalPagesExp);
62+
}
6863

69-
it("customfont check without passing fontweight in setfont", () => {
70-
var PTSans = loadBinaryResource("reference/PTSans.ttf");
71-
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
72-
var totalPagesExp = "{totalPages}";
64+
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
65+
});
7366

74-
doc.addFileToVFS("PTSans.ttf", PTSans);
75-
doc.addFont("PTSans.ttf", "PTSans", "normal");
67+
it("customfont check without passing fontweight in setfont", () => {
68+
var PTSans = loadBinaryResource("reference/PTSans.ttf");
69+
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
70+
var totalPagesExp = "{totalPages}";
7671

77-
doc.setFont("PTSans",'normal');
72+
doc.addFileToVFS("PTSans.ttf", PTSans);
73+
doc.addFont("PTSans.ttf", "PTSans", "normal");
7874

79-
doc.text(10, 10, "Page 1 of {totalPages}");
80-
doc.addPage();
75+
doc.setFont("PTSans", "normal");
8176

82-
doc.text(10, 10, "Page 2 of {totalPages}");
77+
doc.text(10, 10, "Page 1 of {totalPages}");
78+
doc.addPage();
8379

84-
if (typeof doc.putTotalPages === "function") {
85-
doc.putTotalPages(totalPagesExp);
86-
}
87-
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
88-
});
80+
doc.text(10, 10, "Page 2 of {totalPages}");
8981

82+
if (typeof doc.putTotalPages === "function") {
83+
doc.putTotalPages(totalPagesExp);
84+
}
85+
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
86+
});
9087

91-
it("customfont with fontweight", () => {
92-
var PTSans = loadBinaryResource("reference/PTSans.ttf");
93-
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
94-
var totalPagesExp = "{totalPages}";
88+
it("customfont with fontweight", () => {
89+
var PTSans = loadBinaryResource("reference/PTSans.ttf");
90+
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
91+
var totalPagesExp = "{totalPages}";
9592

96-
doc.addFileToVFS("PTSans.ttf", PTSans);
97-
doc.addFont("PTSans.ttf", "PTSans", "normal",200, "Identity-H");
93+
doc.addFileToVFS("PTSans.ttf", PTSans);
94+
doc.addFont("PTSans.ttf", "PTSans", "normal", 200, "Identity-H");
9895

99-
doc.setFont("PTSans",'normal',200);
96+
doc.setFont("PTSans", "normal", 200);
10097

101-
doc.text(10, 10, "Page 1 of {totalPages}");
102-
doc.addPage();
98+
doc.text(10, 10, "Page 1 of {totalPages}");
99+
doc.addPage();
103100

104-
doc.text(10, 10, "Page 2 of {totalPages}");
101+
doc.text(10, 10, "Page 2 of {totalPages}");
105102

106-
if (typeof doc.putTotalPages === "function") {
107-
doc.putTotalPages(totalPagesExp);
108-
}
109-
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
110-
});
103+
if (typeof doc.putTotalPages === "function") {
104+
doc.putTotalPages(totalPagesExp);
105+
}
106+
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
107+
});
111108

112-
it("customfont with samevalue in fontweight and fontstyle ", () => {
113-
var PTSans = loadBinaryResource("reference/PTSans.ttf");
114-
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
115-
var totalPagesExp = "{totalPages}";
109+
it("customfont with samevalue in fontweight and fontstyle ", () => {
110+
var PTSans = loadBinaryResource("reference/PTSans.ttf");
111+
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
112+
var totalPagesExp = "{totalPages}";
116113

117-
doc.addFileToVFS("PTSans.ttf", PTSans);
118-
doc.addFont("PTSans.ttf", "PTSans", "normal", "normal", "Identity-H");
114+
doc.addFileToVFS("PTSans.ttf", PTSans);
115+
doc.addFont("PTSans.ttf", "PTSans", "normal", "normal", "Identity-H");
119116

120-
doc.setFont("PTSans",'normal', "normal");
117+
doc.setFont("PTSans", "normal", "normal");
121118

122-
doc.text(10, 10, "Page 1 of {totalPages}");
123-
doc.addPage();
119+
doc.text(10, 10, "Page 1 of {totalPages}");
120+
doc.addPage();
124121

125-
doc.text(10, 10, "Page 2 of {totalPages}");
122+
doc.text(10, 10, "Page 2 of {totalPages}");
126123

127-
if (typeof doc.putTotalPages === "function") {
128-
doc.putTotalPages(totalPagesExp);
129-
}
130-
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
124+
if (typeof doc.putTotalPages === "function") {
125+
doc.putTotalPages(totalPagesExp);
126+
}
127+
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
128+
});
131129
});

0 commit comments

Comments
 (0)