* Open/Close Gallery transitions * Include postId in file info & disable opening the gallery in some cases * Add progress bar component * Transition to gallery based on platform * Improve getting the filename for non attachments * Patch RNFetchBlob TS definition * Add gallery types * fix unit tests for message and post attachment * add getLocalPath method * Add react-native-share dependency * Re-style gallery footer * Refactor Gallery screen * Double tap zoom in/out and translate * Make android activity "transparent" * Do not animate to height on dismissing gallery * Open gallery for file uploads * Fix borderRadius for gallery action button * Use progress bar for file uploads * Replace progress bar for file attachment document * Upgrade RNN to 7.1.0 to fix share elements transitions * Fix Gallery unit tests * translate down when popping screen on iOS * Swipe, Pan & Tap fixes * fix gallery footer avatar eslint * Fix gallery snapshot tests * Use CompassIcon in Gallery * Feedback from UX review * Fix gallery UI for other file types * Set other file type gallery button to 48pt
129 lines
4.1 KiB
JavaScript
129 lines
4.1 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {
|
|
generateId,
|
|
getLocalPath,
|
|
getLocalFilePathFromFile,
|
|
getExtensionFromContentDisposition,
|
|
hashCode,
|
|
} from 'app/utils/file';
|
|
|
|
import {DeviceTypes} from 'app/constants';
|
|
|
|
describe('getExtensionFromContentDisposition', () => {
|
|
it('should return the extracted the extension', () => {
|
|
const exts = [
|
|
'png',
|
|
'PNG',
|
|
'gif',
|
|
'GIF',
|
|
'bmp',
|
|
'BMP',
|
|
'jpg',
|
|
'JPG',
|
|
'jpeg',
|
|
'JPEG',
|
|
];
|
|
|
|
exts.forEach((ext) => {
|
|
const contentDisposition = `inline;filename="test_image.${ext}"; filename*=UTF-8''test_image.${ext}"`;
|
|
const extension = getExtensionFromContentDisposition(contentDisposition);
|
|
expect(extension).toBe(ext.toLowerCase());
|
|
});
|
|
});
|
|
|
|
it('should return null for an invalid extension', () => {
|
|
const invalidExt = 'invalid';
|
|
const contentDisposition = `inline;filename="test_image.${invalidExt}"; filename*=UTF-8''test_image.${invalidExt}"`;
|
|
const extension = getExtensionFromContentDisposition(contentDisposition);
|
|
expect(extension).toBe(null);
|
|
});
|
|
|
|
it('should return null for no content disposition', () => {
|
|
const contentDispositions = [
|
|
undefined,
|
|
null,
|
|
'',
|
|
];
|
|
|
|
contentDispositions.forEach((contentDisposition) => {
|
|
const extension = getExtensionFromContentDisposition(contentDisposition);
|
|
expect(extension).toBe(null);
|
|
});
|
|
});
|
|
|
|
it('should return the path for the file', () => {
|
|
const file = {
|
|
id: generateId(),
|
|
name: 'Some Video file.mp4',
|
|
extension: 'mp4',
|
|
};
|
|
|
|
const localFile = getLocalFilePathFromFile('Videos', file);
|
|
const [filename] = file.name.split('.');
|
|
expect(localFile).toBe(`Videos/${filename}-${hashCode(file.id)}.${file.extension}`);
|
|
});
|
|
|
|
it('should return the undefined as the path if it does not have an id and name set', () => {
|
|
const file = {
|
|
extension: 'mp4',
|
|
};
|
|
|
|
const localFile = getLocalFilePathFromFile('Videos', file);
|
|
expect(localFile).toBeUndefined();
|
|
});
|
|
|
|
it('should return the undefined as the path if it does not have an extension set', () => {
|
|
const file = {
|
|
id: generateId(),
|
|
};
|
|
const localFile = getLocalFilePathFromFile('Videos', file);
|
|
expect(localFile).toBeUndefined();
|
|
});
|
|
|
|
it('should return the same path as the local file', () => {
|
|
const file = {
|
|
localPath: 'some/path/filename.mp4',
|
|
};
|
|
|
|
const localFile = getLocalPath(file);
|
|
expect(localFile).toEqual(file.localPath);
|
|
});
|
|
|
|
it('should return the path for the video file', () => {
|
|
const file = {
|
|
id: generateId(),
|
|
name: 'Some Video file.mp4',
|
|
extension: 'mp4',
|
|
};
|
|
|
|
const localFile = getLocalPath(file);
|
|
const [filename] = file.name.split('.');
|
|
expect(localFile).toBe(`${DeviceTypes.VIDEOS_PATH}/${filename}-${hashCode(file.id)}.${file.extension}`);
|
|
});
|
|
|
|
it('should return the path for the image file', () => {
|
|
const file = {
|
|
id: generateId(),
|
|
name: 'Some animated image.gif',
|
|
extension: 'gif',
|
|
};
|
|
|
|
const localFile = getLocalPath(file);
|
|
const [filename] = file.name.split('.');
|
|
expect(localFile).toBe(`${DeviceTypes.IMAGES_PATH}/${filename}-${hashCode(file.id)}.${file.extension}`);
|
|
});
|
|
|
|
it('should return the path for the document file', () => {
|
|
const file = {
|
|
id: generateId(),
|
|
name: 'Some other doocument.txt',
|
|
extension: 'txt',
|
|
};
|
|
|
|
const localFile = getLocalPath(file);
|
|
const [filename] = file.name.split('.');
|
|
expect(localFile).toBe(`${DeviceTypes.DOCUMENTS_PATH}/${filename}-${hashCode(file.id)}.${file.extension}`);
|
|
});
|
|
});
|