* Use file preview URL for images in post
* Use getFilePreviewUrl for gallery as well
* But use getFileUrl for GIFs in gallery
(cherry picked from commit 304e3674c8)
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
parent
57a11783c3
commit
abb93e9b3d
4 changed files with 102 additions and 3 deletions
|
|
@ -0,0 +1,38 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`FileAttachmentImage should match snapshot 1`] = `
|
||||
<View
|
||||
style={
|
||||
Object {
|
||||
"borderRadius": 5,
|
||||
"overflow": "hidden",
|
||||
}
|
||||
}
|
||||
>
|
||||
<View
|
||||
style={
|
||||
Object {
|
||||
"paddingBottom": "100%",
|
||||
}
|
||||
}
|
||||
/>
|
||||
<Connect(ProgressiveImage)
|
||||
onError={[Function]}
|
||||
resizeMethod="resize"
|
||||
resizeMode="cover"
|
||||
style={
|
||||
Array [
|
||||
Object {
|
||||
"bottom": 0,
|
||||
"left": 0,
|
||||
"position": "absolute",
|
||||
"right": 0,
|
||||
"top": 0,
|
||||
},
|
||||
undefined,
|
||||
]
|
||||
}
|
||||
tintDefaultSource={true}
|
||||
/>
|
||||
</View>
|
||||
`;
|
||||
|
|
@ -11,7 +11,6 @@ import {
|
|||
import brokenImageIcon from '@assets/images/icons/brokenimage.png';
|
||||
import ProgressiveImage from '@components/progressive_image';
|
||||
import {Client4} from '@mm-redux/client';
|
||||
import {isGif} from '@utils/file';
|
||||
import {changeOpacity} from '@utils/theme';
|
||||
|
||||
const SMALL_IMAGE_MAX_HEIGHT = 48;
|
||||
|
|
@ -81,7 +80,7 @@ export default class FileAttachmentImage extends PureComponent {
|
|||
imageProps.defaultSource = {uri: file.localPath};
|
||||
} else if (file.id) {
|
||||
imageProps.thumbnailUri = Client4.getFileThumbnailUrl(file.id);
|
||||
imageProps.imageUri = isGif(file) ? Client4.getFilePreviewUrl(file.id) : Client4.getFileUrl(file.id);
|
||||
imageProps.imageUri = Client4.getFilePreviewUrl(file.id);
|
||||
}
|
||||
return imageProps;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import React from 'react';
|
||||
import {shallow} from 'enzyme';
|
||||
|
||||
import {Client4} from '@mm-redux/client';
|
||||
import brokenImageIcon from '@assets/images/icons/brokenimage.png';
|
||||
|
||||
import FileAttachmentImage from './file_attachment_image.js';
|
||||
|
||||
describe('FileAttachmentImage', () => {
|
||||
const baseProps = {
|
||||
file: {},
|
||||
};
|
||||
|
||||
test('should match snapshot', () => {
|
||||
const wrapper = shallow(
|
||||
<FileAttachmentImage {...baseProps}/>,
|
||||
);
|
||||
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe('imageProps', () => {
|
||||
const wrapper = shallow(
|
||||
<FileAttachmentImage {...baseProps}/>,
|
||||
);
|
||||
const instance = wrapper.instance();
|
||||
|
||||
it('should have brokenImageIcon as defaultSource if state.failed is true', () => {
|
||||
wrapper.setState({failed: true});
|
||||
const file = {};
|
||||
const imageProps = instance.imageProps(file);
|
||||
expect(imageProps.defaultSource).toStrictEqual(brokenImageIcon);
|
||||
expect(imageProps.thumbnailUri).toBeUndefined();
|
||||
expect(imageProps.imageUri).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should have file.localPath as defaultSource if localPath is set', () => {
|
||||
wrapper.setState({failed: false});
|
||||
const file = {localPath: '/localPath.png'};
|
||||
const imageProps = instance.imageProps(file);
|
||||
expect(imageProps.defaultSource).toStrictEqual({uri: file.localPath});
|
||||
expect(imageProps.thumbnailUri).toBeUndefined();
|
||||
expect(imageProps.imageUri).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should have thumbnailUri and imageUri if the file has an ID', () => {
|
||||
const getFileThumbnailUrl = jest.spyOn(Client4, 'getFileThumbnailUrl');
|
||||
const getFilePreviewUrl = jest.spyOn(Client4, 'getFilePreviewUrl');
|
||||
|
||||
wrapper.setState({failed: false});
|
||||
const file = {id: 'id'};
|
||||
const imageProps = instance.imageProps(file);
|
||||
expect(getFileThumbnailUrl).toHaveBeenCalled();
|
||||
expect(getFilePreviewUrl).toHaveBeenCalled();
|
||||
expect(imageProps.defaultSource).toBeUndefined();
|
||||
expect(imageProps.thumbnailUri).toBeDefined();
|
||||
expect(imageProps.imageUri).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -86,7 +86,7 @@ export default class FileAttachmentList extends ImageViewPort {
|
|||
if (file.localPath) {
|
||||
uri = file.localPath;
|
||||
} else {
|
||||
uri = Client4.getFileUrl(file.id);
|
||||
uri = isGif(file) ? Client4.getFileUrl(file.id) : Client4.getFilePreviewUrl(file.id);
|
||||
}
|
||||
|
||||
results.push({
|
||||
|
|
|
|||
Loading…
Reference in a new issue