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
112
113
114
115
116
117
118
119
|
import { mount } from '@vue/test-utils';
import { file } from 'jest/ide/helpers';
import ItemComponent from '~/vue_shared/components/file_finder/item.vue';
describe('File finder item spec', () => {
let wrapper;
const createComponent = ({ file: customFileFields = {}, ...otherProps } = {}) => {
wrapper = mount(ItemComponent, {
propsData: {
file: {
...file(),
name: 'test file',
path: 'test/file',
...customFileFields,
},
focused: true,
searchText: '',
index: 0,
...otherProps,
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('renders file name & path', () => {
createComponent();
expect(wrapper.text()).toContain('test file');
expect(wrapper.text()).toContain('test/file');
});
describe('focused', () => {
it('adds is-focused class', () => {
createComponent();
expect(wrapper.classes()).toContain('is-focused');
});
it('does not have is-focused class when not focused', async () => {
createComponent({ focused: false });
expect(wrapper.classes()).not.toContain('is-focused');
});
});
describe('changed file icon', () => {
it('does not render when not a changed or temp file', () => {
createComponent();
expect(wrapper.find('.diff-changed-stats').exists()).toBe(false);
});
it('renders when a changed file', async () => {
createComponent({ file: { changed: true } });
expect(wrapper.find('.diff-changed-stats').exists()).toBe(true);
});
it('renders when a temp file', async () => {
createComponent({ file: { tempFile: true } });
expect(wrapper.find('.diff-changed-stats').exists()).toBe(true);
});
});
it('emits event when clicked', async () => {
createComponent();
await wrapper.find('*').trigger('click');
expect(wrapper.emitted('click')[0]).toStrictEqual([wrapper.props('file')]);
});
describe('path', () => {
const findChangedFilePath = () => wrapper.find('.diff-changed-file-path');
it('highlights text', () => {
createComponent({ searchText: 'file' });
expect(findChangedFilePath().findAll('.highlighted')).toHaveLength(4);
});
it('adds ellipsis to long text', async () => {
const path = new Array(70)
.fill()
.map((_, i) => `${i}-`)
.join('');
createComponent({ searchText: 'file', file: { path } });
expect(findChangedFilePath().text()).toBe(`...${path.substring(path.length - 60)}`);
});
});
describe('name', () => {
const findChangedFileName = () => wrapper.find('.diff-changed-file-name');
it('highlights text', () => {
createComponent({ searchText: 'file' });
expect(findChangedFileName().findAll('.highlighted')).toHaveLength(4);
});
it('does not add ellipsis to long text', async () => {
const name = new Array(70)
.fill()
.map((_, i) => `${i}-`)
.join('');
createComponent({ searchText: 'file', file: { name } });
expect(findChangedFileName().text()).not.toBe(`...${name.substring(name.length - 60)}`);
});
});
});
|