feat(files): download from anywhere — a link box, a pasted link, the palette; the running downloads in a tray
- Files toolbar link box (paste button, Enter); a lone http(s) link pasted onto any page opens the one app-wide download dialog, which now names the link; the palette's "Download from a link…" focuses the box on its history entry. - The download tray, bottom right on every page: what waits, runs, is paused or failed (reason + Retry, the queue's right-click / "…" menu), and what finished in this tab as "Done · Open" until closed; folds to a pill (per-account pref); closed, it stays shut — across a reload — until the work changes or something finishes. Back to top steps up over it, the page end keeps clear. - A finish is announced once: "Downloaded: …", whether a phone plays it, Copy link + Open (toasts and notices may carry a second action). - The inbox's ready notice opens the file in its folder: download_done carries job_id + folder_id. - GET /api/downloads is the queue only (in flight, failed, finished in the last 10 minutes), with each row's source key.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// @vitest-environment jsdom
|
||||
//
|
||||
// The queue as a tab watches it: a finish is a job that is done now and was not on the last look —
|
||||
// seen once, kept for the tray until it is closed, announced once. The first look only learns.
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import type { QueueJob } from "./api";
|
||||
import {
|
||||
clearFinished,
|
||||
noteQueue,
|
||||
resetQueueWatch,
|
||||
takeUnannounced,
|
||||
useFinished,
|
||||
} from "./downloadQueue";
|
||||
import { renderHook } from "@testing-library/react";
|
||||
|
||||
const job = (id: number, status: string) => ({ id, status }) as unknown as QueueJob;
|
||||
const finishedIds = () => renderHook(() => useFinished()).result.current.map((j) => j.id);
|
||||
|
||||
beforeEach(resetQueueWatch);
|
||||
|
||||
describe("downloadQueue · a finish", () => {
|
||||
it("the first look is old news: what is already done is not announced", () => {
|
||||
noteQueue([job(1, "done"), job(2, "running")]);
|
||||
expect(takeUnannounced()).toEqual([]);
|
||||
expect(finishedIds()).toEqual([]);
|
||||
});
|
||||
|
||||
it("a job that turns done is announced once and kept, newest first", () => {
|
||||
noteQueue([job(1, "running"), job(2, "queued")]);
|
||||
noteQueue([job(1, "done"), job(2, "running")]);
|
||||
noteQueue([job(1, "done"), job(2, "done")]);
|
||||
expect(takeUnannounced().map((j) => j.id)).toEqual([1, 2]);
|
||||
expect(takeUnannounced()).toEqual([]);
|
||||
expect(finishedIds()).toEqual([2, 1]);
|
||||
});
|
||||
|
||||
it("a job first seen done after the first look finished meanwhile (a cache hit, another device)", () => {
|
||||
noteQueue([]);
|
||||
noteQueue([job(5, "done")]);
|
||||
expect(takeUnannounced().map((j) => j.id)).toEqual([5]);
|
||||
});
|
||||
|
||||
it("a failure is not a finish; closing the tray forgets what finished", () => {
|
||||
noteQueue([job(1, "running"), job(2, "running")]);
|
||||
noteQueue([job(1, "error"), job(2, "done")]);
|
||||
expect(finishedIds()).toEqual([2]);
|
||||
clearFinished();
|
||||
expect(finishedIds()).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user