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
|
import { file } from 'jest/ide/helpers';
import FileRow from '~/vue_shared/components/file_row.vue';
import { mount } from '@vue/test-utils';
describe('File row component', () => {
let wrapper;
function createComponent(propsData) {
wrapper = mount(FileRow, {
propsData,
});
}
afterEach(() => {
wrapper.destroy();
});
it('renders name', () => {
const fileName = 't4';
createComponent({
file: file(fileName),
level: 0,
});
const name = wrapper.find('.file-row-name');
expect(name.text().trim()).toEqual(fileName);
});
it('emits toggleTreeOpen on click', () => {
const fileName = 't3';
createComponent({
file: {
...file(fileName),
type: 'tree',
},
level: 0,
});
jest.spyOn(wrapper.vm, '$emit');
wrapper.element.click();
expect(wrapper.vm.$emit).toHaveBeenCalledWith('toggleTreeOpen', fileName);
});
it('calls scrollIntoView if made active', () => {
createComponent({
file: {
...file(),
type: 'blob',
active: false,
},
level: 0,
});
jest.spyOn(wrapper.vm, 'scrollIntoView');
wrapper.setProps({
file: Object.assign({}, wrapper.props('file'), {
active: true,
}),
});
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.scrollIntoView).toHaveBeenCalled();
});
});
it('indents row based on level', () => {
createComponent({
file: file('t4'),
level: 2,
});
expect(wrapper.find('.file-row-name').element.style.marginLeft).toBe('32px');
});
it('renders header for file', () => {
createComponent({
file: {
isHeader: true,
path: 'app/assets',
tree: [],
},
level: 0,
});
expect(wrapper.element.classList).toContain('js-file-row-header');
});
});
|