Skip to content

Commit

Permalink
Merge pull request #3047 from HackbrettXXX/fix-instable-encryption-tests
Browse files Browse the repository at this point in the history
Fix instable tests
  • Loading branch information
HackbrettXXX authored Dec 24, 2020
2 parents 7403adb + 6e9ce29 commit ec7e835
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 83 deletions.
31 changes: 10 additions & 21 deletions test/specs/encryption.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@
describe("Core: Standard Encryption", () => {
beforeAll(loadGlobals);
it("should allow text insertion", () => {
const doc = jsPDF({
const doc = jsPDF({
floatPrecision: 2,
encryption: {
userPassword: "password"
}
});
doc.__private__.setFileId("0000000000000000000000000BADFACE");
doc.__private__.setCreationDate("D:19871210000000+00'00'");
doc.text(10, 10, "This is a test!");
comparePdf(doc.output(), "encrypted_standard.pdf", "encryption");
doc.internal.encryption = null;
doc.internal.encryptionOptions = null;
});
it("should be printable", () => {
const doc = jsPDF({
const doc = jsPDF({
floatPrecision: 2,
encryption: {
userPassword: "password",
userPermissions: ["print"]
}
});
doc.__private__.setFileId("0000000000000000000000000BADFACE");
doc.__private__.setCreationDate("D:19871210000000+00'00'");
doc.text(10, 10, "This is a test!");
comparePdf(doc.output(), "encrypted_printable.pdf", "encryption");
doc.internal.encryption = null;
doc.internal.encryptionOptions = null;
});
it("should display forms properly", () => {
var doc = new jsPDF({
floatPrecision: 2,
encryption: {}
});
doc.__private__.setFileId("0000000000000000000000000BADFACE");
doc.__private__.setCreationDate("D:19871210000000+00'00'");
var {
ComboBox,
ListBox,
Expand All @@ -49,7 +48,7 @@ describe("Core: Standard Encryption", () => {
TextField,
PasswordField,
RadioButton,
Appearance,
Appearance
} = jsPDF.AcroForm;

doc.setFontSize(12);
Expand Down Expand Up @@ -112,14 +111,9 @@ describe("Core: Standard Encryption", () => {
var radioButton3 = radioGroup.createOption("Test3");
radioButton3.Rect = [50, 190, 20, 10];
radioGroup.setAppearance(Appearance.RadioButton.Cross);

comparePdf(
doc.output(),
"encrypted_withAcroForm.pdf",
"encryption"
);

})
comparePdf(doc.output(), "encrypted_withAcroForm.pdf", "encryption");
});
it("colortype_3_indexed_single_colour_alpha_4_bit_png", () => {
var colortype_3_indexed_single_colour_alpha_4_bit_png =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAG1BMVEX/////AAD/pQD//wAA/wAAgAAAgIAAAP+BAIC08EFzAAAAAXRSTlMAQObYZgAAAJtJREFUCB0BkABv/wAREQAAAAAAAAAiIhEQAAAAAAAzMyIhEAAAAABERDMyIQAAAABVVUQzIhAAAABmZlVEMyEAAAB3d2ZVQzIQAACIh3dlVDIhAAAACId2VUMhAAAAAAiHZUMyEAAAAACHdlQyEAAAAAAIdlQyEAAAAAAId2VDIQAAAAAAh2VDIQAAAAAAh2VDIQAAAAAAh2VDIWfgFTHZzlYNAAAAAElFTkSuQmCC";
Expand All @@ -134,6 +128,7 @@ describe("Core: Standard Encryption", () => {
}
});
doc.__private__.setFileId("0000000000000000000000000BADFACE");
doc.__private__.setCreationDate("D:19871210000000+00'00'");
doc.addImage(
colortype_3_indexed_single_colour_alpha_4_bit_png,
"PNG",
Expand All @@ -144,12 +139,6 @@ describe("Core: Standard Encryption", () => {
undefined,
undefined
);
comparePdf(
doc.output(),
"encrypted_withImage.pdf",
"encryption"
);
doc.internal.encryption = null;
doc.internal.encryptionOptions = null;
comparePdf(doc.output(), "encrypted_withImage.pdf", "encryption");
});
});
122 changes: 60 additions & 62 deletions test/specs/putTotalPages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,91 +41,89 @@ describe("Module: putTotalPages", () => {

comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});
});

it("customfont with encoding without passing fontWeight", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";

doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal", "Identity-H");

doc.setFont("PTSans");
it("customfont with encoding without passing fontWeight", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";

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

doc.text(10, 10, "Page 2 of {totalPages}");
doc.setFont("PTSans");

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();

comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});
doc.text(10, 10, "Page 2 of {totalPages}");

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}

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

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

doc.setFont("PTSans",'normal');
doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal");

doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();
doc.setFont("PTSans", "normal");

doc.text(10, 10, "Page 2 of {totalPages}");
doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});
doc.text(10, 10, "Page 2 of {totalPages}");

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});

it("customfont with fontweight", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";
it("customfont with fontweight", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";

doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal",200, "Identity-H");
doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal", 200, "Identity-H");

doc.setFont("PTSans",'normal',200);
doc.setFont("PTSans", "normal", 200);

doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();
doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();

doc.text(10, 10, "Page 2 of {totalPages}");
doc.text(10, 10, "Page 2 of {totalPages}");

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});
if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});

it("customfont with samevalue in fontweight and fontstyle ", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";
it("customfont with samevalue in fontweight and fontstyle ", () => {
var PTSans = loadBinaryResource("reference/PTSans.ttf");
var doc = new jsPDF({ filters: ["ASCIIHexEncode"], floatPrecision: 2 });
var totalPagesExp = "{totalPages}";

doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal", "normal", "Identity-H");
doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal", "normal", "Identity-H");

doc.setFont("PTSans",'normal', "normal");
doc.setFont("PTSans", "normal", "normal");

doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();
doc.text(10, 10, "Page 1 of {totalPages}");
doc.addPage();

doc.text(10, 10, "Page 2 of {totalPages}");
doc.text(10, 10, "Page 2 of {totalPages}");

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPagesExp);
}
comparePdf(doc.output(), "customfont.pdf", "putTotalPages");
});
});

0 comments on commit ec7e835

Please sign in to comment.