Remove Promise.all and async+done from unit/scripting_spec
This commit is contained in:
parent
82f75a8ac2
commit
ccef734ebb
@ -81,7 +81,7 @@ describe("Scripting", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Sandbox", 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) {
|
function compute(n) {
|
||||||
let s = 0;
|
let s = 0;
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
@ -112,27 +112,22 @@ describe("Scripting", function () {
|
|||||||
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
await sandbox.dispatchEventInSandbox({
|
||||||
.dispatchEventInSandbox({
|
|
||||||
id: refId,
|
id: refId,
|
||||||
value: `${number}`,
|
value: `${number}`,
|
||||||
name: "Keystroke",
|
name: "Keystroke",
|
||||||
willCommit: true,
|
willCommit: true,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId)).toEqual(true);
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
valueAsString: expected,
|
valueAsString: expected,
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(done.fail);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Doc", function () {
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -151,18 +146,12 @@ describe("Scripting", function () {
|
|||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
|
|
||||||
try {
|
|
||||||
await myeval(`(this.foobar = 123456, 0)`);
|
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);
|
expect(value).toEqual(123456);
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should get field using a path", async function (done) {
|
it("should get field using a path", async () => {
|
||||||
const base = value => {
|
const base = value => {
|
||||||
return {
|
return {
|
||||||
id: getId(),
|
id: getId(),
|
||||||
@ -188,37 +177,30 @@ describe("Scripting", function () {
|
|||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
|
|
||||||
try {
|
let value = await myeval(`this.getField("A").value`);
|
||||||
await myeval(`this.getField("A").value`).then(value => {
|
|
||||||
expect(value).toEqual(1);
|
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(
|
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)`
|
`this.getField("A.B.C.D").getArray().map((x) => x.value)`
|
||||||
).then(value => {
|
);
|
||||||
expect(value).toEqual([5, 7]);
|
expect(value).toEqual([5, 7]);
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Util", function () {
|
describe("Util", function () {
|
||||||
@ -232,115 +214,97 @@ describe("Scripting", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("printd", 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")`;
|
const date = `new Date("Sun Apr 15 2007 03:14:15")`;
|
||||||
Promise.all([
|
let value = await myeval(`util.printd(0, ${date})`);
|
||||||
myeval(`util.printd(0, ${date})`).then(value => {
|
|
||||||
expect(value).toEqual("D:20070415031415");
|
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");
|
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");
|
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");
|
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");
|
expect(value).toEqual("Sunday Sun 15 15");
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("scand", function () {
|
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");
|
const date = new Date("Sun Apr 15 2007 03:14:15");
|
||||||
Promise.all([
|
let value = await myeval(
|
||||||
myeval(`util.scand(0, "D:20070415031415").toString()`).then(value => {
|
`util.scand(0, "D:20070415031415").toString()`
|
||||||
|
);
|
||||||
expect(new Date(value)).toEqual(date);
|
expect(new Date(value)).toEqual(date);
|
||||||
}),
|
|
||||||
myeval(`util.scand(1, "2007.04.15 03:14:15").toString()`).then(
|
value = await myeval(`util.scand(1, "2007.04.15 03:14:15").toString()`);
|
||||||
value => {
|
|
||||||
expect(new Date(value)).toEqual(date);
|
expect(new Date(value)).toEqual(date);
|
||||||
}
|
|
||||||
),
|
value = await myeval(`util.scand(2, "4/15/07 3:14:15 am").toString()`);
|
||||||
myeval(`util.scand(2, "4/15/07 3:14:15 am").toString()`).then(
|
|
||||||
value => {
|
|
||||||
expect(new Date(value)).toEqual(date);
|
expect(new Date(value)).toEqual(date);
|
||||||
}
|
|
||||||
),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("printf", function () {
|
describe("printf", function () {
|
||||||
it("should print some data according to a format", function (done) {
|
it("should print some data according to a format", async () => {
|
||||||
Promise.all([
|
let value = await myeval(
|
||||||
myeval(
|
|
||||||
`util.printf("Integer numbers: %d, %d,...", 1.234, 56.789)`
|
`util.printf("Integer numbers: %d, %d,...", 1.234, 56.789)`
|
||||||
).then(value => {
|
);
|
||||||
expect(value).toEqual("Integer numbers: 1, 56,...");
|
expect(value).toEqual("Integer numbers: 1, 56,...");
|
||||||
}),
|
|
||||||
myeval(`util.printf("Hex numbers: %x, %x,...", 1234, 56789)`).then(
|
value = await myeval(
|
||||||
value => {
|
`util.printf("Hex numbers: %x, %x,...", 1234, 56789)`
|
||||||
|
);
|
||||||
expect(value).toEqual("Hex numbers: 4D2, DDD5,...");
|
expect(value).toEqual("Hex numbers: 4D2, DDD5,...");
|
||||||
}
|
|
||||||
),
|
value = await myeval(
|
||||||
myeval(
|
|
||||||
`util.printf("Hex numbers with 0x: %#x, %#x,...", 1234, 56789)`
|
`util.printf("Hex numbers with 0x: %#x, %#x,...", 1234, 56789)`
|
||||||
).then(value => {
|
);
|
||||||
expect(value).toEqual("Hex numbers with 0x: 0x4D2, 0xDDD5,...");
|
expect(value).toEqual("Hex numbers with 0x: 0x4D2, 0xDDD5,...");
|
||||||
}),
|
|
||||||
myeval(`util.printf("Decimal number: %,0+.3f", 1234567.89123)`).then(
|
value = await myeval(
|
||||||
value => {
|
`util.printf("Decimal number: %,0+.3f", 1234567.89123)`
|
||||||
|
);
|
||||||
expect(value).toEqual("Decimal number: +1,234,567.891");
|
expect(value).toEqual("Decimal number: +1,234,567.891");
|
||||||
}
|
|
||||||
),
|
value = await myeval(
|
||||||
myeval(`util.printf("Decimal number: %,0+8.3f", 1.234567)`).then(
|
`util.printf("Decimal number: %,0+8.3f", 1.234567)`
|
||||||
value => {
|
);
|
||||||
expect(value).toEqual("Decimal number: + 1.235");
|
expect(value).toEqual("Decimal number: + 1.235");
|
||||||
}
|
|
||||||
),
|
value = await myeval(
|
||||||
myeval(`util.printf("Decimal number: %,0.2f", -12.34567)`).then(
|
`util.printf("Decimal number: %,0.2f", -12.34567)`
|
||||||
value => {
|
);
|
||||||
expect(value).toEqual("Decimal number: -12.35");
|
expect(value).toEqual("Decimal number: -12.35");
|
||||||
}
|
|
||||||
),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should print a string with no argument", function (done) {
|
it("should print a string with no argument", async () => {
|
||||||
myeval(`util.printf("hello world")`)
|
const value = await myeval(`util.printf("hello world")`);
|
||||||
.then(value => {
|
|
||||||
expect(value).toEqual("hello world");
|
expect(value).toEqual("hello world");
|
||||||
})
|
|
||||||
.then(() => done());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("print a string with a percent", function (done) {
|
it("print a string with a percent", async () => {
|
||||||
myeval(`util.printf("%%s")`)
|
const value = await myeval(`util.printf("%%s")`);
|
||||||
.then(value => {
|
|
||||||
expect(value).toEqual("%%s");
|
expect(value).toEqual("%%s");
|
||||||
})
|
|
||||||
.then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("printx", function () {
|
describe("printx", function () {
|
||||||
it("should print some data according to a format", function (done) {
|
it("should print some data according to a format", async () => {
|
||||||
myeval(`util.printx("9 (999) 999-9999", "aaa14159697489zzz")`)
|
const value = await myeval(
|
||||||
.then(value => {
|
`util.printx("9 (999) 999-9999", "aaa14159697489zzz")`
|
||||||
|
);
|
||||||
expect(value).toEqual("1 (415) 969-7489");
|
expect(value).toEqual("1 (415) 969-7489");
|
||||||
})
|
|
||||||
.then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Events", function () {
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -359,25 +323,22 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
|
||||||
.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "",
|
value: "",
|
||||||
name: "test",
|
name: "test",
|
||||||
willCommit: true,
|
willCommit: true,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId)).toEqual(true);
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "123",
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -396,8 +357,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
await sandbox.dispatchEventInSandbox({
|
||||||
.dispatchEventInSandbox({
|
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "hell",
|
value: "hell",
|
||||||
name: "Keystroke",
|
name: "Keystroke",
|
||||||
@ -405,20 +365,17 @@ describe("Scripting", function () {
|
|||||||
change: "o",
|
change: "o",
|
||||||
selStart: 4,
|
selStart: 4,
|
||||||
selEnd: 4,
|
selEnd: 4,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId)).toEqual(true);
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "hell",
|
value: "hell",
|
||||||
selRange: [4, 4],
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -437,8 +394,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
await sandbox.dispatchEventInSandbox({
|
||||||
.dispatchEventInSandbox({
|
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "hell",
|
value: "hell",
|
||||||
name: "Keystroke",
|
name: "Keystroke",
|
||||||
@ -446,19 +402,16 @@ describe("Scripting", function () {
|
|||||||
change: "o",
|
change: "o",
|
||||||
selStart: 4,
|
selStart: 4,
|
||||||
selEnd: 4,
|
selEnd: 4,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId)).toEqual(true);
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "hella",
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -477,21 +430,16 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
await sandbox.dispatchEventInSandbox({
|
||||||
.dispatchEventInSandbox({
|
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "",
|
value: "",
|
||||||
name: "test",
|
name: "test",
|
||||||
willCommit: true,
|
willCommit: true,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId)).toEqual(false);
|
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 refId1 = getId();
|
||||||
const refId2 = getId();
|
const refId2 = getId();
|
||||||
const data = {
|
const data = {
|
||||||
@ -521,23 +469,19 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [refId2],
|
calculationOrder: [refId2],
|
||||||
};
|
};
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
sandbox
|
await sandbox.dispatchEventInSandbox({
|
||||||
.dispatchEventInSandbox({
|
|
||||||
id: refId1,
|
id: refId1,
|
||||||
value: "hello",
|
value: "hello",
|
||||||
name: "Keystroke",
|
name: "Keystroke",
|
||||||
willCommit: true,
|
willCommit: true,
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
expect(send_queue.has(refId1)).toEqual(true);
|
expect(send_queue.has(refId1)).toEqual(true);
|
||||||
expect(send_queue.get(refId1)).toEqual({
|
expect(send_queue.get(refId1)).toEqual({
|
||||||
id: refId1,
|
id: refId1,
|
||||||
value: "world",
|
value: "world",
|
||||||
valueAsString: "world",
|
valueAsString: "world",
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(done.fail);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -558,80 +502,66 @@ describe("Scripting", function () {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should convert RGB color for different color spaces", function (done) {
|
it("should convert RGB color for different color spaces", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "T")`);
|
||||||
myeval(`color.convert(["RGB", 0.1, 0.2, 0.3], "T")`).then(value => {
|
|
||||||
expect(round(value)).toEqual(["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]);
|
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]);
|
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]);
|
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) {
|
it("should convert CMYK color for different color spaces", async () => {
|
||||||
Promise.all([
|
let value = await myeval(
|
||||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "T")`).then(
|
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "T")`
|
||||||
value => {
|
);
|
||||||
expect(round(value)).toEqual(["T"]);
|
expect(round(value)).toEqual(["T"]);
|
||||||
}
|
|
||||||
),
|
value = await myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "G")`);
|
||||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "G")`).then(
|
|
||||||
value => {
|
|
||||||
expect(round(value)).toEqual(["G", 0.371]);
|
expect(round(value)).toEqual(["G", 0.371]);
|
||||||
}
|
|
||||||
),
|
value = await myeval(
|
||||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "RGB")`).then(
|
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "RGB")`
|
||||||
value => {
|
);
|
||||||
expect(round(value)).toEqual(["RGB", 0.5, 0.3, 0.4]);
|
expect(round(value)).toEqual(["RGB", 0.5, 0.3, 0.4]);
|
||||||
}
|
|
||||||
),
|
value = await myeval(
|
||||||
myeval(`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "CMYK")`).then(
|
`color.convert(["CMYK", 0.1, 0.2, 0.3, 0.4], "CMYK")`
|
||||||
value => {
|
);
|
||||||
expect(round(value)).toEqual(["CMYK", 0.1, 0.2, 0.3, 0.4]);
|
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) {
|
it("should convert Gray color for different color spaces", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`color.convert(["G", 0.1], "T")`);
|
||||||
myeval(`color.convert(["G", 0.1], "T")`).then(value => {
|
|
||||||
expect(round(value)).toEqual(["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]);
|
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]);
|
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]);
|
expect(round(value)).toEqual(["CMYK", 0, 0, 0, 0.9]);
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert Transparent color for different color spaces", function (done) {
|
it("should convert Transparent color for different color spaces", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`color.convert(["T"], "T")`);
|
||||||
myeval(`color.convert(["T"], "T")`).then(value => {
|
|
||||||
expect(round(value)).toEqual(["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]);
|
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]);
|
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]);
|
expect(round(value)).toEqual(["CMYK", 0, 0, 0, 1]);
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -645,26 +575,20 @@ describe("Scripting", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should test language", function (done) {
|
it("should test language", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`app.language`);
|
||||||
myeval(`app.language`).then(value => {
|
|
||||||
expect(value).toEqual("ENU");
|
expect(value).toEqual("ENU");
|
||||||
}),
|
|
||||||
myeval(`app.language = "hello"`).then(value => {
|
value = await myeval(`app.language = "hello"`);
|
||||||
expect(value).toEqual("app.language is read-only");
|
expect(value).toEqual("app.language is read-only");
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should test platform", function (done) {
|
it("should test platform", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`app.platform`);
|
||||||
myeval(`app.platform`).then(value => {
|
|
||||||
expect(value).toEqual("UNIX");
|
expect(value).toEqual("UNIX");
|
||||||
}),
|
|
||||||
myeval(`app.platform = "hello"`).then(value => {
|
value = await myeval(`app.platform = "hello"`);
|
||||||
expect(value).toEqual("app.platform is read-only");
|
expect(value).toEqual("app.platform is read-only");
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -680,61 +604,54 @@ describe("Scripting", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("AFExtractNums", function () {
|
describe("AFExtractNums", function () {
|
||||||
it("should extract numbers", function (done) {
|
it("should extract numbers", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`AFExtractNums("123 456 789")`);
|
||||||
myeval(`AFExtractNums("123 456 789")`).then(value => {
|
|
||||||
expect(value).toEqual(["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"]);
|
expect(value).toEqual(["123", "456"]);
|
||||||
}),
|
|
||||||
myeval(`AFExtractNums("123")`).then(value => {
|
value = await myeval(`AFExtractNums("123")`);
|
||||||
expect(value).toEqual(["123"]);
|
expect(value).toEqual(["123"]);
|
||||||
}),
|
|
||||||
myeval(`AFExtractNums(".123")`).then(value => {
|
value = await myeval(`AFExtractNums(".123")`);
|
||||||
expect(value).toEqual(["0", "123"]);
|
expect(value).toEqual(["0", "123"]);
|
||||||
}),
|
|
||||||
myeval(`AFExtractNums(",123")`).then(value => {
|
value = await myeval(`AFExtractNums(",123")`);
|
||||||
expect(value).toEqual(["0", "123"]);
|
expect(value).toEqual(["0", "123"]);
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFMakeNumber", function () {
|
describe("AFMakeNumber", function () {
|
||||||
it("should convert string to number", function (done) {
|
it("should convert string to number", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`AFMakeNumber("123.456")`);
|
||||||
myeval(`AFMakeNumber("123.456")`).then(value => {
|
|
||||||
expect(value).toEqual(123.456);
|
expect(value).toEqual(123.456);
|
||||||
}),
|
|
||||||
myeval(`AFMakeNumber(123.456)`).then(value => {
|
value = await myeval(`AFMakeNumber(123.456)`);
|
||||||
expect(value).toEqual(123.456);
|
expect(value).toEqual(123.456);
|
||||||
}),
|
|
||||||
myeval(`AFMakeNumber("-123.456")`).then(value => {
|
value = await myeval(`AFMakeNumber("-123.456")`);
|
||||||
expect(value).toEqual(-123.456);
|
expect(value).toEqual(-123.456);
|
||||||
}),
|
|
||||||
myeval(`AFMakeNumber("-123,456")`).then(value => {
|
value = await myeval(`AFMakeNumber("-123,456")`);
|
||||||
expect(value).toEqual(-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);
|
expect(value).toEqual(null);
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFMakeArrayFromList", function () {
|
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(
|
const value = await myeval(
|
||||||
`AFMakeArrayFromList("aaaa, bbbbbbb,cc,ddd, e")`
|
`AFMakeArrayFromList("aaaa, bbbbbbb,cc,ddd, e")`
|
||||||
);
|
);
|
||||||
expect(value).toEqual(["aaaa", " bbbbbbb", "cc", "ddd", "e"]);
|
expect(value).toEqual(["aaaa", " bbbbbbb", "cc", "ddd", "e"]);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFNumber_format", function () {
|
describe("AFNumber_format", function () {
|
||||||
it("should format a number", async function (done) {
|
it("should format a number", async () => {
|
||||||
const refId = getId();
|
const refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -772,7 +689,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -834,16 +751,11 @@ describe("Scripting", function () {
|
|||||||
value: "(52,345.68€)",
|
value: "(52,345.68€)",
|
||||||
textColor: ["RGB", 1, 0, 0],
|
textColor: ["RGB", 1, 0, 0],
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFNumber_Keystroke", function () {
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -865,7 +777,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -879,13 +791,9 @@ describe("Scripting", function () {
|
|||||||
value: "123456.789",
|
value: "123456.789",
|
||||||
valueAsString: "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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -907,7 +815,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -921,15 +829,11 @@ describe("Scripting", function () {
|
|||||||
value:
|
value:
|
||||||
"The value entered does not match the format of the field [ MyField ]",
|
"The value entered does not match the format of the field [ MyField ]",
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFPercent_Format", function () {
|
describe("AFPercent_Format", function () {
|
||||||
it("should format a percentage", async function (done) {
|
it("should format a percentage", async () => {
|
||||||
const refId = getId();
|
const refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -955,7 +859,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -979,16 +883,11 @@ describe("Scripting", function () {
|
|||||||
id: refId,
|
id: refId,
|
||||||
value: "%45.68",
|
value: "%45.68",
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFDate_Format", function () {
|
describe("AFDate_Format", function () {
|
||||||
it("should format a date", async function (done) {
|
it("should format a date", async () => {
|
||||||
const refId = getId();
|
const refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -1010,7 +909,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -1034,16 +933,11 @@ describe("Scripting", function () {
|
|||||||
id: refId,
|
id: refId,
|
||||||
value: "4/15/07 3:14 am",
|
value: "4/15/07 3:14 am",
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFRange_Validate", function () {
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -1062,7 +956,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -1076,14 +970,9 @@ describe("Scripting", function () {
|
|||||||
value: "321",
|
value: "321",
|
||||||
valueAsString: "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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -1102,7 +991,7 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -1116,16 +1005,11 @@ describe("Scripting", function () {
|
|||||||
value:
|
value:
|
||||||
"Invalid value: must be greater than or equal to 123 and less than or equal to 456.",
|
"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 () {
|
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 refIds = [0, 1, 2, 3].map(_ => getId());
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -1171,7 +1055,6 @@ describe("Scripting", function () {
|
|||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refIds[0],
|
id: refIds[0],
|
||||||
@ -1211,16 +1094,11 @@ describe("Scripting", function () {
|
|||||||
value: 6,
|
value: 6,
|
||||||
valueAsString: "6",
|
valueAsString: "6",
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AFSpecial_KeystrokeEx", function () {
|
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 refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
objects: {
|
objects: {
|
||||||
@ -1239,7 +1117,6 @@ describe("Scripting", function () {
|
|||||||
calculationOrder: [],
|
calculationOrder: [],
|
||||||
dispatchEventName: "_dispatchMe",
|
dispatchEventName: "_dispatchMe",
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
@ -1289,27 +1166,19 @@ describe("Scripting", function () {
|
|||||||
value: "3F?",
|
value: "3F?",
|
||||||
selRange: [3, 3],
|
selRange: [3, 3],
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
} catch (ex) {
|
|
||||||
done.fail(ex);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("eMailValidate", function () {
|
describe("eMailValidate", function () {
|
||||||
it("should validate an e-mail address", function (done) {
|
it("should validate an e-mail address", async () => {
|
||||||
Promise.all([
|
let value = await myeval(`eMailValidate(123)`);
|
||||||
myeval(`eMailValidate(123)`).then(value => {
|
|
||||||
expect(value).toEqual(false);
|
expect(value).toEqual(false);
|
||||||
}),
|
|
||||||
myeval(`eMailValidate("foo@bar.com")`).then(value => {
|
value = await myeval(`eMailValidate("foo@bar.com")`);
|
||||||
expect(value).toEqual(true);
|
expect(value).toEqual(true);
|
||||||
}),
|
|
||||||
myeval(`eMailValidate("foo bar")`).then(value => {
|
value = await myeval(`eMailValidate("foo bar")`);
|
||||||
expect(value).toEqual(false);
|
expect(value).toEqual(false);
|
||||||
}),
|
|
||||||
]).then(() => done());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user