feat: enable downloads from search results

This commit is contained in:
Leon Tonhäuser committed 2026-08-12 16:45:42 +02:00
1 parent cccb214229
commit 9aa79cbce9
3 files changed
+52 -2

No files matched your search

+20 -1
View File
@@ -1,6 +1,6 @@
// @vitest-environment jsdom // @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
import { afterEach, expect, test } from "vitest"; import { afterEach, expect, test } from "vitest";
import { AlbumContactSheet } from "./catalog-content"; import { AlbumContactSheet } from "./catalog-content";
@@ -83,6 +83,25 @@ test("renders the server-scoped download choices for a catalog photo", () => {
expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull(); expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull();
}); });
test("offers the existing download workflow on a global search result and its lightbox", () => {
render(
<PhotoGallery
albumName="Alle Alben"
downloadOptions={{ priceCents: 100, priorUsagesByAsset: {} }}
items={[{
...photo,
id: "22222222-2222-4222-8222-222222222222",
albums: [{ id: "33333333-3333-4333-8333-333333333333" }],
}]}
showAlbumName
/>,
);
expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull();
fireEvent.click(screen.getByRole("button", { name: /tor-des-sieges\.jpg vergrößern/i }));
expect(within(screen.getByRole("dialog")).getByRole("button", { name: /original laden/i })).not.toBeNull();
});
test("opens a full-screen lightbox when a photo tile is clicked", () => { test("opens a full-screen lightbox when a photo tile is clicked", () => {
render( render(
<PhotoGallery <PhotoGallery
+22
View File
@@ -62,6 +62,28 @@ test("uses a requested album only when it is in the current editorial grants", a
); );
}); });
test("restores the queried granted album when Immich omits an asset album association", async () => {
const { catalog, immich } = createCatalog({ grantedAlbumIds: ["allowed"] });
immich.searchPhotos.mockResolvedValue({
items: [{
id: "asset-1",
type: "IMAGE",
originalFileName: "tor.jpg",
originalMimeType: "image/jpeg",
localDateTime: null,
fileCreatedAt: null,
albums: [],
}],
total: 1,
nextPage: null,
previousPage: null,
});
const result = await catalog.searchVisiblePhotos("editorial-1", { page: 1 });
expect(result.items[0]?.albums).toEqual([{ id: "allowed" }]);
});
test("does not call Immich when an editorial has no current album grants", async () => { test("does not call Immich when an editorial has no current album grants", async () => {
const { catalog, immich } = createCatalog({ grantedAlbumIds: [] }); const { catalog, immich } = createCatalog({ grantedAlbumIds: [] });
+10 -1
View File
@@ -107,13 +107,22 @@ async function searchAlbum(
size: number, size: number,
): Promise<ImmichSearchPage> { ): Promise<ImmichSearchPage> {
try { try {
return await immich.searchPhotos({ const searchPage = await immich.searchPhotos({
albumIds, albumIds,
...(description === undefined ? {} : { description }), ...(description === undefined ? {} : { description }),
type: "IMAGE", type: "IMAGE",
page, page,
size, size,
}); });
const queriedAlbumId = albumIds[0];
return {
...searchPage,
items: queriedAlbumId
? searchPage.items.map((asset) => asset.albums.some(({ id }) => id === queriedAlbumId)
? asset
: { ...asset, albums: [{ id: queriedAlbumId }, ...asset.albums] })
: searchPage.items,
};
} catch { } catch {
throw new AlbumCatalogError("IMMICH_UNAVAILABLE"); throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
} }