feat: enable downloads from search results
This commit is contained in:
1 parent
cccb214229
commit
9aa79cbce9
3 files changed
+53
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// @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 { 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();
|
||||
});
|
||||
|
||||
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", () => {
|
||||
render(
|
||||
<PhotoGallery
|
||||
@@ -106,4 +125,4 @@ test("opens a full-screen lightbox when a photo tile is clicked", () => {
|
||||
expect(screen.getByRole("button", { name: /nächstes bild/i })).not.toBeNull();
|
||||
// No previous on the first photo.
|
||||
expect(screen.queryByRole("button", { name: /vorheriges bild/i })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -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 () => {
|
||||
const { catalog, immich } = createCatalog({ grantedAlbumIds: [] });
|
||||
|
||||
|
||||
@@ -107,13 +107,22 @@ async function searchAlbum(
|
||||
size: number,
|
||||
): Promise<ImmichSearchPage> {
|
||||
try {
|
||||
return await immich.searchPhotos({
|
||||
const searchPage = await immich.searchPhotos({
|
||||
albumIds,
|
||||
...(description === undefined ? {} : { description }),
|
||||
type: "IMAGE",
|
||||
page,
|
||||
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 {
|
||||
throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user