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.

197 lines
5.9 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
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';
2021-11-18 22:05:49 +05:30
import NewDirectoryModal from '~/repository/components/new_directory_modal.vue';
2023-06-20 00:43:36 +05:30
import waitForPromises from 'helpers/wait_for_promises';
import permissionsQuery from 'shared_queries/repository/permissions.query.graphql';
import projectPathQuery from '~/repository/queries/project_path.query.graphql';
import createApolloProvider from 'helpers/mock_apollo_helper';
2019-09-04 21:01:54 +05:30
2021-10-27 15:23:28 +05:30
const defaultMockRoute = {
name: 'blobPath',
};
2023-06-20 00:43:36 +05:30
const TEST_PROJECT_PATH = 'test-project/path';
Vue.use(VueApollo);
2019-09-04 21:01:54 +05:30
describe('Repository breadcrumbs component', () => {
2021-04-29 21:17:54 +05:30
let wrapper;
2023-06-20 00:43:36 +05:30
let permissionsQuerySpy;
const createPermissionsQueryResponse = ({
pushCode = false,
forkProject = false,
createMergeRequestIn = false,
} = {}) => ({
data: {
project: {
id: 1,
__typename: '__typename',
2021-04-29 21:17:54 +05:30
userPermissions: {
2023-06-20 00:43:36 +05:30
__typename: '__typename',
pushCode,
forkProject,
createMergeRequestIn,
2021-04-29 21:17:54 +05:30
},
},
2023-06-20 00:43:36 +05:30
},
});
const factory = (currentPath, extraProps = {}, mockRoute = {}) => {
const apolloProvider = createApolloProvider([[permissionsQuery, permissionsQuerySpy]]);
apolloProvider.clients.defaultClient.cache.writeQuery({
query: projectPathQuery,
data: {
projectPath: TEST_PROJECT_PATH,
},
});
2021-04-29 21:17:54 +05:30
wrapper = shallowMount(Breadcrumbs, {
2023-06-20 00:43:36 +05:30
apolloProvider,
2021-04-29 21:17:54 +05:30
propsData: {
currentPath,
...extraProps,
},
stubs: {
RouterLink: RouterLinkStub,
},
2021-10-27 15:23:28 +05:30
mocks: {
$route: {
defaultMockRoute,
...mockRoute,
},
},
2021-04-29 21:17:54 +05:30
});
};
2023-06-20 00:43:36 +05:30
const findDropdown = () => wrapper.findComponent(GlDropdown);
2022-10-11 01:57:18 +05:30
const findUploadBlobModal = () => wrapper.findComponent(UploadBlobModal);
const findNewDirectoryModal = () => wrapper.findComponent(NewDirectoryModal);
2023-06-20 00:43:36 +05:30
const findRouterLink = () => wrapper.findAllComponents(RouterLinkStub);
beforeEach(() => {
permissionsQuerySpy = jest.fn().mockResolvedValue(createPermissionsQueryResponse());
});
it('queries for permissions', async () => {
factory('/');
// We need to wait for the projectPath query to resolve
await waitForPromises();
expect(permissionsQuerySpy).toHaveBeenCalledWith({
projectPath: TEST_PROJECT_PATH,
});
});
2021-04-29 21:17:54 +05:30
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);
2023-06-20 00:43:36 +05:30
expect(findRouterLink().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 });
2023-06-20 00:43:36 +05:30
expect(findRouterLink().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#');
2023-06-20 00:43:36 +05:30
expect(findRouterLink().at(3).props('to')).toEqual('/-/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');
2023-06-20 00:43:36 +05:30
expect(findRouterLink().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 () => {
2023-06-20 00:43:36 +05:30
factory('/', { canCollaborate: false }, {});
2022-04-04 11:22:00 +05:30
await nextTick();
2021-04-29 21:17:54 +05:30
2023-06-20 00:43:36 +05:30
expect(findDropdown().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 });
2023-06-20 00:43:36 +05:30
expect(findDropdown().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 () => {
2023-06-20 00:43:36 +05:30
permissionsQuerySpy.mockResolvedValue(
createPermissionsQueryResponse({ forkProject: true, createMergeRequestIn: true }),
);
2021-04-29 21:17:54 +05:30
2023-06-20 00:43:36 +05:30
factory('/', { canCollaborate: true });
2022-04-04 11:22:00 +05:30
await nextTick();
2021-04-29 21:17:54 +05:30
2023-06-20 00:43:36 +05:30
expect(findDropdown().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-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 () => {
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
});