Improve guest photo downloads with preview/original variants
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user