forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filename_overlay.test.jsx
73 lines (60 loc) · 2.24 KB
/
filename_overlay.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
// 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.jsx';
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,
};
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();
});
});