1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #12247 from timvandermeij/acroform-choice-null

Improve the field value parsing for choice widgets to handle `null` values
This commit is contained in:
Tim van der Meij 2020-08-21 23:17:20 +02:00 committed by GitHub
commit 3c790936c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 43 deletions

View file

@ -2478,48 +2478,32 @@ describe("annotation", function () {
}, done.fail);
});
it("should handle array field values", function (done) {
const fieldValue = ["Foo", "Bar"];
it("should convert the field value to an array", function (done) {
const inputs = [null, "Foo", ["Foo", "Bar"]];
const outputs = [[], ["Foo"], ["Foo", "Bar"]];
choiceWidgetDict.set("V", fieldValue);
let promise = Promise.resolve();
for (let i = 0, ii = inputs.length; i < ii; i++) {
promise = promise.then(() => {
choiceWidgetDict.set("V", inputs[i]);
const choiceWidgetRef = Ref.get(968, 0);
const xref = new XRefMock([
{ ref: choiceWidgetRef, data: choiceWidgetDict },
]);
const choiceWidgetRef = Ref.get(968, 0);
const xref = new XRefMock([
{ ref: choiceWidgetRef, data: choiceWidgetDict },
]);
AnnotationFactory.create(
xref,
choiceWidgetRef,
pdfManagerMock,
idFactoryMock
).then(({ data }) => {
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual(fieldValue);
done();
}, done.fail);
});
it("should handle string field values", function (done) {
const fieldValue = "Foo";
choiceWidgetDict.set("V", fieldValue);
const choiceWidgetRef = Ref.get(978, 0);
const xref = new XRefMock([
{ ref: choiceWidgetRef, data: choiceWidgetDict },
]);
AnnotationFactory.create(
xref,
choiceWidgetRef,
pdfManagerMock,
idFactoryMock
).then(({ data }) => {
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual([fieldValue]);
done();
}, done.fail);
return AnnotationFactory.create(
xref,
choiceWidgetRef,
pdfManagerMock,
idFactoryMock
).then(({ data }) => {
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual(outputs[i]);
});
});
}
promise.then(done, done.fail);
});
it("should handle unknown flags", function (done) {