diff --git a/frontend/src/lib/feedSort.ts b/frontend/src/lib/feedSort.ts index 2257c8fc..745e6556 100644 --- a/frontend/src/lib/feedSort.ts +++ b/frontend/src/lib/feedSort.ts @@ -36,7 +36,7 @@ const SORT_MAP: Record, { asc: string; priority: { desc: "priority", asc: "priority_asc" }, }; -export const SORT_DEFAULT_DIR: Record, "asc" | "desc"> = { +const SORT_DEFAULT_DIR: Record, "asc" | "desc"> = { date: "desc", popular: "desc", duration: "desc", diff --git a/frontend/src/lib/feedSort.yt.test.ts b/frontend/src/lib/feedSort.yt.test.ts index ca8c178e..2e76d4d2 100644 --- a/frontend/src/lib/feedSort.yt.test.ts +++ b/frontend/src/lib/feedSort.yt.test.ts @@ -1,11 +1,5 @@ import { describe, it, expect } from "vitest"; -import { - feedSortOptions, - sortYtResults, - SORT_DEFAULT_DIR, - YT_SORT_KEYS, - SORT_KEYS, -} from "./feedSort"; +import { feedSortOptions, sortYtResults, YT_SORT_KEYS, SORT_KEYS } from "./feedSort"; import type { Video } from "./api"; // The live-YouTube results view shipped with no sort control at all: the provider's order was the @@ -122,11 +116,17 @@ describe("feedSortOptions", () => { // The library feed and the live results used to build their options from two copies of this // mapping; one helper means a key cannot get a different default direction in one of the modes. it("gives directional keys their default direction and marks shuffle/relevance directionless", () => { - const opts = feedSortOptions(["relevance", "date", "duration", "shuffle"], (k) => `label:${k}`); + // Literal directions, not the implementation's own table: comparing against that table let a + // wrong entry in it pass. Name is the one key that starts ascending. + const opts = feedSortOptions( + ["relevance", "date", "duration", "title", "shuffle"], + (k) => `label:${k}`, + ); expect(opts.map((o) => [o.key, o.label, !!o.directionless, o.defaultDir])).toEqual([ ["relevance", "label:relevance", true, undefined], - ["date", "label:date", false, SORT_DEFAULT_DIR.date], - ["duration", "label:duration", false, SORT_DEFAULT_DIR.duration], + ["date", "label:date", false, "desc"], + ["duration", "label:duration", false, "desc"], + ["title", "label:title", false, "asc"], ["shuffle", "label:shuffle", true, undefined], ]); });