2019-05-29 05:24:35 -04:00
|
|
|
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
|
2020-10-14 17:08:38 -04:00
|
|
|
import { GlDropdown } from '@gitlab/ui';
|
2019-05-29 05:24:35 -04:00
|
|
|
import Breadcrumbs from '~/repository/components/breadcrumbs.vue';
|
|
|
|
|
|
|
|
let vm;
|
|
|
|
|
2019-07-10 08:17:45 -04:00
|
|
|
function factory(currentPath, extraProps = {}) {
|
2019-05-29 05:24:35 -04:00
|
|
|
vm = shallowMount(Breadcrumbs, {
|
|
|
|
propsData: {
|
|
|
|
currentPath,
|
2019-07-10 08:17:45 -04:00
|
|
|
...extraProps,
|
2019-05-29 05:24:35 -04:00
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
RouterLink: RouterLinkStub,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Repository breadcrumbs component', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
vm.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
path | linkCount
|
|
|
|
${'/'} | ${1}
|
|
|
|
${'app'} | ${2}
|
|
|
|
${'app/assets'} | ${3}
|
|
|
|
${'app/assets/javascripts'} | ${4}
|
|
|
|
`('renders $linkCount links for path $path', ({ path, linkCount }) => {
|
|
|
|
factory(path);
|
|
|
|
|
|
|
|
expect(vm.findAll(RouterLinkStub).length).toEqual(linkCount);
|
|
|
|
});
|
|
|
|
|
2020-02-06 10:09:11 -05:00
|
|
|
it('escapes hash in directory path', () => {
|
|
|
|
factory('app/assets/javascripts#');
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(vm.findAll(RouterLinkStub).at(3).props('to')).toEqual(
|
|
|
|
'/-/tree/app/assets/javascripts%23',
|
|
|
|
);
|
2020-02-06 10:09:11 -05:00
|
|
|
});
|
|
|
|
|
2019-05-29 05:24:35 -04:00
|
|
|
it('renders last link as active', () => {
|
|
|
|
factory('app/assets');
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(vm.findAll(RouterLinkStub).at(2).attributes('aria-current')).toEqual('page');
|
2019-05-29 05:24:35 -04:00
|
|
|
});
|
2019-07-10 08:17:45 -04:00
|
|
|
|
|
|
|
it('does not render add to tree dropdown when permissions are false', () => {
|
|
|
|
factory('/', { canCollaborate: false });
|
|
|
|
|
|
|
|
vm.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });
|
|
|
|
|
2020-01-01 01:09:01 -05:00
|
|
|
return vm.vm.$nextTick(() => {
|
2020-10-14 17:08:38 -04:00
|
|
|
expect(vm.find(GlDropdown).exists()).toBe(false);
|
2020-01-01 01:09:01 -05:00
|
|
|
});
|
2019-07-10 08:17:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders add to tree dropdown when permissions are true', () => {
|
|
|
|
factory('/', { canCollaborate: true });
|
|
|
|
|
|
|
|
vm.setData({ userPermissions: { forkProject: true, createMergeRequestIn: true } });
|
|
|
|
|
2020-01-01 01:09:01 -05:00
|
|
|
return vm.vm.$nextTick(() => {
|
2020-10-14 17:08:38 -04:00
|
|
|
expect(vm.find(GlDropdown).exists()).toBe(true);
|
2020-01-01 01:09:01 -05:00
|
|
|
});
|
2019-07-10 08:17:45 -04:00
|
|
|
});
|
2019-05-29 05:24:35 -04:00
|
|
|
});
|