debian-mirror-gitlab/spec/frontend/repository/components/breadcrumbs_spec.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
2021-01-03 14:25:43 +05:30
import { GlDropdown } from '@gitlab/ui';
2019-09-04 21:01:54 +05:30
import Breadcrumbs from '~/repository/components/breadcrumbs.vue';
let vm;
2019-09-30 21:07:59 +05:30
function factory(currentPath, extraProps = {}) {
2019-09-04 21:01:54 +05:30
vm = shallowMount(Breadcrumbs, {
propsData: {
currentPath,
2019-09-30 21:07:59 +05:30
...extraProps,
2019-09-04 21:01:54 +05:30
},
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-03-13 15:44:24 +05:30
it('escapes hash in directory path', () => {
factory('app/assets/javascripts#');
expect(
vm
.findAll(RouterLinkStub)
.at(3)
.props('to'),
).toEqual('/-/tree/app/assets/javascripts%23');
});
2019-09-04 21:01:54 +05:30
it('renders last link as active', () => {
factory('app/assets');
expect(
vm
.findAll(RouterLinkStub)
.at(2)
.attributes('aria-current'),
).toEqual('page');
});
2019-09-30 21:07:59 +05:30
it('does not render add to tree dropdown when permissions are false', () => {
factory('/', { canCollaborate: false });
vm.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });
2020-03-13 15:44:24 +05:30
return vm.vm.$nextTick(() => {
2021-01-03 14:25:43 +05:30
expect(vm.find(GlDropdown).exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
2019-09-30 21:07:59 +05:30
});
it('renders add to tree dropdown when permissions are true', () => {
factory('/', { canCollaborate: true });
vm.setData({ userPermissions: { forkProject: true, createMergeRequestIn: true } });
2020-03-13 15:44:24 +05:30
return vm.vm.$nextTick(() => {
2021-01-03 14:25:43 +05:30
expect(vm.find(GlDropdown).exists()).toBe(true);
2020-03-13 15:44:24 +05:30
});
2019-09-30 21:07:59 +05:30
});
2019-09-04 21:01:54 +05:30
});