mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Implement unit tests for the parseQueryString
utility function
Now that these unit tests are in place, we also take the opportunity to slightly modernize the code itself by using a `for ... of` loop.
This commit is contained in:
parent
449f941b7b
commit
d1c0f8f91c
2 changed files with 40 additions and 3 deletions
|
@ -22,6 +22,7 @@ import {
|
|||
isPortraitOrientation,
|
||||
isValidRotation,
|
||||
moveToEndOfArray,
|
||||
parseQueryString,
|
||||
waitOnEventOrTimeout,
|
||||
WaitOnType,
|
||||
} from "../../web/ui_utils.js";
|
||||
|
@ -253,6 +254,43 @@ describe("ui_utils", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("parseQueryString", function () {
|
||||
it("should parse one key/value pair", function () {
|
||||
const parameters = parseQueryString("key1=value1");
|
||||
expect(parameters.size).toEqual(1);
|
||||
expect(parameters.get("key1")).toEqual("value1");
|
||||
});
|
||||
|
||||
it("should parse multiple key/value pairs", function () {
|
||||
const parameters = parseQueryString(
|
||||
"key1=value1&key2=value2&key3=value3"
|
||||
);
|
||||
expect(parameters.size).toEqual(3);
|
||||
expect(parameters.get("key1")).toEqual("value1");
|
||||
expect(parameters.get("key2")).toEqual("value2");
|
||||
expect(parameters.get("key3")).toEqual("value3");
|
||||
});
|
||||
|
||||
it("should parse keys without values", function () {
|
||||
const parameters = parseQueryString("key1");
|
||||
expect(parameters.size).toEqual(1);
|
||||
expect(parameters.get("key1")).toEqual("");
|
||||
});
|
||||
|
||||
it("should decode encoded key/value pairs", function () {
|
||||
const parameters = parseQueryString("k%C3%ABy1=valu%C3%AB1");
|
||||
expect(parameters.size).toEqual(1);
|
||||
expect(parameters.get("këy1")).toEqual("valuë1");
|
||||
});
|
||||
|
||||
it("should convert keys to lowercase", function () {
|
||||
const parameters = parseQueryString("Key1=Value1&KEY2=Value2");
|
||||
expect(parameters.size).toEqual(2);
|
||||
expect(parameters.get("key1")).toEqual("Value1");
|
||||
expect(parameters.get("key2")).toEqual("Value2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("waitOnEventOrTimeout", function () {
|
||||
let eventBus;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue