/** * What order a container's children come back in. * * The store used to pin `sortBy: "SortName"` onto every drill-down, which is * where the podcast bug came from: a Jellypod channel folder lists its episodes * newest-first, and an alphabetical sort not only lost that order but clumped * every "[Played] …" title at the top. The store now says *what the container * is* and lets Rust say how it orders — the same division as `SearchScope`. * * TRACES: UR-007 | DR-257 | UT-231 */ import { describe, it, expect, beforeEach, vi } from "vitest"; const getItemsMock = vi.fn(); vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => {}), })); vi.mock("./auth", () => ({ auth: { getRepository: () => ({ getItems: getItemsMock }), }, })); import { library } from "./library"; describe("library.loadItems ordering", () => { beforeEach(() => { getItemsMock.mockReset(); getItemsMock.mockResolvedValue({ items: [], totalRecordCount: 0 }); }); it("names the container rather than a sort field", async () => { await library.loadItems("podcast-1", { parentKind: "channelFolder" }); const options = getItemsMock.mock.calls[0][1]; expect(options.parentKind).toBe("channelFolder"); // Naming a sort field here would put the ordering rule back in the // presentation layer, which is the leak this fix removes. expect(options.sortBy).toBeUndefined(); expect(options.sortOrder).toBeUndefined(); }); it("falls back to a plain folder when the caller names no container", async () => { await library.loadItems("library-1"); const options = getItemsMock.mock.calls[0][1]; expect(options.parentKind).toBe("folder"); expect(options.sortBy).toBeUndefined(); }); });