Implement unit tests for the recoverJsURL utility function

This commit is contained in:
Tim van der Meij 2023-01-08 14:43:07 +01:00
parent e09ad99973
commit a6dfcc89fa
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -23,6 +23,7 @@ import {
isWhiteSpace,
log2,
parseXFAPath,
recoverJsURL,
stringToUTF16HexString,
stringToUTF16String,
toRomanNumerals,
@ -210,6 +211,39 @@ describe("core_utils", function () {
});
});
describe("recoverJsURL", function () {
it("should get valid URLs without `newWindow` property", function () {
const inputs = [
"window.open('https://test.local')",
"window.open('https://test.local', true)",
"app.launchURL('https://test.local')",
"app.launchURL('https://test.local', false)",
"xfa.host.gotoURL('https://test.local')",
"xfa.host.gotoURL('https://test.local', true)",
];
for (const input of inputs) {
expect(recoverJsURL(input)).toEqual({
url: "https://test.local",
newWindow: false,
});
}
});
it("should get valid URLs with `newWindow` property", function () {
const input = "app.launchURL('https://test.local', true)";
expect(recoverJsURL(input)).toEqual({
url: "https://test.local",
newWindow: true,
});
});
it("should not get invalid URLs", function () {
const input = "navigateToUrl('https://test.local')";
expect(recoverJsURL(input)).toBeNull();
});
});
describe("escapePDFName", function () {
it("should escape PDF name", function () {
expect(escapePDFName("hello")).toEqual("hello");