Skip to content

Commit ac46fbe

Browse files
committed
Update acroform.spec.js
1 parent 19f1235 commit ac46fbe

File tree

1 file changed

+103
-19
lines changed

1 file changed

+103
-19
lines changed

test/specs/acroform.spec.js

Lines changed: 103 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-self-assign */
2-
/* global describe, it, expect, jsPDF, comparePdf, Button, ComboBox, ChoiceField, EditBox, ListBox, PushButton, CheckBox, TextField, PasswordField, RadioButton, AcroForm */
2+
/* global describe, it, expect, jsPDF, comparePdf, Button, ComboBox, ChoiceField, EditBox, ListBox, PushButton, CheckBox, TextField, TextFieldParent, PasswordField, RadioButton, AcroForm */
33

44
/**
55
* Acroform testing
@@ -791,29 +791,29 @@ describe("Module: Acroform Unit Test", function() {
791791

792792
textField.backgroundColor = [1, 0, 1];
793793
textField.borderColor = [1, 0, 0];
794-
expect(textField.MK).toEqual('<<\n/BG [1 0 1]\n/BC [1 0 0]\n>>');
794+
expect(textField.MK).toEqual("<<\n/BG [1 0 1]\n/BC [1 0 0]\n>>");
795795
expect(textField._MK.BC).toEqual(textField.borderColor);
796796
expect(textField._MK.BG).toEqual(textField.backgroundColor);
797797
});
798798

799-
it("AcroFormButton MK", function(){
799+
it("AcroFormButton MK", function() {
800800
var pushButton = new PushButton();
801-
pushButton.caption = "OK"
802-
expect(pushButton.MK).toEqual('<<\n/CA (OK)\n>>');
801+
pushButton.caption = "OK";
802+
expect(pushButton.MK).toEqual("<<\n/CA (OK)\n>>");
803803
expect(pushButton.caption).toEqual("OK");
804804

805805
pushButton.MK = {
806806
BC: [0],
807807
BG: [1],
808808
CA: "Cancel"
809-
}
810-
expect(pushButton.MK).toEqual('<<\n/BC [0]\n/BG [1]\n/CA (Cancel)\n>>');
809+
};
810+
expect(pushButton.MK).toEqual("<<\n/BC [0]\n/BG [1]\n/CA (Cancel)\n>>");
811811
expect(pushButton.caption).toEqual("Cancel");
812812
});
813813

814814
it("AcroFormRadioButton MK", function() {
815815
var doc = new jsPDF({});
816-
var radioGroup = new RadioButton();
816+
var radioGroup = new RadioButton();
817817
radioGroup.borderColor = [0, 0, 0, 0];
818818
doc.addField(radioGroup);
819819

@@ -824,42 +824,80 @@ describe("Module: Acroform Unit Test", function() {
824824
radioGroup.setAppearance(AcroForm.Appearance.RadioButton.Cross);
825825

826826
expect(radioButton1.caption).toEqual("8");
827-
expect(radioButton1.MK).toEqual('<<\n/BG [1]\n/BC [0 0 0 0]\n/CA (8)\n>>'); // BG should be [1] by default for radio buttons
827+
expect(radioButton1.MK).toEqual("<<\n/BG [1]\n/BC [0 0 0 0]\n/CA (8)\n>>"); // BG should be [1] by default for radio buttons
828828
expect(radioButton2.MK).toEqual(radioButton1.MK);
829-
expect(radioButton3.MK).toEqual('<<\n/BG [1]\n/BC [1 1 1 1]\n/CA (8)\n>>');
829+
expect(radioButton3.MK).toEqual("<<\n/BG [1]\n/BC [1 1 1 1]\n/CA (8)\n>>");
830830

831831
radioGroup.setAppearance(AcroForm.Appearance.RadioButton.Circle);
832832
expect(radioButton1.caption).toEqual("l");
833-
expect(radioButton1.MK).toEqual('<<\n/BG [1]\n/BC [0 0 0 0]\n/CA (l)\n>>');
833+
expect(radioButton1.MK).toEqual("<<\n/BG [1]\n/BC [0 0 0 0]\n/CA (l)\n>>");
834834
});
835835

836836
it("AcroFormField BS", function() {
837837
const textField = new TextField();
838838
expect(textField.BS).toEqual(undefined);
839839

840840
textField.borderStyle = "dashed";
841-
expect(textField.BS).toEqual('<<\n/S /D\n>>');
841+
expect(textField.BS).toEqual("<<\n/S /D\n>>");
842842
textField.borderStyle = "solid";
843-
expect(textField.BS).toEqual('<<\n/S /l\n>>');
843+
expect(textField.BS).toEqual("<<\n/S /l\n>>");
844844
textField.borderStyle = "beveled";
845-
expect(textField.BS).toEqual('<<\n/S /B\n>>');
845+
expect(textField.BS).toEqual("<<\n/S /B\n>>");
846846
textField.borderStyle = "inset";
847-
expect(textField.BS).toEqual('<<\n/S /I\n>>');
847+
expect(textField.BS).toEqual("<<\n/S /I\n>>");
848848
textField.borderStyle = "underline";
849-
expect(textField.BS).toEqual('<<\n/S /U\n>>');
849+
expect(textField.BS).toEqual("<<\n/S /U\n>>");
850850

851851
textField.borderWidth = 3;
852-
expect(textField.BS).toEqual('<<\n/S /U\n/W 3\n>>');
852+
expect(textField.BS).toEqual("<<\n/S /U\n/W 3\n>>");
853853
expect(textField._BS).toEqual({
854-
borderStyle: 'underline',
854+
borderStyle: "underline",
855855
borderWidth: 3
856856
});
857-
expect(textField.borderStyle).toEqual('underline');
857+
expect(textField.borderStyle).toEqual("underline");
858858
expect(textField.borderWidth).toEqual(3);
859859

860860
textField.BS = {};
861861
expect(textField.BS).toEqual(undefined);
862862
});
863+
864+
it("Textfield group: AcroFormTextFieldParent, AcroFormTextFieldChild", function() {
865+
const textFieldParent = new TextFieldParent();
866+
textFieldParent.fieldName = "LastName";
867+
textFieldParent.value = "Smith";
868+
textFieldParent.borderColor = [0, 0, 1];
869+
textFieldParent.backgroundColor = [1, 0, 1];
870+
871+
expect(textFieldParent.F).toEqual(null);
872+
expect(textFieldParent.Kids).toEqual([]);
873+
expect(textFieldParent.hasAppearanceStream).toEqual(false);
874+
875+
const doc = new jsPDF({
876+
orientation: "p",
877+
unit: "mm",
878+
format: "a4",
879+
floatPrecision: 2
880+
});
881+
882+
doc.addField(textFieldParent);
883+
884+
const child1 = textFieldParent.createChild();
885+
expect(child1.value).toEqual("Smith");
886+
expect(child1.borderColor).toEqual([0, 0, 1]);
887+
expect(child1.backgroundColor).toEqual([1, 0, 1]);
888+
expect(child1.hasAppearanceStream).toEqual(true);
889+
890+
const child2 = textFieldParent.createChild();
891+
expect(child2.value).toEqual("Smith");
892+
893+
child2.value = "Jones";
894+
expect(child1.value).toEqual("Jones");
895+
expect(textFieldParent.value).toEqual("Jones");
896+
897+
child2.backgroundColor = [1];
898+
expect(child2.backgroundColor).toEqual([1]);
899+
expect(child1.backgroundColor).toEqual([1, 0, 1]);
900+
});
863901
});
864902

865903
describe("Module: Acroform Integration Test", function() {
@@ -1043,6 +1081,52 @@ describe("Module: Acroform Integration Test", function() {
10431081
comparePdf(doc.output(), "textfield.pdf", "acroform");
10441082
});
10451083

1084+
it("should add a TextFieldGroup", function() {
1085+
const doc = new jsPDF({
1086+
format: "a6",
1087+
orientation: "landscape",
1088+
unit: "mm",
1089+
floatPrecision: 2
1090+
});
1091+
1092+
const txtNameGroup = new TextFieldParent();
1093+
txtNameGroup.fieldName = "Name";
1094+
txtNameGroup.value = "Smith, Robert";
1095+
doc.addField(txtNameGroup);
1096+
1097+
const txtDateGroup = new TextFieldParent();
1098+
txtDateGroup.fieldName = "Date";
1099+
txtDateGroup.value = "12/31/2033";
1100+
doc.addField(txtDateGroup);
1101+
1102+
addHeader();
1103+
doc.addPage();
1104+
addHeader();
1105+
1106+
comparePdf(doc.output(), "textfieldGroup.pdf", "acroform");
1107+
1108+
function addHeader() {
1109+
let yPos = 9;
1110+
let xPos = 5;
1111+
let txtChild;
1112+
1113+
doc.text("Name:", xPos, yPos);
1114+
xPos += doc.getTextWidth("Name:") + 1;
1115+
txtChild = txtNameGroup.createChild();
1116+
txtChild.Rect = [xPos, yPos - 6, 60, 9];
1117+
1118+
xPos += 70;
1119+
1120+
doc.text("Date:", xPos, yPos);
1121+
xPos += doc.getTextWidth("Date:") + 1;
1122+
txtChild = txtDateGroup.createChild();
1123+
txtChild.Rect = [xPos, yPos - 6, 35, 9];
1124+
1125+
yPos += 5;
1126+
doc.line(0, yPos, doc.internal.pageSize.width, yPos);
1127+
}
1128+
});
1129+
10461130
it("should add a Password", function() {
10471131
var doc = new jsPDF({
10481132
orientation: "p",

0 commit comments

Comments
 (0)