This commit is contained in:
tinkerish 2026-02-04 03:04:06 +02:00 committed by GitHub
commit 45503b030f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 22 deletions

View file

@ -8,7 +8,6 @@ import FilePreviewModal from 'components/file_preview_modal/file_preview_modal';
import Constants from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import * as Utils from 'utils/utils';
import {generateId} from 'utils/utils';
describe('components/FilePreviewModal', () => {
@ -170,17 +169,6 @@ describe('components/FilePreviewModal', () => {
});
test('should handle external image URLs correctly', () => {
// Create a mock for Utils.loadImage
const loadImageSpy = jest.spyOn(Utils, 'loadImage').mockImplementation((url, onLoad) => {
// Create a mock ProgressEvent
const mockProgressEvent = new ProgressEvent('progress');
// Call onLoad with the mock event if it exists
if (onLoad) {
onLoad.call({} as XMLHttpRequest, mockProgressEvent);
}
});
// Create a LinkInfo object for an external image URL
const externalImageUrl = 'http://localhost:8065/api/v4/image?url=https%3A%2F%2Fexample.com%2Fimage.jpg';
const fileInfos = [{
@ -199,18 +187,8 @@ describe('components/FilePreviewModal', () => {
// Call loadImage with the external image URL
wrapper.instance().loadImage(0);
// Verify that Utils.loadImage was called with the correct URL
expect(loadImageSpy).toHaveBeenCalledWith(
externalImageUrl,
expect.any(Function),
expect.any(Function),
);
// Verify that handleImageLoaded was called
expect(handleImageLoadedSpy).toHaveBeenCalled();
// Restore the original loadImage function
loadImageSpy.mockRestore();
});
test('should have called loadImage', () => {
@ -317,4 +295,24 @@ describe('components/FilePreviewModal', () => {
expect(wrapper).toMatchSnapshot();
});
test('should be marked as loaded immediately to avoid infinite loading of external images', () => {
const externalImageUrl = 'http://localhost:8065/api/v4/image?url=https%3A%2F%2Fexample.com%2Fimage.jpg';
const fileInfos = [{
has_preview_image: false,
link: externalImageUrl,
extension: '',
name: 'External Image',
}];
const props = {...baseProps, fileInfos};
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...props}/>);
wrapper.instance().loadImage(0);
expect(wrapper.state('loaded')[0]).toBe(true);
});
});

View file

@ -204,6 +204,8 @@ export default class FilePreviewModal extends React.PureComponent<Props, State>
} else if (isLinkInfo(fileInfo)) {
// For LinkInfo, use the link directly
previewUrl = fileInfo.link;
this.handleImageLoaded(index);
return;
}
Utils.loadImage(