Improve the API unit-tests for scripting-related functionality

I happened to notice that we didn't have *any* unit-tests for either `getFieldObjects` or `getCalculationOrderIds`, on the `PDFDocumentProxy` class, which seems unfortunate since it's API functionality that we depend on in e.g. the viewer.
This commit is contained in:
Jonas Jenwald 2021-12-29 12:22:20 +01:00
parent e42d54e1b5
commit b99927e1ee

View File

@ -1256,6 +1256,105 @@ describe("api", function () {
await loadingTask.destroy();
});
it("gets non-existent fieldObjects", async function () {
const fieldObjects = await pdfDocument.getFieldObjects();
expect(fieldObjects).toEqual(null);
});
it("gets fieldObjects", async function () {
if (isNodeJS) {
pending(
"Node.js appears to ignore Object properties that are explicitly " +
"set to `undefined`, thus breaking the expectations used below."
);
}
const loadingTask = getDocument(buildGetDocumentParams("js-authors.pdf"));
const pdfDoc = await loadingTask.promise;
const fieldObjects = await pdfDoc.getFieldObjects();
expect(fieldObjects).toEqual({
Text1: [
{
id: "25R",
value: "",
defaultValue: null,
multiline: false,
password: false,
charLimit: null,
comb: false,
editable: true,
hidden: false,
name: "Text1",
rect: [24.1789, 719.66, 432.22, 741.66],
actions: null,
page: 0,
strokeColor: null,
fillColor: null,
type: "text",
},
],
Button1: [
{
id: "26R",
value: "Off",
defaultValue: null,
exportValues: undefined,
editable: true,
name: "Button1",
rect: [455.436, 719.678, 527.436, 739.678],
hidden: false,
actions: {
Action: [
`this.getField("Text1").value = this.info.authors.join("::");`,
],
},
page: 0,
strokeColor: null,
fillColor: new Uint8ClampedArray([192, 192, 192]),
type: "button",
},
],
});
await loadingTask.destroy();
});
it("gets non-existent calculationOrder", async function () {
const calculationOrder = await pdfDocument.getCalculationOrderIds();
expect(calculationOrder).toEqual(null);
});
it("gets calculationOrder", async function () {
if (isNodeJS) {
pending("Linked test-cases are not supported in Node.js.");
}
const loadingTask = getDocument(buildGetDocumentParams("issue13132.pdf"));
const pdfDoc = await loadingTask.promise;
const calculationOrder = await pdfDoc.getCalculationOrderIds();
expect(calculationOrder).toEqual([
"319R",
"320R",
"321R",
"322R",
"323R",
"324R",
"325R",
"326R",
"327R",
"328R",
"329R",
"330R",
"331R",
"332R",
"333R",
"334R",
"335R",
]);
await loadingTask.destroy();
});
it("gets non-existent outline", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("tracemonkey.pdf")