mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
Merge 930589fd4b into 0263262ef4
This commit is contained in:
commit
45503b030f
2 changed files with 22 additions and 22 deletions
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue