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
|
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui';
import ParentRow from '~/repository/components/table/parent_row.vue';
let vm;
let $router;
function factory(path, loadingPath) {
$router = {
push: jest.fn(),
};
vm = shallowMount(ParentRow, {
propsData: {
commitRef: 'master',
path,
loadingPath,
},
stubs: {
RouterLink: RouterLinkStub,
},
mocks: {
$router,
},
});
}
describe('Repository parent row component', () => {
afterEach(() => {
vm.destroy();
});
it.each`
path | to
${'app'} | ${'/-/tree/master/'}
${'app/assets'} | ${'/-/tree/master/app'}
${'app/assets#/test'} | ${'/-/tree/master/app/assets%23'}
${'app/assets#/test/world'} | ${'/-/tree/master/app/assets%23/test'}
`('renders link in $path to $to', ({ path, to }) => {
factory(path);
expect(vm.find(RouterLinkStub).props().to).toEqual({
path: to,
});
});
it('pushes new router when clicking row', () => {
factory('app/assets');
vm.find('td').trigger('click');
expect($router.push).toHaveBeenCalledWith({
path: '/-/tree/master/app',
});
});
// We test that it does not get called when clicking any internal
// links as this was causing multipe routes to get pushed
it('does not trigger router.push when clicking link', () => {
factory('app/assets');
vm.find('a').trigger('click');
expect($router.push).not.toHaveBeenCalledWith({
path: '/-/tree/master/app',
});
});
it('renders loading icon when loading parent', () => {
factory('app/assets', 'app');
expect(vm.find(GlLoadingIcon).exists()).toBe(true);
});
});
|