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
/
filename_overlay.test.tsx
80 lines (67 loc) · 2.39 KB
/
filename_overlay.test.tsx
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import FilenameOverlay from 'components/file_attachment/filename_overlay';
import DownloadIcon from 'components/widgets/icons/download_icon';
import AttachmentIcon from 'components/widgets/icons/attachment_icon';
describe('components/file_attachment/FilenameOverlay', () => {
function emptyFunction() {} //eslint-disable-line no-empty-function
const fileInfo = {
id: 'thumbnail_id',
name: 'test_filename',
extension: 'jpg',
width: 100,
height: 80,
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
size: 100,
mime_type: '',
clientId: '',
};
const baseProps = {
fileInfo,
handleImageClick: emptyFunction,
compactDisplay: false,
canDownload: true,
};
test('should match snapshot, standard display', () => {
const wrapper = shallow(
<FilenameOverlay {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, compact display', () => {
const handleImageClick = jest.fn();
const props = {...baseProps, compactDisplay: true, handleImageClick};
const wrapper = shallow(
<FilenameOverlay {...props}/>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(AttachmentIcon).exists()).toBe(true);
wrapper.find('a').first().simulate('click');
expect(handleImageClick).toHaveBeenCalledTimes(1);
});
test('should match snapshot, with Download icon as children', () => {
const props = {...baseProps, canDownload: true};
const wrapper = shallow(
<FilenameOverlay {...props}>
<DownloadIcon/>
</FilenameOverlay>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(DownloadIcon).exists()).toBe(true);
});
test('should match snapshot, standard but not downloadable', () => {
const props = {...baseProps, canDownload: false};
const wrapper = shallow(
<FilenameOverlay {...props}>
<DownloadIcon/>
</FilenameOverlay>,
);
expect(wrapper).toMatchSnapshot();
});
});