Files
siftlode/frontend/src/components/channelColumns.dom.test.tsx
T
peter 1b946113c6 feat(design): a channel's and a Plex playlist's one action list (C1) — the row's "…", Delete + undo, an action toast's 8 s floor (E28 S3e2)
- Channels: the row's full-history, hide and unsubscribe buttons become its "…" at the row end
  (useChannelActions: open, pin, YouTube, copy name / link, full history or the admin reset,
  hide with an undo toast, unsubscribe behind its danger confirm); the card layout docks the "…"
  beside the name (ChannelLayoutGrid moreKey). The admin reset's confirm now names the reset.
- Plex playlist page: a title, a show group and a season each open the page's one row menu (a
  title's is its usePlexCardActions list plus the removal); no X at rest; removals take an undo
  toast whose Undo puts every row back at its own index in one request (bulk add `positions`);
  j/k walk the visible rows, Delete removes the walked one; rename and delete in the header's "…".
- notify: a toast with an action lives at least 8 s (the owner's call), whatever the toast setting.
2026-09-26 05:56:07 +02:00

99 lines
3.5 KiB
TypeScript

// @vitest-environment jsdom
//
// applySyncFilter is the sync-status pre-filter the top chips drive (R14 retired the Sync column and
// folded its status into a Stored charm). It replaced a column `filter.test`, so it carries the exact
// "fully" | "needsFull" | "" vocab + predicate — asserted here so a regression can't silently change
// which channels the top chips show.
import { describe, it, expect } from "vitest";
import { applySyncFilter, buildChannelColumns, tagsColumnTest } from "./channelColumns";
import { NO_TAG_SENTINEL, type ManagedChannel } from "../lib/api";
const ch = (over: Partial<ManagedChannel>): ManagedChannel => ({
id: "c",
title: null,
handle: null,
thumbnail_url: null,
subscriber_count: null,
video_count: null,
description: null,
stored_videos: 0,
last_video_at: null,
total_duration_seconds: 0,
priority: 0,
hidden: false,
deep_requested: false,
deep_in_queue: false,
tag_ids: [],
details_synced: false,
recent_synced: false,
backfill_done: false,
...over,
});
const rows = [
ch({ id: "fully", recent_synced: true, backfill_done: true }),
ch({ id: "recentOnly", recent_synced: true, backfill_done: false }),
ch({ id: "none", recent_synced: false, backfill_done: false }),
];
describe("applySyncFilter", () => {
it("returns every row for the empty/all value (and unknown values)", () => {
expect(applySyncFilter(rows, "").map((r) => r.id)).toEqual(["fully", "recentOnly", "none"]);
expect(applySyncFilter(rows, undefined)).toHaveLength(3);
expect(applySyncFilter(rows, "bogus")).toHaveLength(3);
});
it("'fully' keeps only channels with recent uploads AND full history in", () => {
expect(applySyncFilter(rows, "fully").map((r) => r.id)).toEqual(["fully"]);
});
it("'needsFull' keeps every channel whose back-catalogue is not done", () => {
expect(applySyncFilter(rows, "needsFull").map((r) => r.id)).toEqual(["recentOnly", "none"]);
});
});
describe("tagsColumnTest (item B — 'No tag')", () => {
const tagged = ch({ id: "tagged", tag_ids: [1, 2] });
const untagged = ch({ id: "untagged", tag_ids: [] });
it("the No-tag sentinel keeps only channels with no user tag", () => {
expect(tagsColumnTest(tagged, [NO_TAG_SENTINEL])).toBe(false);
expect(tagsColumnTest(untagged, [NO_TAG_SENTINEL])).toBe(true);
});
it("real tag values match ANY selected id (sentinel absent)", () => {
expect(tagsColumnTest(tagged, ["2"])).toBe(true);
expect(tagsColumnTest(tagged, ["3"])).toBe(false);
expect(tagsColumnTest(untagged, ["1"])).toBe(false);
});
it("the sentinel wins if it somehow co-exists with real ids", () => {
expect(tagsColumnTest(tagged, [NO_TAG_SENTINEL, "1"])).toBe(false);
});
});
describe("buildChannelColumns — the row's end", () => {
it('ends every row in the channel\'s "…", with no action buttons before it', () => {
const more = (c: ManagedChannel) => `more:${c.id}`;
const noop = () => {};
const cols = buildChannelColumns({
t: ((k: string) => k) as never,
prioOptions: [],
userTags: [],
bumpPriority: noop,
setPriority: noop,
more,
onView: noop,
toggleTag: noop,
createAndAttachTag: noop,
onFilterByTag: noop,
suggestionsFor: () => [],
onAcceptSuggestion: noop,
onDismissSuggestion: noop,
});
expect(cols[cols.length - 1]!.key).toBe("actions");
expect(cols.filter((c) => c.key === "actions")).toHaveLength(1);
expect(cols[cols.length - 1]!.render(ch({ id: "UCz" }))).toBe("more:UCz");
});
});