2020-10-14 17:08:38 -04:00
|
|
|
import { GlDropdown } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
|
2019-05-29 05:24:35 -04:00
|
|
|
import Breadcrumbs from '~/repository/components/breadcrumbs.vue';
|
2021-03-16 08:11:31 -04:00
|
|
|
import UploadBlobModal from '~/repository/components/upload_blob_modal.vue';
|
2021-10-11 02:13:09 -04:00
|
|
|
import NewDirectoryModal from '~/repository/components/new_directory_modal.vue';
|
2021-02-23 04:10:45 -05:00
|
|
|
|
2021-08-06 08:10:15 -04:00
|
|
|
const defaultMockRoute = {
|
|
|
|
name: 'blobPath',
|
|
|
|
};
|
|
|
|
|
2021-03-03 04:10:53 -05:00
|
|
|
describe('Repository breadcrumbs component', () => {
|
2021-03-16 08:11:31 -04:00
|
|
|
let wrapper;
|
|
|
|
|
2021-10-11 02:13:09 -04:00
|
|
|
const factory = (currentPath, extraProps = {}, mockRoute = {}, newDirModal = true) => {
|
2021-03-16 08:11:31 -04:00
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
|
|
|
userPermissions: {
|
|
|
|
loading: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(Breadcrumbs, {
|
|
|
|
propsData: {
|
|
|
|
currentPath,
|
|
|
|
...extraProps,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
RouterLink: RouterLinkStub,
|
|
|
|
},
|
2021-08-06 08:10:15 -04:00
|
|
|
mocks: {
|
|
|
|
$route: {
|
|
|
|
defaultMockRoute,
|
|
|
|
...mockRoute,
|
|
|
|
},
|
|
|
|
$apollo,
|
|
|
|
},
|
2021-10-11 02:13:09 -04:00
|
|
|
provide: { glFeatures: { newDirModal } },
|
2021-03-16 08:11:31 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findUploadBlobModal = () => wrapper.find(UploadBlobModal);
|
2021-10-11 02:13:09 -04:00
|
|
|
const findNewDirectoryModal = () => wrapper.find(NewDirectoryModal);
|
2021-03-16 08:11:31 -04:00
|
|
|
|
2019-05-29 05:24:35 -04:00
|
|
|
afterEach(() => {
|
2021-03-16 08:11:31 -04:00
|
|
|
wrapper.destroy();
|
2019-05-29 05:24:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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-03-16 08:11:31 -04:00
|
|
|
expect(wrapper.findAll(RouterLinkStub).length).toEqual(linkCount);
|
2019-05-29 05:24:35 -04:00
|
|
|
});
|
|
|
|
|
2020-02-06 10:09:11 -05:00
|
|
|
it('escapes hash in directory path', () => {
|
|
|
|
factory('app/assets/javascripts#');
|
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
expect(wrapper.findAll(RouterLinkStub).at(3).props('to')).toEqual(
|
2020-12-23 07:10:26 -05:00
|
|
|
'/-/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');
|
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
expect(wrapper.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
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
it('does not render add to tree dropdown when permissions are false', async () => {
|
2019-07-10 08:17:45 -04:00
|
|
|
factory('/', { canCollaborate: false });
|
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
wrapper.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });
|
2019-07-10 08:17:45 -04:00
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.find(GlDropdown).exists()).toBe(false);
|
2019-07-10 08:17:45 -04:00
|
|
|
});
|
|
|
|
|
2021-08-06 08:10:15 -04:00
|
|
|
it.each`
|
|
|
|
routeName | isRendered
|
|
|
|
${'blobPath'} | ${false}
|
|
|
|
${'blobPathDecoded'} | ${false}
|
|
|
|
${'treePath'} | ${true}
|
|
|
|
${'treePathDecoded'} | ${true}
|
|
|
|
${'projectRoot'} | ${true}
|
|
|
|
`(
|
|
|
|
'does render add to tree dropdown $isRendered when route is $routeName',
|
|
|
|
({ routeName, isRendered }) => {
|
|
|
|
factory('app/assets/javascripts.js', { canCollaborate: true }, { name: routeName });
|
|
|
|
expect(wrapper.find(GlDropdown).exists()).toBe(isRendered);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
it('renders add to tree dropdown when permissions are true', async () => {
|
2019-07-10 08:17:45 -04:00
|
|
|
factory('/', { canCollaborate: true });
|
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
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-07-10 08:17:45 -04:00
|
|
|
|
2021-03-16 08:11:31 -04:00
|
|
|
expect(findUploadBlobModal().exists()).toBe(true);
|
2020-01-01 01:09:01 -05:00
|
|
|
});
|
2019-07-10 08:17:45 -04:00
|
|
|
});
|
2021-10-11 02:13:09 -04:00
|
|
|
|
|
|
|
describe('renders the new directory modal', () => {
|
|
|
|
describe('with the feature flag enabled', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
window.gon.features = {
|
|
|
|
newDirModal: true,
|
|
|
|
};
|
|
|
|
factory('/', { canEditTree: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the modal while loading', () => {
|
|
|
|
expect(findNewDirectoryModal().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the modal once loaded', async () => {
|
|
|
|
wrapper.setData({ $apollo: { queries: { userPermissions: { loading: false } } } });
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findNewDirectoryModal().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with the feature flag disabled', () => {
|
|
|
|
it('does not render the modal', () => {
|
|
|
|
window.gon.features = {
|
|
|
|
newDirModal: false,
|
|
|
|
};
|
|
|
|
factory('/', { canEditTree: true }, {}, {}, false);
|
|
|
|
expect(findNewDirectoryModal().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-05-29 05:24:35 -04:00
|
|
|
});
|