2021-01-03 14:25:43 +05:30
|
|
|
import { GlDropdown } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
|
2019-09-04 21:01:54 +05:30
|
|
|
import Breadcrumbs from '~/repository/components/breadcrumbs.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import UploadBlobModal from '~/repository/components/upload_blob_modal.vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
describe('Repository breadcrumbs component', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (currentPath, extraProps = {}) => {
|
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
|
|
|
userPermissions: {
|
|
|
|
loading: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(Breadcrumbs, {
|
|
|
|
propsData: {
|
|
|
|
currentPath,
|
|
|
|
...extraProps,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
RouterLink: RouterLinkStub,
|
|
|
|
},
|
|
|
|
mocks: { $apollo },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findUploadBlobModal = () => wrapper.find(UploadBlobModal);
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
afterEach(() => {
|
2021-04-29 21:17:54 +05:30
|
|
|
wrapper.destroy();
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
path | linkCount
|
|
|
|
${'/'} | ${1}
|
|
|
|
${'app'} | ${2}
|
|
|
|
${'app/assets'} | ${3}
|
|
|
|
${'app/assets/javascripts'} | ${4}
|
|
|
|
`('renders $linkCount links for path $path', ({ path, linkCount }) => {
|
|
|
|
factory(path);
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(wrapper.findAll(RouterLinkStub).length).toEqual(linkCount);
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('escapes hash in directory path', () => {
|
|
|
|
factory('app/assets/javascripts#');
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(wrapper.findAll(RouterLinkStub).at(3).props('to')).toEqual(
|
2021-03-08 18:12:59 +05:30
|
|
|
'/-/tree/app/assets/javascripts%23',
|
|
|
|
);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('renders last link as active', () => {
|
|
|
|
factory('app/assets');
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(wrapper.findAll(RouterLinkStub).at(2).attributes('aria-current')).toEqual('page');
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('does not render add to tree dropdown when permissions are false', async () => {
|
2019-09-30 21:07:59 +05:30
|
|
|
factory('/', { canCollaborate: false });
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
wrapper.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.find(GlDropdown).exists()).toBe(false);
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('renders add to tree dropdown when permissions are true', async () => {
|
2019-09-30 21:07:59 +05:30
|
|
|
factory('/', { canCollaborate: true });
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
wrapper.setData({ userPermissions: { forkProject: true, createMergeRequestIn: true } });
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.find(GlDropdown).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renders the upload blob modal', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory('/', { canEditTree: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the modal while loading', () => {
|
|
|
|
expect(findUploadBlobModal().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the modal once loaded', async () => {
|
|
|
|
wrapper.setData({ $apollo: { queries: { userPermissions: { loading: false } } } });
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(findUploadBlobModal().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
|
|
|
});
|