Improve guest photo downloads with preview/original variants
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-07 14:31:48 +01:00
parent 3ba4d11d92
commit ddbfa38db1
7 changed files with 356 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
const setSearchParamsMock = vi.fn();
const pushGuestToastMock = vi.fn();
@@ -199,4 +199,40 @@ describe('GalleryScreen', () => {
expect(screen.queryByLabelText('AI Magic Edit')).not.toBeInTheDocument()
);
});
it('uses download_url when downloading from lightbox', async () => {
fetchGalleryMock.mockResolvedValue({
data: [{
id: 123,
thumbnail_url: '/storage/demo-thumb.jpg',
download_url: '/api/v1/gallery/demo/photos/123/download?signature=abc',
likes_count: 2,
}],
});
fetchPhotoMock.mockRejectedValue(Object.assign(new Error('not found'), { status: 404 }));
const originalCreateElement = document.createElement.bind(document);
const clickSpy = vi.fn();
let createdLink: HTMLAnchorElement | null = null;
const createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tagName: string) => {
const element = originalCreateElement(tagName) as HTMLElement;
if (tagName.toLowerCase() === 'a') {
createdLink = element as HTMLAnchorElement;
(createdLink as any).click = clickSpy;
}
return element;
});
render(<GalleryScreen />);
await waitFor(() => expect(fetchGalleryMock).toHaveBeenCalled());
const downloadButton = await screen.findByRole('button', { name: /download/i });
fireEvent.click(downloadButton);
expect(clickSpy).toHaveBeenCalled();
expect(createdLink?.getAttribute('href')).toBe('/api/v1/gallery/demo/photos/123/download?signature=abc');
createElementSpy.mockRestore();
});
});