Files
gerbeur/shared/test/paths.test.ts
khannurien 561cdf98b0 v4: playlists sort by their last dump, their creation or their size, and /playlists is a grid of covers — every list of playlists came newest first, so one fed every week sank under those made since and left empty. GET /api/playlists and /api/users/:key/playlists take ?sort=updated|new|dumps (PLAYLIST_SORTS, shared/playlist.ts), updated being the default: the last to take a dump first, or its creation while it holds none; a new title, cover or description doesn't bring it back up. A playlist carries that date as lastDumpAt, read with its dumpCount by isMemberVisibleTo's rule (VISIBLE_DUMP_FIGURES, the viewer's id as ?1), so the owner's private dumps date and count their playlists for them alone, in the lists and over the socket: playlist_created, playlist_updated and playlist_dumps_updated carry each socket's own. The /playlists page and a profile's playlists tab show the orders as tabs beside the category menu and keep the one picked in ?sort=, the default being the bare path; a tab takes the current history entry's place, and picking a category keeps the order. Live, usePlaylistListSync takes the list's order: a new playlist goes where it puts it, one that rises moves up to its place, as in the updated order when it takes a dump, and one that falls stays until the list is fetched again, its place being perhaps on a page not loaded. The lists in an order of their own, the followed playlists and the search's, pass none, and take no new playlist as before (noNewEntries goes). comparePlaylists is the order on the client, which a test holds to the API's.
/playlists lays its cards out as tiles, the cover across the top, four to a row and two on a phone, on the wide column: the same PlaylistCard, laid out by its list's class (.playlist-grid), so each theme's card skin carries over. It drops the "public" badge there, every playlist listed being public. On every card, a playlist without a cover shows a tile of its own colour with its initial (ThumbnailPlaceholder) in place of the 📋, and the date is "updated …" of its last dump, or "created …".

A middle, ctrl, cmd or shift click anywhere on a playlist card opens it in a new tab — only its title was a link, the rest navigating by a click handler. useCardLink (hooks/shared) is useDumpCardLink's handlers for any card, which the dump cards now get through it.

A profile tab's query stays with the tab — going from the playlists to the dumps kept the whole query, so a playlist category, and now ?sort=, landed on the dumps' URL. Only the dump lists pass their category to each other; any other change of tab drops the query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 08:51:37 +00:00

135 lines
4.1 KiB
TypeScript

import { assertEquals } from "@std/assert";
import {
dumpPath,
feedPath,
parsePagePath,
playlistPath,
playlistSortQuery,
playlistsPath,
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(
dumpPath({ ownerUsername: "bob", slug: "a-b" }, "edit"),
"/@bob/dumps/a-b/edit",
);
assertEquals(feedPath(), "/");
assertEquals(feedPath(undefined, "hot"), "/hot");
assertEquals(feedPath("music"), "/music");
assertEquals(feedPath("music", "follow"), "/music/follow");
assertEquals(feedPath("music", "follow", "users"), "/music/follow");
assertEquals(
feedPath(undefined, "follow", "playlists"),
"/follow/playlists",
);
assertEquals(feedPath(undefined, "new", "playlists"), "/new");
assertEquals(searchPath(), "/search");
assertEquals(searchPath("users", "a b"), "/search/users?q=a%20b");
assertEquals(searchPath("dumps", "x"), "/search?q=x");
assertEquals(playlistsPath(), "/playlists");
assertEquals(playlistsPath("mixes"), "/playlists/mixes");
assertEquals(playlistsPath(undefined, "updated"), "/playlists");
assertEquals(playlistsPath("mixes", "new"), "/playlists/mixes?sort=new");
// The query of a list that has other parameters: the default order takes
// an old `sort` out, and leaves the rest.
const category = new URLSearchParams({ category: "mixes", sort: "new" });
assertEquals(
playlistSortQuery("dumps", category),
"?category=mixes&sort=dumps",
);
assertEquals(playlistSortQuery("updated", category), "?category=mixes");
assertEquals(playlistSortQuery("updated"), "");
});
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",
edit: false,
});
assertEquals(parsePagePath("/@bob/playlists/mix/edit"), {
kind: "playlist",
username: "bob",
slug: "mix",
edit: true,
});
assertEquals(
playlistPath({ ownerUsername: "bob", slug: "mix" }, "edit"),
"/@bob/playlists/mix/edit",
);
for (
const other of [
"/",
"/hot",
"/music/hot",
"/search/users",
"/@",
"/@b-ob",
"/@bob/nope",
"/@bob/follow/users",
"/@bob/dumps/x/y",
"/@bob/playlists/x/y",
"/@bob/%E0%A4%A",
]
) {
assertEquals(parsePagePath(other), null, other);
}
});
Deno.test("handles: a user from another instance is /@name@host", () => {
assertEquals(userPath("alice@music.example"), "/@alice@music.example");
assertEquals(
dumpPath({ ownerUsername: "alice@localhost:8001", slug: "x" }),
"/@alice@localhost:8001/dumps/x",
);
assertEquals(parsePagePath("/@alice@music.example/playlists/mix"), {
kind: "playlist",
username: "alice@music.example",
slug: "mix",
edit: false,
});
assertEquals(parsePagePath("/@alice%40music.example"), {
kind: "user",
username: "alice@music.example",
rest: [],
});
assertEquals(parsePagePath("/@alice@"), null);
assertEquals(parsePagePath("/@alice@-bad.example"), null);
});