2019-09-04 21:01:54 +05:30
|
|
|
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2019-09-04 21:01:54 +05:30
|
|
|
import ParentRow from '~/repository/components/table/parent_row.vue';
|
|
|
|
|
|
|
|
let vm;
|
|
|
|
let $router;
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
function factory(path, loadingPath) {
|
2019-09-04 21:01:54 +05:30
|
|
|
$router = {
|
|
|
|
push: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
vm = shallowMount(ParentRow, {
|
|
|
|
propsData: {
|
|
|
|
commitRef: 'master',
|
|
|
|
path,
|
2020-03-13 15:44:24 +05:30
|
|
|
loadingPath,
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
RouterLink: RouterLinkStub,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$router,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Repository parent row component', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
vm.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2020-04-22 19:07:51 +05:30
|
|
|
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'}
|
2019-09-04 21:01:54 +05:30
|
|
|
`('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({
|
2020-03-13 15:44:24 +05:30
|
|
|
path: '/-/tree/master/app',
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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({
|
2020-03-13 15:44:24 +05:30
|
|
|
path: '/-/tree/master/app',
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it('renders loading icon when loading parent', () => {
|
|
|
|
factory('app/assets', 'app');
|
|
|
|
|
|
|
|
expect(vm.find(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|