diff --git a/webapp/channels/src/components/file_preview_modal/file_preview_modal.test.tsx b/webapp/channels/src/components/file_preview_modal/file_preview_modal.test.tsx index e6c46d6178c..fdc6c2dff71 100644 --- a/webapp/channels/src/components/file_preview_modal/file_preview_modal.test.tsx +++ b/webapp/channels/src/components/file_preview_modal/file_preview_modal.test.tsx @@ -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(); + + wrapper.instance().loadImage(0); + + expect(wrapper.state('loaded')[0]).toBe(true); + }); + }); diff --git a/webapp/channels/src/components/file_preview_modal/file_preview_modal.tsx b/webapp/channels/src/components/file_preview_modal/file_preview_modal.tsx index f4d398ab63c..b582f1f1987 100644 --- a/webapp/channels/src/components/file_preview_modal/file_preview_modal.tsx +++ b/webapp/channels/src/components/file_preview_modal/file_preview_modal.tsx @@ -204,6 +204,8 @@ export default class FilePreviewModal extends React.PureComponent } else if (isLinkInfo(fileInfo)) { // For LinkInfo, use the link directly previewUrl = fileInfo.link; + this.handleImageLoaded(index); + return; } Utils.loadImage(