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
120
121
122
123
124
125
126
127
128
129
130
|
import { file } from 'jest/ide/helpers';
import FileRow from '~/vue_shared/components/file_row.vue';
import FileHeader from '~/vue_shared/components/file_row_header.vue';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { escapeFileUrl } from '~/lib/utils/url_utility';
describe('File row component', () => {
let wrapper;
function createComponent(propsData, $router = undefined) {
wrapper = shallowMount(FileRow, {
propsData,
mocks: {
$router,
},
});
}
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 nextTick().then(() => {
expect(wrapper.vm.scrollIntoView).toHaveBeenCalled();
});
});
it('is marked as viewed if clicked', () => {
createComponent({
file: {
...file(),
type: 'blob',
fileHash: '#123456789',
},
level: 0,
viewedFiles: ['#123456789'],
});
expect(wrapper.classes()).toContain('is-viewed');
});
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.contains(FileHeader)).toBe(true);
});
it('matches the current route against encoded file URL', () => {
const fileName = 'with space';
const rowFile = Object.assign({}, file(fileName), {
url: `/${fileName}`,
});
const routerPath = `/project/${escapeFileUrl(fileName)}`;
createComponent(
{
file: rowFile,
level: 0,
},
{
currentRoute: {
path: routerPath,
},
},
);
expect(wrapper.vm.hasUrlAtCurrentRoute()).toBe(true);
});
});
|