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
|
import { GlLink, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import DownloadViewer from '~/repository/components/blob_viewers/download_viewer.vue';
describe('Text Viewer', () => {
let wrapper;
const DEFAULT_PROPS = {
fileName: 'file_name.js',
filePath: '/some/file/path',
fileSize: 2269674,
};
const createComponent = (props = {}) => {
wrapper = shallowMount(DownloadViewer, {
propsData: {
...DEFAULT_PROPS,
...props,
},
});
};
it('renders component', () => {
createComponent();
const { fileName, filePath, fileSize } = DEFAULT_PROPS;
expect(wrapper.props()).toMatchObject({
fileName,
filePath,
fileSize,
});
});
it('renders download human readable file size text', () => {
createComponent();
const downloadText = `Download (${numberToHumanSize(DEFAULT_PROPS.fileSize)})`;
expect(wrapper.text()).toBe(downloadText);
});
it('renders download text', () => {
createComponent({
fileSize: 0,
});
expect(wrapper.text()).toBe('Download');
});
it('renders download link', () => {
createComponent();
const { filePath, fileName } = DEFAULT_PROPS;
expect(wrapper.findComponent(GlLink).attributes()).toMatchObject({
rel: 'nofollow',
target: '_blank',
href: filePath,
download: fileName,
});
});
it('renders download icon', () => {
createComponent();
expect(wrapper.findComponent(GlIcon).props()).toMatchObject({
name: 'download',
size: 16,
});
});
});
|