mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
JS -- Fix doc.getField and add missing field methods
- getField("foo") was wrongly returning a field named "foobar"; - field object had few missing unimplemented methods
This commit is contained in:
parent
952bc08ec0
commit
82f75a8ac2
4 changed files with 169 additions and 3 deletions
|
@ -161,6 +161,64 @@ describe("Scripting", function () {
|
|||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
|
||||
it("should get field using a path", async function (done) {
|
||||
const base = value => {
|
||||
return {
|
||||
id: getId(),
|
||||
value,
|
||||
actions: {},
|
||||
type: "text",
|
||||
};
|
||||
};
|
||||
const data = {
|
||||
objects: {
|
||||
A: [base(1)],
|
||||
"A.B": [base(2)],
|
||||
"A.B.C": [base(3)],
|
||||
"A.B.C.D": [base(4)],
|
||||
"A.B.C.D.E": [base(5)],
|
||||
"A.B.C.D.E.F": [base(6)],
|
||||
"A.B.C.D.G": [base(7)],
|
||||
C: [base(8)],
|
||||
},
|
||||
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
|
||||
try {
|
||||
await myeval(`this.getField("A").value`).then(value => {
|
||||
expect(value).toEqual(1);
|
||||
});
|
||||
await myeval(`this.getField("B.C").value`).then(value => {
|
||||
expect(value).toEqual(3);
|
||||
});
|
||||
// path has been cached so try again
|
||||
await myeval(`this.getField("B.C").value`).then(value => {
|
||||
expect(value).toEqual(3);
|
||||
});
|
||||
await myeval(`this.getField("B.C.D#0").value`).then(value => {
|
||||
expect(value).toEqual(5);
|
||||
});
|
||||
await myeval(`this.getField("B.C.D#1").value`).then(value => {
|
||||
expect(value).toEqual(7);
|
||||
});
|
||||
await myeval(`this.getField("C").value`).then(value => {
|
||||
expect(value).toEqual(8);
|
||||
});
|
||||
|
||||
await myeval(
|
||||
`this.getField("A.B.C.D").getArray().map((x) => x.value)`
|
||||
).then(value => {
|
||||
expect(value).toEqual([5, 7]);
|
||||
});
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Util", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue