All checks were successful
CI / ci-tests (push) Successful in 15s
Also fix old parseQueryString and alias it to getQueryStringParam
105 lines
2.0 KiB
JavaScript
105 lines
2.0 KiB
JavaScript
import { describe, it, expect } from "vitest";
|
|
|
|
import {
|
|
parseQueryString,
|
|
getQueryStringParam,
|
|
} from '../src/utils/UrlParser.mjs';
|
|
|
|
let url_list = [
|
|
{
|
|
"id": "no params",
|
|
"in": {
|
|
"query": "http://foor.org",
|
|
"search": "",
|
|
"single": false
|
|
},
|
|
"out": {}
|
|
},
|
|
{
|
|
"id": "no params",
|
|
"in": {
|
|
"query": "http://foor.org/?param",
|
|
"search": "",
|
|
"single": false
|
|
},
|
|
"out": {"param": ""}
|
|
},
|
|
{
|
|
"id": "one params",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo",
|
|
"search": "",
|
|
"single": false
|
|
},
|
|
"out": {"param": "foo"}
|
|
},
|
|
{
|
|
"id": "two params",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo&bar=other",
|
|
"search": "",
|
|
"single": false
|
|
},
|
|
"out": {"param": "foo", "bar": "other"}
|
|
},
|
|
{
|
|
"id": "two params, select",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo&bar=other",
|
|
"search": "bar",
|
|
"single": false
|
|
},
|
|
"out": "other"
|
|
},
|
|
{
|
|
"id": "two params, same",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo¶m=other",
|
|
"search": "",
|
|
"single": false
|
|
},
|
|
"out": {"param": ["foo", "other"]}
|
|
},
|
|
{
|
|
"id": "two params, same, single but no search",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo¶m=other",
|
|
"search": "",
|
|
"single": true
|
|
},
|
|
// "out": {"param": ["foo", "other"]}
|
|
"out": {"param": "foo"}
|
|
},
|
|
{
|
|
"id": "three params, same, search",
|
|
"in": {
|
|
"query": "http://foor.org/?param=foo¶m=other&different=1",
|
|
"search": "param",
|
|
"single": false
|
|
},
|
|
"out": ["foo", "other"]
|
|
},
|
|
];
|
|
describe("getQueryStringParam", () => {
|
|
it('Should parse query string for key', () => {
|
|
for (const url of url_list) {
|
|
expect(
|
|
getQueryStringParam(url.in.search, url.in.query, url.in.single)
|
|
).toEqual(url.out);
|
|
}
|
|
});
|
|
});
|
|
describe("parseQueryString", () => {
|
|
it('Should parse query string for key', () => {
|
|
// let kv = getQueryStringParam("key", "http://foor.org?key=value");
|
|
// expect(kv).toEqual("value");
|
|
for (const url of url_list) {
|
|
expect(
|
|
parseQueryString(url.in.query, url.in.search, url.in.single)
|
|
).toEqual(url.out);
|
|
}
|
|
});
|
|
});
|
|
|
|
// __END__
|