fix(downloads): media-library UI review fixes (E7)
Deep-review remediation on the frontend, all findings adversarially verified: - LibraryPlayer picks audio vs video from the canonical media_kind (single source), not a hardcoded container whitelist, so an uploaded audio file with an uncommon/absent container renders in <audio> instead of a broken video box (legacy null media_kind keeps the heuristic). - UploadDialog aborts the in-flight upload when the dialog is closed by X/ESC/backdrop/Back (not only the footer Cancel); drag highlight uses an enter/leave depth counter to stop the flicker; the progress bar gets a stable role=progressbar aria-label with the value on aria-valuenow. - DownloadCenter's Shared tab renders honest loading/error states instead of a blank panel, and the library/shared row-action gating moves to a single tested helper (lib/downloadActions). Tests: downloadActions gating matrix, the uploadReq XHR path (abort/401/422-localize/onerror), and the media_kind-driven audio/video branch. i18n: downloads.upload.uploadProgress (HU + EN).
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// 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<DownloadJob>,
|
||||
asset: Partial<NonNullable<DownloadJob["asset"]>> | 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 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user