// E7·S5b — the Library/Shared row-action gate. A generic uploaded file (media_kind='file') is // download+share only (no Play/Edit/Details); an edit clip and an upload can't be re-downloaded. // These pin the gate so a regression that shows Play/Edit on a file, or re-download on an upload, // is caught (the affordance itself, not just the backend guard behind it). import { describe, it, expect } from "vitest"; import { libraryRowActions, sharedRowActions } from "./downloadActions"; import type { DownloadJob } from "./api"; const job = ( over: Partial, asset: Partial> | null, ) => ({ id: 1, status: "done", job_kind: "download", can_download: true, asset: asset && { id: 1, status: "ready", title: "x", duration_s: 90, media_kind: "video", container: "mp4", ...asset, }, ...over, }) as unknown as DownloadJob; describe("libraryRowActions", () => { it("a media (video) item gets play, edit, details, redownload", () => { expect(libraryRowActions(job({}, {}))).toEqual({ play: true, edit: true, editDetails: true, redownload: true, }); }); it("a generic file gets NO play/edit/details (download+share only)", () => { const a = libraryRowActions(job({}, { media_kind: "file", duration_s: null })); expect(a.play).toBe(false); expect(a.edit).toBe(false); expect(a.editDetails).toBe(false); }); it("an upload cannot be re-downloaded (no re-fetchable source)", () => { expect(libraryRowActions(job({ job_kind: "upload" }, { media_kind: "file" })).redownload).toBe( false, ); }); it("an edit clip cannot be re-downloaded", () => { expect(libraryRowActions(job({ job_kind: "edit" }, {})).redownload).toBe(false); }); it("edit is hidden when the media has no duration", () => { expect(libraryRowActions(job({}, { duration_s: 0 })).edit).toBe(false); }); }); describe("sharedRowActions", () => { it("a downloadable media item gets play, save, edit", () => { expect(sharedRowActions(job({}, {}))).toEqual({ play: true, save: true, edit: true }); }); it("nothing is offered when the owner disabled download", () => { expect(sharedRowActions(job({ can_download: false }, {}))).toEqual({ play: false, save: false, edit: false, }); }); it("a shared generic file gets only save (no player/trim)", () => { const a = sharedRowActions(job({}, { media_kind: "file", duration_s: null })); expect(a).toEqual({ play: false, save: true, edit: false }); }); });