import { Applied, Late, Of, Shared } from "silentium"; import { expect, test, vi } from "vitest"; import { Router } from "../navigation/Router"; const drop = (dropPart: string) => (value: string) => { return value.replace(dropPart, ""); }; test("Router accepts routes as plain array without Message wrapper", () => { const $url = Late("http://domain.com/"); const $urlPath = Shared(Applied($url, drop("http://domain.com"))); const g = vi.fn(); $urlPath.then(g); const $router = Router( $urlPath, [ { pattern: "^/$", message: () => Of("page/home.html"), }, { pattern: "/some/contacts", message: () => Of("page/contacts.html"), }, ], () => Of("page/404.html"), ); const g2 = vi.fn(); $router.then(g2); expect(g2).toHaveBeenLastCalledWith("page/home.html"); $url.use("http://domain.com/some/contacts"); expect(g).toHaveBeenLastCalledWith("/some/contacts"); expect(g2).toHaveBeenLastCalledWith("page/contacts.html"); $url.use("http://domain.com/some/unknown/"); expect(g2).toHaveBeenLastCalledWith("page/404.html"); $url.use("http://domain.com/"); expect(g2).toHaveBeenLastCalledWith("page/home.html"); });