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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

170 lines
5.5 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;
2022-06-21 17:19:12 +05:30
const factory = (currentPath, extraProps = {}, mockRoute = {}) => {
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-04-29 21:17:54 +05:30
});
};
2022-10-11 01:57:18 +05:30
const findUploadBlobModal = () => wrapper.findComponent(UploadBlobModal);
const findNewDirectoryModal = () => wrapper.findComponent(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);
2022-10-11 01:57:18 +05:30
expect(wrapper.findAllComponents(RouterLinkStub).length).toEqual(linkCount);
2019-09-04 21:01:54 +05:30
});
2022-05-07 20:08:51 +05:30
it.each`
routeName | path | linkTo
${'treePath'} | ${'app/assets/javascripts'} | ${'/-/tree/app/assets/javascripts'}
${'treePathDecoded'} | ${'app/assets/javascripts'} | ${'/-/tree/app/assets/javascripts'}
${'blobPath'} | ${'app/assets/index.js'} | ${'/-/blob/app/assets/index.js'}
${'blobPathDecoded'} | ${'app/assets/index.js'} | ${'/-/blob/app/assets/index.js'}
`(
'links to the correct router path when routeName is $routeName',
({ routeName, path, linkTo }) => {
factory(path, {}, { name: routeName });
2022-10-11 01:57:18 +05:30
expect(wrapper.findAllComponents(RouterLinkStub).at(3).props('to')).toEqual(linkTo);
2022-05-07 20:08:51 +05:30
},
);
2020-03-13 15:44:24 +05:30
it('escapes hash in directory path', () => {
factory('app/assets/javascripts#');
2022-10-11 01:57:18 +05:30
expect(wrapper.findAllComponents(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');
2022-10-11 01:57:18 +05:30
expect(wrapper.findAllComponents(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
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(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 });
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(GlDropdown).exists()).toBe(isRendered);
2021-10-27 15:23:28 +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 });
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
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(GlDropdown).exists()).toBe(true);
2021-04-29 21:17:54 +05:30
});
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', () => {
2022-06-21 17:19:12 +05:30
beforeEach(() => {
2022-07-16 23:28:13 +05:30
factory('some_dir', { canEditTree: true, newDirPath: 'root/master' });
2022-06-21 17:19:12 +05:30
});
it('does not render the modal while loading', () => {
expect(findNewDirectoryModal().exists()).toBe(false);
2021-11-18 22:05:49 +05:30
});
2022-06-21 17:19:12 +05:30
it('renders the modal once loaded', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({ $apollo: { queries: { userPermissions: { loading: false } } } });
await nextTick();
expect(findNewDirectoryModal().exists()).toBe(true);
2022-07-16 23:28:13 +05:30
expect(findNewDirectoryModal().props('path')).toBe('root/master/some_dir');
2021-11-18 22:05:49 +05:30
});
});
2019-09-04 21:01:54 +05:30
});