- The Downloads module, its rail icon and badge are gone. A bookmark, the remembered page and an old
history entry that name it land on Files (urlState.resolvePage); `g d` goes to Files too.
- Users page: a Storage tab — the disk in numbers, every user's use against their own limit with
their file count, every user's downloads; aligned tables, one menu per row (edit / reset quota,
open source, copy, the owner's quota). The admin storage rows carry quota + file count, the admin
job list its owner.
- Settings: a Downloads tab — the download formats in one list (duplicate a built-in, edit or delete
your own) and the site sign-ins, moved from Account.
- "View" on an added download, a clip or a converting upload opens the tray on that row (unfolded,
back if closed; a finished one opens as a file; under a player it opens without taking focus).
- The download dialog opens on the format used last.
- DataTable: `pager={false}` for a short list, `cardRow` to give a lone "…" its own card line.
- Welcome and README speak of Files; a new Files screenshot.
102 lines
3.7 KiB
TypeScript
102 lines
3.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The download dialog opens on the format used last (per account), so a pasted link is one Enter
|
|
// away; a format deleted since falls back to the first. Its "added" notice's View opens the tray on
|
|
// the new job. The prefs are a map that outlives a mount — a reload, as far as the dialog can tell.
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { useState } from "react";
|
|
import { api, type DownloadProfile } from "../lib/api";
|
|
|
|
const h = vi.hoisted(() => ({
|
|
prefs: new Map<string, unknown>(),
|
|
notify: vi.fn(),
|
|
showInTray: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("react-i18next")>()),
|
|
useTranslation: () => ({ i18n: { language: "en" }, t: (key: string) => key }),
|
|
}));
|
|
vi.mock("../lib/usePref", () => ({
|
|
usePref: <T,>(key: string, initial: T) => {
|
|
const [value, setValue] = useState<T>(() =>
|
|
h.prefs.has(key) ? (h.prefs.get(key) as T) : initial,
|
|
);
|
|
return [
|
|
value,
|
|
(next: T) => {
|
|
h.prefs.set(key, next);
|
|
setValue(next);
|
|
},
|
|
];
|
|
},
|
|
}));
|
|
vi.mock("../lib/notifications", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("../lib/notifications")>()),
|
|
notify: h.notify,
|
|
}));
|
|
vi.mock("../lib/downloadQueue", () => ({ showInTray: h.showInTray }));
|
|
|
|
import DownloadDialog from "./DownloadDialog";
|
|
|
|
const profile = (id: number, name: string) =>
|
|
({ id, name, is_builtin: false, spec: { mode: "av" } }) as unknown as DownloadProfile;
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
h.prefs.clear();
|
|
h.notify.mockClear();
|
|
h.showInTray.mockClear();
|
|
});
|
|
|
|
function open() {
|
|
vi.spyOn(api, "downloadProfiles").mockResolvedValue([profile(1, "Best"), profile(2, "Phone")]);
|
|
const enqueue = vi.spyOn(api, "enqueueDownload").mockResolvedValue({ id: 77 } as never);
|
|
render(
|
|
<QueryClientProvider client={new QueryClient()}>
|
|
<DownloadDialog source="https://example.com/v" onClose={() => {}} />
|
|
</QueryClientProvider>,
|
|
);
|
|
return enqueue;
|
|
}
|
|
|
|
const picked = () =>
|
|
screen.getByRole("button", { name: /^downloads\.dialog\.profile: / }).getAttribute("aria-label");
|
|
|
|
describe("DownloadDialog", () => {
|
|
it("opens on the format used last; a deleted one falls back to the first", async () => {
|
|
const enqueue = open();
|
|
await waitFor(() => expect(picked()).toBe("downloads.dialog.profile: Best"));
|
|
fireEvent.click(screen.getByRole("button", { name: /^downloads\.dialog\.profile: / }));
|
|
const phone = (await screen.findAllByRole("menuitemradio", { hidden: true })).find(
|
|
(o) => o.textContent === "Phone",
|
|
)!;
|
|
fireEvent.click(phone);
|
|
fireEvent.click(screen.getByText("downloads.dialog.submit"));
|
|
await waitFor(() =>
|
|
expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ profile_id: 2 })),
|
|
);
|
|
cleanup();
|
|
|
|
open();
|
|
await waitFor(() => expect(picked()).toBe("downloads.dialog.profile: Phone"));
|
|
cleanup();
|
|
|
|
h.prefs.set("downloadProfile", 99);
|
|
open();
|
|
await waitFor(() => expect(picked()).toBe("downloads.dialog.profile: Best"));
|
|
});
|
|
|
|
it("its notice's View opens the tray on the new job", async () => {
|
|
open();
|
|
await waitFor(() => expect(picked()).toBe("downloads.dialog.profile: Best"));
|
|
fireEvent.click(screen.getByText("downloads.dialog.submit"));
|
|
await waitFor(() => expect(h.notify).toHaveBeenCalledTimes(1));
|
|
(h.notify.mock.calls[0]![0] as { action: { onClick: () => void } }).action.onClick();
|
|
expect(h.showInTray).toHaveBeenCalledWith(77);
|
|
});
|
|
});
|