From 0b4b26867816a8568ad6c1dc55dad5c7c0952e77 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Fri, 11 Sep 2026 03:19:17 +0200 Subject: [PATCH] test(feed): pin the sort options' default directions as literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The feedSortOptions test compared each option's default direction against SORT_DEFAULT_DIR — the implementation's own table, so a wrong entry passed — and that import was the export's only user outside its module, which kept knip from seeing it had become dead after F3. The test now states the directions, the table is private again. --- frontend/src/lib/feedSort.ts | 2 +- frontend/src/lib/feedSort.yt.test.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) 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], ]); });