MM-17792 Do not show download option for files uploaded locally (#3192)

This commit is contained in:
Mattermost Build 2019-08-26 16:17:54 +02:00 committed by Elias Nahum
parent 26c4777365
commit 3b6ca6fdb8
3 changed files with 22 additions and 0 deletions

View file

@ -234,6 +234,8 @@ exports[`ImagePreview should match snapshot 1`] = `
</AnimatedComponent>
`;
exports[`ImagePreview should match snapshot and not renderDownloadButton for local files 1`] = `null`;
exports[`ImagePreview should match snapshot, renderDownloadButton 1`] = `
<TouchableOpacity
activeOpacity={0.2}

View file

@ -227,6 +227,11 @@ export default class ImagePreview extends PureComponent {
const {canDownloadFiles} = this.props;
const file = this.getCurrentFile();
if (file?.data?.localPath) {
// we already have the file locally we don't need to download it
return null;
}
if (file) {
let icon;
let action = emptyFunction;

View file

@ -67,6 +67,21 @@ describe('ImagePreview', () => {
expect(wrapper.instance().renderDownloadButton()).toMatchSnapshot();
});
test('should match snapshot and not renderDownloadButton for local files', () => {
const props = {
...baseProps,
files: [{caption: 'Caption 1', source: 'source', data: {localPath: 'path'}}],
};
const wrapper = shallow(
<ImagePreview {...props}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.instance().renderDownloadButton()).toMatchSnapshot();
expect(wrapper.instance().renderDownloadButton()).toBeNull();
});
test('should match state on handleChangeImage', () => {
const wrapper = shallow(
<ImagePreview {...baseProps}/>,