test(feed): pin the sort options' default directions as literals
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.
This commit is contained in:
@@ -36,7 +36,7 @@ const SORT_MAP: Record<Exclude<SortKey, "shuffle" | "relevance">, { asc: string;
|
||||
priority: { desc: "priority", asc: "priority_asc" },
|
||||
};
|
||||
|
||||
export const SORT_DEFAULT_DIR: Record<Exclude<SortKey, "shuffle" | "relevance">, "asc" | "desc"> = {
|
||||
const SORT_DEFAULT_DIR: Record<Exclude<SortKey, "shuffle" | "relevance">, "asc" | "desc"> = {
|
||||
date: "desc",
|
||||
popular: "desc",
|
||||
duration: "desc",
|
||||
|
||||
@@ -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],
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user