Merge pull request #12830 from calixteman/field
JS -- Fix doc.getField and add missing field methods
This commit is contained in:
commit
4de8b7e433
@ -828,8 +828,26 @@ class Doc extends PDFObject {
|
||||
return searchedField;
|
||||
}
|
||||
|
||||
const parts = cName.split("#");
|
||||
let childIndex = NaN;
|
||||
if (parts.length === 2) {
|
||||
childIndex = Math.floor(parseFloat(parts[1]));
|
||||
cName = parts[0];
|
||||
}
|
||||
|
||||
for (const [name, field] of this._fields.entries()) {
|
||||
if (name.includes(cName)) {
|
||||
if (name.endsWith(cName)) {
|
||||
if (!isNaN(childIndex)) {
|
||||
const children = this._getChildren(name);
|
||||
if (childIndex < 0 || childIndex >= children.length) {
|
||||
childIndex = 0;
|
||||
}
|
||||
if (childIndex < children.length) {
|
||||
this._fields.set(cName, children[childIndex]);
|
||||
return children[childIndex];
|
||||
}
|
||||
}
|
||||
this._fields.set(cName, field);
|
||||
return field;
|
||||
}
|
||||
}
|
||||
@ -837,6 +855,23 @@ class Doc extends PDFObject {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
_getChildren(fieldName) {
|
||||
// Children of foo.bar are foo.bar.oof, foo.bar.rab
|
||||
// but not foo.bar.oof.FOO.
|
||||
const len = fieldName.length;
|
||||
const children = [];
|
||||
const pattern = /^\.[^.]+$/;
|
||||
for (const [name, field] of this._fields.entries()) {
|
||||
if (name.startsWith(fieldName)) {
|
||||
const finalPart = name.slice(len);
|
||||
if (finalPart.match(pattern)) {
|
||||
children.push(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
getIcon() {
|
||||
/* Not implemented */
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class Field extends PDFObject {
|
||||
this.doNotSpellCheck = data.doNotSpellCheck;
|
||||
this.delay = data.delay;
|
||||
this.display = data.display;
|
||||
this.doc = data.doc;
|
||||
this.doc = data.doc.wrapped;
|
||||
this.editable = data.editable;
|
||||
this.exportValues = data.exportValues;
|
||||
this.fileSelect = data.fileSelect;
|
||||
@ -68,8 +68,13 @@ class Field extends PDFObject {
|
||||
|
||||
// Private
|
||||
this._actions = createActionsMap(data.actions);
|
||||
this._browseForFileToSubmit = data.browseForFileToSubmit || null;
|
||||
this._buttonCaption = null;
|
||||
this._buttonIcon = null;
|
||||
this._children = null;
|
||||
this._currentValueIndices = data.currentValueIndices || 0;
|
||||
this._document = data.doc;
|
||||
this._fieldPath = data.fieldPath;
|
||||
this._fillColor = data.fillColor || ["T"];
|
||||
this._isChoice = Array.isArray(data.items);
|
||||
this._items = data.items || [];
|
||||
@ -197,6 +202,48 @@ class Field extends PDFObject {
|
||||
this._valueAsString = val ? val.toString() : "";
|
||||
}
|
||||
|
||||
browseForFileToSubmit() {
|
||||
if (this._browseForFileToSubmit) {
|
||||
// TODO: implement this function on Firefox side
|
||||
// we can use nsIFilePicker but open method is async.
|
||||
// Maybe it's possible to use a html input (type=file) too.
|
||||
this._browseForFileToSubmit();
|
||||
}
|
||||
}
|
||||
|
||||
buttonGetCaption(nFace = 0) {
|
||||
if (this._buttonCaption) {
|
||||
return this._buttonCaption[nFace];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
buttonGetIcon(nFace = 0) {
|
||||
if (this._buttonIcon) {
|
||||
return this._buttonIcon[nFace];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
buttonImportIcon(cPath = null, nPave = 0) {
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
buttonSetCaption(cCaption, nFace = 0) {
|
||||
if (!this._buttonCaption) {
|
||||
this._buttonCaption = ["", "", ""];
|
||||
}
|
||||
this._buttonCaption[nFace] = cCaption;
|
||||
// TODO: send to the annotation layer
|
||||
}
|
||||
|
||||
buttonSetIcon(oIcon, nFace = 0) {
|
||||
if (!this._buttonIcon) {
|
||||
this._buttonIcon = [null, null, null];
|
||||
}
|
||||
this._buttonIcon[nFace] = oIcon;
|
||||
}
|
||||
|
||||
checkThisBox(nWidget, bCheckIt = true) {}
|
||||
|
||||
clearItems() {
|
||||
@ -260,6 +307,17 @@ class Field extends PDFObject {
|
||||
return bExportValue ? item.exportValue : item.displayValue;
|
||||
}
|
||||
|
||||
getArray() {
|
||||
if (this._children === null) {
|
||||
this._children = this._document.obj._getChildren(this._fieldPath);
|
||||
}
|
||||
return this._children;
|
||||
}
|
||||
|
||||
getLock() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
isBoxChecked(nWidget) {
|
||||
return false;
|
||||
}
|
||||
@ -337,6 +395,20 @@ class Field extends PDFObject {
|
||||
this._send({ id: this._id, items: this._items });
|
||||
}
|
||||
|
||||
setLock() {}
|
||||
|
||||
signatureGetModifications() {}
|
||||
|
||||
signatureGetSeedValue() {}
|
||||
|
||||
signatureInfo() {}
|
||||
|
||||
signatureSetSeedValue() {}
|
||||
|
||||
signatureSign() {}
|
||||
|
||||
signatureValidate() {}
|
||||
|
||||
_isButton() {
|
||||
return false;
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ function initSandbox(params) {
|
||||
const obj = objs[0];
|
||||
obj.send = send;
|
||||
obj.globalEval = globalEval;
|
||||
obj.doc = _document.wrapped;
|
||||
obj.doc = _document;
|
||||
obj.fieldPath = name;
|
||||
let field;
|
||||
if (obj.type === "radiobutton") {
|
||||
const otherButtons = objs.slice(1);
|
||||
|
@ -81,7 +81,7 @@ describe("Scripting", function () {
|
||||
});
|
||||
|
||||
describe("Sandbox", function () {
|
||||
it("should send a value, execute an action and get back a new value", function (done) {
|
||||
it("should send a value, execute an action and get back a new value", async () => {
|
||||
function compute(n) {
|
||||
let s = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
@ -112,27 +112,22 @@ describe("Scripting", function () {
|
||||
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value: `${number}`,
|
||||
name: "Keystroke",
|
||||
willCommit: true,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
valueAsString: expected,
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Doc", function () {
|
||||
it("should treat globalThis as the doc", async function (done) {
|
||||
it("should treat globalThis as the doc", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -151,15 +146,60 @@ describe("Scripting", function () {
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
|
||||
try {
|
||||
await myeval(`(this.foobar = 123456, 0)`);
|
||||
await myeval(`this.getField("field").doc.foobar`).then(value => {
|
||||
const value = await myeval(`this.getField("field").doc.foobar`);
|
||||
expect(value).toEqual(123456);
|
||||
});
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
|
||||
it("should get field using a path", async () => {
|
||||
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);
|
||||
|
||||
let value = await myeval(`this.getField("A").value`);
|
||||
expect(value).toEqual(1);
|
||||
|
||||
value = await myeval(`this.getField("B.C").value`);
|
||||
expect(value).toEqual(3);
|
||||
|
||||
// path has been cached so try again
|
||||
value = await myeval(`this.getField("B.C").value`);
|
||||
expect(value).toEqual(3);
|
||||
|
||||
value = await myeval(`this.getField("B.C.D#0").value`);
|
||||
expect(value).toEqual(5);
|
||||
|
||||
value = await myeval(`this.getField("B.C.D#1").value`);
|
||||
expect(value).toEqual(7);
|
||||
|
||||
value = await myeval(`this.getField("C").value`);
|
||||
expect(value).toEqual(8);
|
||||
|
||||
value = await myeval(
|
||||
`this.getField("A.B.C.D").getArray().map((x) => x.value)`
|
||||
);
|
||||
expect(value).toEqual([5, 7]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -174,115 +214,97 @@ describe("Scripting", function () {
|
||||
});
|
||||
|
||||
describe("printd", function () {
|
||||
it("should print a date according to a format", function (done) {
|
||||
it("should print a date according to a format", async () => {
|
||||
const date = `new Date("Sun Apr 15 2007 03:14:15")`;
|
||||
Promise.all([
|
||||
myeval(`util.printd(0, ${date})`).then(value => {
|
||||
let value = await myeval(`util.printd(0, ${date})`);
|
||||
expect(value).toEqual("D:20070415031415");
|
||||
}),
|
||||
myeval(`util.printd(1, ${date})`).then(value => {
|
||||
|
||||
value = await myeval(`util.printd(1, ${date})`);
|
||||
expect(value).toEqual("2007.04.15 03:14:15");
|
||||
}),
|
||||
myeval(`util.printd(2, ${date})`).then(value => {
|
||||
|
||||
value = await myeval(`util.printd(2, ${date})`);
|
||||
expect(value).toEqual("4/15/07 3:14:15 am");
|
||||
}),
|
||||
myeval(`util.printd("mmmm mmm mm m", ${date})`).then(value => {
|
||||
|
||||
value = await myeval(`util.printd("mmmm mmm mm m", ${date})`);
|
||||
expect(value).toEqual("April Apr 04 4");
|
||||
}),
|
||||
myeval(`util.printd("dddd ddd dd d", ${date})`).then(value => {
|
||||
|
||||
value = await myeval(`util.printd("dddd ddd dd d", ${date})`);
|
||||
expect(value).toEqual("Sunday Sun 15 15");
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe("scand", function () {
|
||||
it("should parse a date according to a format", function (done) {
|
||||
it("should parse a date according to a format", async () => {
|
||||
const date = new Date("Sun Apr 15 2007 03:14:15");
|
||||
Promise.all([
|
||||
myeval(`util.scand(0, "D:20070415031415").toString()`).then(value => {
|
||||
let value = await myeval(
|
||||
`util.scand(0, "D:20070415031415").toString()`
|
||||
);
|
||||
expect(new Date(value)).toEqual(date);
|
||||
}),
|
||||
myeval(`util.scand(1, "2007.04.15 03:14:15").toString()`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(`util.scand(1, "2007.04.15 03:14:15").toString()`);
|
||||
expect(new Date(value)).toEqual(date);
|
||||
}
|
||||
),
|
||||
myeval(`util.scand(2, "4/15/07 3:14:15 am").toString()`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(`util.scand(2, "4/15/07 3:14:15 am").toString()`);
|
||||
expect(new Date(value)).toEqual(date);
|
||||
}
|
||||
),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe("printf", function () {
|
||||
it("should print some data according to a format", function (done) {
|
||||
Promise.all([
|
||||
myeval(
|
||||
it("should print some data according to a format", async () => {
|
||||
let value = await myeval(
|
||||
`util.printf("Integer numbers: %d, %d,...", 1.234, 56.789)`
|
||||
).then(value => {
|
||||
);
|
||||
expect(value).toEqual("Integer numbers: 1, 56,...");
|
||||
}),
|
||||
myeval(`util.printf("Hex numbers: %x, %x,...", 1234, 56789)`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`util.printf("Hex numbers: %x, %x,...", 1234, 56789)`
|
||||
);
|
||||
expect(value).toEqual("Hex numbers: 4D2, DDD5,...");
|
||||
}
|
||||
),
|
||||
myeval(
|
||||
|
||||
value = await myeval(
|
||||
`util.printf("Hex numbers with 0x: %#x, %#x,...", 1234, 56789)`
|
||||
).then(value => {
|
||||
);
|
||||
expect(value).toEqual("Hex numbers with 0x: 0x4D2, 0xDDD5,...");
|
||||
}),
|
||||
myeval(`util.printf("Decimal number: %,0+.3f", 1234567.89123)`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`util.printf("Decimal number: %,0+.3f", 1234567.89123)`
|
||||
);
|
||||
expect(value).toEqual("Decimal number: +1,234,567.891");
|
||||
}
|
||||
),
|
||||
myeval(`util.printf("Decimal number: %,0+8.3f", 1.234567)`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`util.printf("Decimal number: %,0+8.3f", 1.234567)`
|
||||
);
|
||||
expect(value).toEqual("Decimal number: + 1.235");
|
||||
}
|
||||
),
|
||||
myeval(`util.printf("Decimal number: %,0.2f", -12.34567)`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`util.printf("Decimal number: %,0.2f", -12.34567)`
|
||||
);
|
||||
expect(value).toEqual("Decimal number: -12.35");
|
||||
}
|
||||
),
|
||||
]).then(() => done());
|
||||
});
|
||||
|
||||
it("should print a string with no argument", function (done) {
|
||||
myeval(`util.printf("hello world")`)
|
||||
.then(value => {
|
||||
it("should print a string with no argument", async () => {
|
||||
const value = await myeval(`util.printf("hello world")`);
|
||||
expect(value).toEqual("hello world");
|
||||
})
|
||||
.then(() => done());
|
||||
});
|
||||
|
||||
it("print a string with a percent", function (done) {
|
||||
myeval(`util.printf("%%s")`)
|
||||
.then(value => {
|
||||
it("print a string with a percent", async () => {
|
||||
const value = await myeval(`util.printf("%%s")`);
|
||||
expect(value).toEqual("%%s");
|
||||
})
|
||||
.then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe("printx", function () {
|
||||
it("should print some data according to a format", function (done) {
|
||||
myeval(`util.printx("9 (999) 999-9999", "aaa14159697489zzz")`)
|
||||
.then(value => {
|
||||
it("should print some data according to a format", async () => {
|
||||
const value = await myeval(
|
||||
`util.printx("9 (999) 999-9999", "aaa14159697489zzz")`
|
||||
);
|
||||
expect(value).toEqual("1 (415) 969-7489");
|
||||
})
|
||||
.then(() => done());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("should trigger an event and modify the source", function (done) {
|
||||
it("should trigger an event and modify the source", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -301,25 +323,22 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value: "",
|
||||
name: "test",
|
||||
willCommit: true,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
value: "123",
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("should trigger a Keystroke event and invalidate it", function (done) {
|
||||
it("should trigger a Keystroke event and invalidate it", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -338,8 +357,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value: "hell",
|
||||
name: "Keystroke",
|
||||
@ -347,20 +365,17 @@ describe("Scripting", function () {
|
||||
change: "o",
|
||||
selStart: 4,
|
||||
selEnd: 4,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
value: "hell",
|
||||
selRange: [4, 4],
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("should trigger a Keystroke event and change it", function (done) {
|
||||
it("should trigger a Keystroke event and change it", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -379,8 +394,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value: "hell",
|
||||
name: "Keystroke",
|
||||
@ -388,19 +402,16 @@ describe("Scripting", function () {
|
||||
change: "o",
|
||||
selStart: 4,
|
||||
selEnd: 4,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
value: "hella",
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("should trigger an invalid commit Keystroke event", function (done) {
|
||||
it("should trigger an invalid commit Keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -419,21 +430,16 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value: "",
|
||||
name: "test",
|
||||
willCommit: true,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(false);
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("should trigger a valid commit Keystroke event", function (done) {
|
||||
it("should trigger a valid commit Keystroke event", async () => {
|
||||
const refId1 = getId();
|
||||
const refId2 = getId();
|
||||
const data = {
|
||||
@ -463,23 +469,19 @@ describe("Scripting", function () {
|
||||
calculationOrder: [refId2],
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
sandbox
|
||||
.dispatchEventInSandbox({
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId1,
|
||||
value: "hello",
|
||||
name: "Keystroke",
|
||||
willCommit: true,
|
||||
})
|
||||
.then(() => {
|
||||
});
|
||||
|
||||
expect(send_queue.has(refId1)).toEqual(true);
|
||||
expect(send_queue.get(refId1)).toEqual({
|
||||
id: refId1,
|
||||
value: "world",
|
||||
valueAsString: "world",
|
||||
});
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
});
|
||||
|
||||
@ -500,80 +502,66 @@ describe("Scripting", function () {
|
||||
];
|
||||
}
|
||||
|
||||
it("should convert RGB color for different color spaces", function (done) {
|
||||
Promise.all([
|
||||
myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "T")`).then(value => {
|
||||
it("should convert RGB color for different color spaces", async () => {
|
||||
let value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "T")`);
|
||||
expect(round(value)).toEqual(["T"]);
|
||||
}),
|
||||
myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "G")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "G")`);
|
||||
expect(round(value)).toEqual(["G", 0.181]);
|
||||
}),
|
||||
myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "RGB")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "RGB")`);
|
||||
expect(round(value)).toEqual(["RGB", 0.1, 0.2, 0.3]);
|
||||
}),
|
||||
myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "CMYK")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "CMYK")`);
|
||||
expect(round(value)).toEqual(["CMYK", 0.9, 0.8, 0.7, 0.7]);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
|
||||
it("should convert CMYK color for different color spaces", function (done) {
|
||||
Promise.all([
|
||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "T")`).then(
|
||||
value => {
|
||||
it("should convert CMYK color for different color spaces", async () => {
|
||||
let value = await myeval(
|
||||
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "T")`
|
||||
);
|
||||
expect(round(value)).toEqual(["T"]);
|
||||
}
|
||||
),
|
||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "G")`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "G")`);
|
||||
expect(round(value)).toEqual(["G", 0.371]);
|
||||
}
|
||||
),
|
||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "RGB")`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "RGB")`
|
||||
);
|
||||
expect(round(value)).toEqual(["RGB", 0.5, 0.3, 0.4]);
|
||||
}
|
||||
),
|
||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "CMYK")`).then(
|
||||
value => {
|
||||
|
||||
value = await myeval(
|
||||
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "CMYK")`
|
||||
);
|
||||
expect(round(value)).toEqual(["CMYK", 0.1, 0.2, 0.3, 0.4]);
|
||||
}
|
||||
),
|
||||
]).then(() => done());
|
||||
});
|
||||
|
||||
it("should convert Gray color for different color spaces", function (done) {
|
||||
Promise.all([
|
||||
myeval(`color.convert(["G", 0.1], "T")`).then(value => {
|
||||
it("should convert Gray color for different color spaces", async () => {
|
||||
let value = await myeval(`color.convert(["G", 0.1], "T")`);
|
||||
expect(round(value)).toEqual(["T"]);
|
||||
}),
|
||||
myeval(`color.convert(["G", 0.1], "G")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["G", 0.1], "G")`);
|
||||
expect(round(value)).toEqual(["G", 0.1]);
|
||||
}),
|
||||
myeval(`color.convert(["G", 0.1], "RGB")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["G", 0.1], "RGB")`);
|
||||
expect(round(value)).toEqual(["RGB", 0.1, 0.1, 0.1]);
|
||||
}),
|
||||
myeval(`color.convert(["G", 0.1], "CMYK")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["G", 0.1], "CMYK")`);
|
||||
expect(round(value)).toEqual(["CMYK", 0, 0, 0, 0.9]);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
|
||||
it("should convert Transparent color for different color spaces", function (done) {
|
||||
Promise.all([
|
||||
myeval(`color.convert(["T"], "T")`).then(value => {
|
||||
it("should convert Transparent color for different color spaces", async () => {
|
||||
let value = await myeval(`color.convert(["T"], "T")`);
|
||||
expect(round(value)).toEqual(["T"]);
|
||||
}),
|
||||
myeval(`color.convert(["T"], "G")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["T"], "G")`);
|
||||
expect(round(value)).toEqual(["G", 0]);
|
||||
}),
|
||||
myeval(`color.convert(["T"], "RGB")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["T"], "RGB")`);
|
||||
expect(round(value)).toEqual(["RGB", 0, 0, 0]);
|
||||
}),
|
||||
myeval(`color.convert(["T"], "CMYK")`).then(value => {
|
||||
|
||||
value = await myeval(`color.convert(["T"], "CMYK")`);
|
||||
expect(round(value)).toEqual(["CMYK", 0, 0, 0, 1]);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
@ -587,26 +575,20 @@ describe("Scripting", function () {
|
||||
done();
|
||||
});
|
||||
|
||||
it("should test language", function (done) {
|
||||
Promise.all([
|
||||
myeval(`app.language`).then(value => {
|
||||
it("should test language", async () => {
|
||||
let value = await myeval(`app.language`);
|
||||
expect(value).toEqual("ENU");
|
||||
}),
|
||||
myeval(`app.language = "hello"`).then(value => {
|
||||
|
||||
value = await myeval(`app.language = "hello"`);
|
||||
expect(value).toEqual("app.language is read-only");
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
|
||||
it("should test platform", function (done) {
|
||||
Promise.all([
|
||||
myeval(`app.platform`).then(value => {
|
||||
it("should test platform", async () => {
|
||||
let value = await myeval(`app.platform`);
|
||||
expect(value).toEqual("UNIX");
|
||||
}),
|
||||
myeval(`app.platform = "hello"`).then(value => {
|
||||
|
||||
value = await myeval(`app.platform = "hello"`);
|
||||
expect(value).toEqual("app.platform is read-only");
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
@ -622,61 +604,54 @@ describe("Scripting", function () {
|
||||
});
|
||||
|
||||
describe("AFExtractNums", function () {
|
||||
it("should extract numbers", function (done) {
|
||||
Promise.all([
|
||||
myeval(`AFExtractNums("123 456 789")`).then(value => {
|
||||
it("should extract numbers", async () => {
|
||||
let value = await myeval(`AFExtractNums("123 456 789")`);
|
||||
expect(value).toEqual(["123", "456", "789"]);
|
||||
}),
|
||||
myeval(`AFExtractNums("123.456")`).then(value => {
|
||||
|
||||
value = await myeval(`AFExtractNums("123.456")`);
|
||||
expect(value).toEqual(["123", "456"]);
|
||||
}),
|
||||
myeval(`AFExtractNums("123")`).then(value => {
|
||||
|
||||
value = await myeval(`AFExtractNums("123")`);
|
||||
expect(value).toEqual(["123"]);
|
||||
}),
|
||||
myeval(`AFExtractNums(".123")`).then(value => {
|
||||
|
||||
value = await myeval(`AFExtractNums(".123")`);
|
||||
expect(value).toEqual(["0", "123"]);
|
||||
}),
|
||||
myeval(`AFExtractNums(",123")`).then(value => {
|
||||
|
||||
value = await myeval(`AFExtractNums(",123")`);
|
||||
expect(value).toEqual(["0", "123"]);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFMakeNumber", function () {
|
||||
it("should convert string to number", function (done) {
|
||||
Promise.all([
|
||||
myeval(`AFMakeNumber("123.456")`).then(value => {
|
||||
it("should convert string to number", async () => {
|
||||
let value = await myeval(`AFMakeNumber("123.456")`);
|
||||
expect(value).toEqual(123.456);
|
||||
}),
|
||||
myeval(`AFMakeNumber(123.456)`).then(value => {
|
||||
|
||||
value = await myeval(`AFMakeNumber(123.456)`);
|
||||
expect(value).toEqual(123.456);
|
||||
}),
|
||||
myeval(`AFMakeNumber("-123.456")`).then(value => {
|
||||
|
||||
value = await myeval(`AFMakeNumber("-123.456")`);
|
||||
expect(value).toEqual(-123.456);
|
||||
}),
|
||||
myeval(`AFMakeNumber("-123,456")`).then(value => {
|
||||
|
||||
value = await myeval(`AFMakeNumber("-123,456")`);
|
||||
expect(value).toEqual(-123.456);
|
||||
}),
|
||||
myeval(`AFMakeNumber("not a number")`).then(value => {
|
||||
|
||||
value = await myeval(`AFMakeNumber("not a number")`);
|
||||
expect(value).toEqual(null);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFMakeArrayFromList", function () {
|
||||
it("should split a string into an array of strings", async function (done) {
|
||||
it("should split a string into an array of strings", async () => {
|
||||
const value = await myeval(
|
||||
`AFMakeArrayFromList("aaaa, bbbbbbb,cc,ddd, e")`
|
||||
);
|
||||
expect(value).toEqual(["aaaa", " bbbbbbb", "cc", "ddd", "e"]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFNumber_format", function () {
|
||||
it("should format a number", async function (done) {
|
||||
it("should format a number", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -714,7 +689,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -776,16 +751,11 @@ describe("Scripting", function () {
|
||||
value: "(52,345.68€)",
|
||||
textColor: ["RGB", 1, 0, 0],
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFNumber_Keystroke", function () {
|
||||
it("should validate a number on a keystroke event", async function (done) {
|
||||
it("should validate a number on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -807,7 +777,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -821,13 +791,9 @@ describe("Scripting", function () {
|
||||
value: "123456.789",
|
||||
valueAsString: "123456.789",
|
||||
});
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
|
||||
it("should not validate a number on a keystroke event", async function (done) {
|
||||
it("should not validate a number on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -849,7 +815,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -863,15 +829,11 @@ describe("Scripting", function () {
|
||||
value:
|
||||
"The value entered does not match the format of the field [ MyField ]",
|
||||
});
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFPercent_Format", function () {
|
||||
it("should format a percentage", async function (done) {
|
||||
it("should format a percentage", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -897,7 +859,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -921,16 +883,11 @@ describe("Scripting", function () {
|
||||
id: refId,
|
||||
value: "%45.68",
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFDate_Format", function () {
|
||||
it("should format a date", async function (done) {
|
||||
it("should format a date", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -952,7 +909,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -976,16 +933,11 @@ describe("Scripting", function () {
|
||||
id: refId,
|
||||
value: "4/15/07 3:14 am",
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFRange_Validate", function () {
|
||||
it("should validate a number in range [a, b]", async function (done) {
|
||||
it("should validate a number in range [a, b]", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -1004,7 +956,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -1018,14 +970,9 @@ describe("Scripting", function () {
|
||||
value: "321",
|
||||
valueAsString: "321",
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
|
||||
it("should invalidate a number out of range [a, b]", async function (done) {
|
||||
it("should invalidate a number out of range [a, b]", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -1044,7 +991,7 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -1058,16 +1005,11 @@ describe("Scripting", function () {
|
||||
value:
|
||||
"Invalid value: must be greater than or equal to 123 and less than or equal to 456.",
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("ASSimple_Calculate", function () {
|
||||
it("should compute the sum of several fields", async function (done) {
|
||||
it("should compute the sum of several fields", async () => {
|
||||
const refIds = [0, 1, 2, 3].map(_ => getId());
|
||||
const data = {
|
||||
objects: {
|
||||
@ -1113,7 +1055,6 @@ describe("Scripting", function () {
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
|
||||
try {
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refIds[0],
|
||||
@ -1153,16 +1094,11 @@ describe("Scripting", function () {
|
||||
value: 6,
|
||||
valueAsString: "6",
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("AFSpecial_KeystrokeEx", function () {
|
||||
it("should validate a phone number on a keystroke event", async function (done) {
|
||||
it("should validate a phone number on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
@ -1181,7 +1117,6 @@ describe("Scripting", function () {
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
try {
|
||||
sandbox.createSandbox(data);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
@ -1231,27 +1166,19 @@ describe("Scripting", function () {
|
||||
value: "3F?",
|
||||
selRange: [3, 3],
|
||||
});
|
||||
|
||||
done();
|
||||
} catch (ex) {
|
||||
done.fail(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("eMailValidate", function () {
|
||||
it("should validate an e-mail address", function (done) {
|
||||
Promise.all([
|
||||
myeval(`eMailValidate(123)`).then(value => {
|
||||
it("should validate an e-mail address", async () => {
|
||||
let value = await myeval(`eMailValidate(123)`);
|
||||
expect(value).toEqual(false);
|
||||
}),
|
||||
myeval(`eMailValidate("foo@bar.com")`).then(value => {
|
||||
|
||||
value = await myeval(`eMailValidate("foo@bar.com")`);
|
||||
expect(value).toEqual(true);
|
||||
}),
|
||||
myeval(`eMailValidate("foo bar")`).then(value => {
|
||||
|
||||
value = await myeval(`eMailValidate("foo bar")`);
|
||||
expect(value).toEqual(false);
|
||||
}),
|
||||
]).then(() => done());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user