78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { assertEquals } from "@std/assert";
|
|
import {
|
|
dumpPath,
|
|
feedPath,
|
|
parsePagePath,
|
|
playlistPath,
|
|
searchPath,
|
|
userPath,
|
|
} from "../paths.ts";
|
|
|
|
Deno.test("builders: one hierarchy, default views bare", () => {
|
|
assertEquals(userPath("bob"), "/@bob");
|
|
assertEquals(userPath("bob", "playlists"), "/@bob/playlists");
|
|
assertEquals(userPath("bob", "follow"), "/@bob/follow");
|
|
assertEquals(userPath("bob", "follow", "users"), "/@bob/follow");
|
|
assertEquals(
|
|
userPath("bob", "follow", "playlists"),
|
|
"/@bob/follow/playlists",
|
|
);
|
|
const item = { ownerUsername: "bob", slug: "never-gonna" };
|
|
assertEquals(dumpPath(item), "/@bob/dumps/never-gonna");
|
|
assertEquals(playlistPath(item), "/@bob/playlists/never-gonna");
|
|
assertEquals(feedPath(), "/");
|
|
assertEquals(feedPath(undefined, "hot"), "/hot");
|
|
assertEquals(feedPath("music"), "/music");
|
|
assertEquals(feedPath("music", "follow"), "/music/follow");
|
|
assertEquals(searchPath(), "/search");
|
|
assertEquals(searchPath("users", "a b"), "/search/users?q=a%20b");
|
|
assertEquals(searchPath("dumps", "x"), "/search?q=x");
|
|
});
|
|
|
|
Deno.test("parsePagePath: what a path under a user names", () => {
|
|
assertEquals(parsePagePath("/@bob"), {
|
|
kind: "user",
|
|
username: "bob",
|
|
rest: [],
|
|
});
|
|
assertEquals(parsePagePath("/@bob/follow/playlists/"), {
|
|
kind: "user",
|
|
username: "bob",
|
|
rest: ["follow", "playlists"],
|
|
});
|
|
assertEquals(parsePagePath("/@bob/dumps/never-gonna"), {
|
|
kind: "dump",
|
|
username: "bob",
|
|
slug: "never-gonna",
|
|
edit: false,
|
|
});
|
|
assertEquals(parsePagePath("/%40bob/dumps/x/edit"), {
|
|
kind: "dump",
|
|
username: "bob",
|
|
slug: "x",
|
|
edit: true,
|
|
});
|
|
assertEquals(parsePagePath("/@bob/playlists/mix"), {
|
|
kind: "playlist",
|
|
username: "bob",
|
|
slug: "mix",
|
|
});
|
|
for (
|
|
const other of [
|
|
"/",
|
|
"/hot",
|
|
"/music/hot",
|
|
"/search/users",
|
|
"/@",
|
|
"/@b-ob",
|
|
"/@bob/nope",
|
|
"/@bob/follow/users",
|
|
"/@bob/dumps/x/y",
|
|
"/@bob/playlists/x/edit",
|
|
"/@bob/%E0%A4%A",
|
|
]
|
|
) {
|
|
assertEquals(parsePagePath(other), null, other);
|
|
}
|
|
});
|