| 1 |
import { get as store_get } from "svelte/store"; |
| 2 |
import { test } from "uvu"; |
| 3 |
import assert from "uvu/assert"; |
| 4 |
|
| 5 |
import { getUrlPath, urlForAccount, urlForInternal } from "../src/helpers"; |
| 6 |
import { base_url } from "../src/stores"; |
| 7 |
import { initialiseLedgerData } from "./helpers"; |
| 8 |
|
| 9 |
test.before(initialiseLedgerData); |
| 10 |
|
| 11 |
test("get URL", () => { |
| 12 |
const searchParams = new URLSearchParams({ time: "2000" }); |
| 13 |
assert.equal( |
| 14 |
urlForInternal("/base/", searchParams, "report", { |
| 15 |
asdf: 10, |
| 16 |
none: undefined, |
| 17 |
}), |
| 18 |
"/base/report?time=2000&asdf=10", |
| 19 |
); |
| 20 |
assert.equal(searchParams.get("asdf"), null); |
| 21 |
}); |
| 22 |
|
| 23 |
test("get path for account", () => { |
| 24 |
const $urlForAccount = store_get(urlForAccount); |
| 25 |
assert.equal($urlForAccount("Assets"), "/long-example/account/Assets/"); |
| 26 |
}); |
| 27 |
|
| 28 |
test("extract relative path from URL", () => { |
| 29 |
const $base_url = store_get(base_url); |
| 30 |
assert.equal($base_url, "/long-example/"); |
| 31 |
assert.equal(getUrlPath({ pathname: "/example/asdf" }), null); |
| 32 |
assert.equal(getUrlPath({ pathname: "/long-example/asdf" }), "asdf"); |
| 33 |
assert.equal(encodeURI("Ä€/asdf"), "%C3%84%E2%82%AC/asdf"); |
| 34 |
assert.equal( |
| 35 |
getUrlPath({ pathname: "/long-example/%C3%84%E2%82%AC/asdf" }), |
| 36 |
"Ä€/asdf", |
| 37 |
); |
| 38 |
}); |
| 39 |
|
| 40 |
test.run(); |