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

170 lines
5.1 KiB
JavaScript
Raw Normal View History

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';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
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';
2021-11-18 22:05:49 +05:30
import NewDirectoryModal from '~/repository/components/new_directory_modal.vue';
2019-09-04 21:01:54 +05:30
2021-10-27 15:23:28 +05:30
const defaultMockRoute = {
name: 'blobPath',
};
2019-09-04 21:01:54 +05:30
describe('Repository breadcrumbs component', () => {
2021-04-29 21:17:54 +05:30
let wrapper;
2021-11-18 22:05:49 +05:30
const factory = (currentPath, extraProps = {}, mockRoute = {}, newDirModal = true) => {
2021-04-29 21:17:54 +05:30
const $apollo = {
queries: {
userPermissions: {
loading: true,
},
},
};
wrapper = shallowMount(Breadcrumbs, {
propsData: {
currentPath,
...extraProps,
},
stubs: {
RouterLink: RouterLinkStub,
},
2021-10-27 15:23:28 +05:30
mocks: {
$route: {
defaultMockRoute,
...mockRoute,
},
$apollo,
},
2021-11-18 22:05:49 +05:30
provide: { glFeatures: { newDirModal } },
2021-04-29 21:17:54 +05:30
});
};
const findUploadBlobModal = () => wrapper.find(UploadBlobModal);
2021-11-18 22:05:49 +05:30
const findNewDirectoryModal = () => wrapper.find(NewDirectoryModal);
2021-04-29 21:17:54 +05:30
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 });
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2021-04-29 21:17:54 +05:30
wrapper.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2021-04-29 21:17:54 +05:30
expect(wrapper.find(GlDropdown).exists()).toBe(false);
2019-09-30 21:07:59 +05:30
});
2021-10-27 15:23:28 +05:30
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-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 });
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2021-04-29 21:17:54 +05:30
wrapper.setData({ userPermissions: { forkProject: true, createMergeRequestIn: true } });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-04-29 21:17:54 +05:30
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 () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2021-04-29 21:17:54 +05:30
wrapper.setData({ $apollo: { queries: { userPermissions: { loading: false } } } });
2022-04-04 11:22:00 +05:30
await 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
});
2021-11-18 22:05:49 +05:30
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 () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2021-11-18 22:05:49 +05:30
wrapper.setData({ $apollo: { queries: { userPermissions: { loading: false } } } });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-11-18 22:05:49 +05:30
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-09-04 21:01:54 +05:30
});