This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
file_utils.test.jsx
111 lines (89 loc) · 3.54 KB
/
file_utils.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import {
trimFilename,
canUploadFiles,
getFileTypeFromMime,
} from 'utils/file_utils.jsx';
import * as UserAgent from 'utils/user_agent';
describe('FileUtils.trimFilename', () => {
it('trimFilename', () => {
assert.equal(
trimFilename('abcdefghijklmnopqrstuvwxyz'),
'abcdefghijklmnopqrstuvwxyz',
'should return same filename',
);
assert.equal(
trimFilename('abcdefghijklmnopqrstuvwxyz0123456789'),
'abcdefghijklmnopqrstuvwxyz012345678...',
'should return trimmed filename',
);
});
});
describe('FileUtils.canUploadFiles', () => {
UserAgent.isMobileApp = jest.fn().mockImplementation(() => false); // eslint-disable-line no-import-assign
it('is false when file attachments are disabled', () => {
const config = {
EnableFileAttachments: 'false',
EnableMobileFileUpload: 'true',
};
assert.equal(canUploadFiles(config), false);
});
describe('is true when file attachments are enabled', () => {
UserAgent.isMobileApp.mockImplementation(() => false);
it('and not on mobile', () => {
UserAgent.isMobileApp.mockImplementation(() => false);
const config = {
EnableFileAttachments: 'true',
EnableMobileFileUpload: 'false',
};
assert.equal(canUploadFiles(config), true);
});
it('and on mobile with mobile file upload enabled', () => {
UserAgent.isMobileApp.mockImplementation(() => true);
const config = {
EnableFileAttachments: 'true',
EnableMobileFileUpload: 'true',
};
assert.equal(canUploadFiles(config), true);
});
it('unless on mobile with mobile file upload disabled', () => {
UserAgent.isMobileApp.mockImplementation(() => true);
const config = {
EnableFileAttachments: 'true',
EnableMobileFileUpload: 'false',
};
assert.equal(canUploadFiles(config), false);
});
});
describe('get filetypes based on mime interpreted from browsers', () => {
it('mime type for videos', () => {
assert.equal(getFileTypeFromMime('video/mp4'), 'video');
});
it('mime type for audio', () => {
assert.equal(getFileTypeFromMime('audio/mp3'), 'audio');
});
it('mime type for image', () => {
assert.equal(getFileTypeFromMime('image/JPEG'), 'image');
});
it('mime type for pdf', () => {
assert.equal(getFileTypeFromMime('application/pdf'), 'pdf');
});
it('mime type for spreadsheet', () => {
assert.equal(getFileTypeFromMime('application/vnd.ms-excel'), 'spreadsheet');
});
it('mime type for presentation', () => {
assert.equal(getFileTypeFromMime('application/vnd.ms-powerpoint'), 'presentation');
});
it('mime type for word', () => {
assert.equal(getFileTypeFromMime('application/vnd.ms-word'), 'word');
});
it('mime type for unknown file format', () => {
assert.equal(getFileTypeFromMime('application/unknownFormat'), 'other');
});
it('mime type for no suffix', () => {
assert.equal(getFileTypeFromMime('asdasd'), 'other');
});
});
});