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

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

252 lines
7.4 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
2019-09-30 21:07:59 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2022-08-13 15:12:31 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2019-09-30 21:07:59 +05:30
import LastCommit from '~/repository/components/last_commit.vue';
2023-05-27 22:25:52 +05:30
import SignatureBadge from '~/commit/components/signature_badge.vue';
2019-09-30 21:07:59 +05:30
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2023-06-20 00:43:36 +05:30
import eventHub from '~/repository/event_hub';
2022-08-13 15:12:31 +05:30
import pathLastCommitQuery from 'shared_queries/repository/path_last_commit.query.graphql';
2023-06-20 00:43:36 +05:30
import { FORK_UPDATED_EVENT } from '~/repository/constants';
2022-08-13 15:12:31 +05:30
import { refMock } from '../mock_data';
let wrapper;
let mockResolver;
const findPipeline = () => wrapper.find('.js-commit-pipeline');
const findTextExpander = () => wrapper.find('.text-expander');
const findUserLink = () => wrapper.find('.js-user-link');
const findUserAvatarLink = () => wrapper.findComponent(UserAvatarLink);
const findLastCommitLabel = () => wrapper.findByTestId('last-commit-id-label');
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findCommitRowDescription = () => wrapper.find('.commit-row-description');
2023-05-27 22:25:52 +05:30
const findStatusBox = () => wrapper.findComponent(SignatureBadge);
2022-08-13 15:12:31 +05:30
const findItemTitle = () => wrapper.find('.item-title');
const defaultPipelineEdges = [
{
__typename: 'PipelineEdge',
node: {
__typename: 'Pipeline',
id: 'gid://gitlab/Ci::Pipeline/167',
2019-09-30 21:07:59 +05:30
detailedStatus: {
2022-08-13 15:12:31 +05:30
__typename: 'DetailedStatus',
id: 'id',
2019-09-30 21:07:59 +05:30
detailsPath: 'https://test.com/pipeline',
2022-08-13 15:12:31 +05:30
icon: 'status_running',
2019-09-30 21:07:59 +05:30
tooltip: 'failed',
text: 'failed',
2022-08-13 15:12:31 +05:30
group: 'failed',
2019-09-30 21:07:59 +05:30
},
},
2022-08-13 15:12:31 +05:30
},
];
const defaultAuthor = {
__typename: 'UserCore',
id: 'gid://gitlab/User/1',
name: 'Test',
avatarUrl: 'https://test.com',
webPath: '/test',
};
const defaultMessage = 'Commit title';
const createCommitData = ({
pipelineEdges = defaultPipelineEdges,
author = defaultAuthor,
descriptionHtml = '',
2023-05-27 22:25:52 +05:30
signature = null,
2022-08-13 15:12:31 +05:30
message = defaultMessage,
}) => {
return {
data: {
project: {
__typename: 'Project',
id: 'gid://gitlab/Project/6',
repository: {
__typename: 'Repository',
paginatedTree: {
__typename: 'TreeConnection',
nodes: [
{
__typename: 'Tree',
lastCommit: {
__typename: 'Commit',
id: 'gid://gitlab/CommitPresenter/123456789',
sha: '123456789',
title: 'Commit title',
titleHtml: 'Commit title',
descriptionHtml,
message,
webPath: '/commit/123',
authoredDate: '2019-01-01',
authorName: 'Test',
authorGravatar: 'https://test.com',
author,
2023-05-27 22:25:52 +05:30
signature,
2022-08-13 15:12:31 +05:30
pipelines: {
__typename: 'PipelineConnection',
edges: pipelineEdges,
},
},
},
],
2019-09-30 21:07:59 +05:30
},
},
},
},
2022-08-13 15:12:31 +05:30
};
};
2019-09-30 21:07:59 +05:30
2023-06-20 00:43:36 +05:30
const createComponent = (data = {}) => {
2022-08-13 15:12:31 +05:30
Vue.use(VueApollo);
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
const currentPath = 'path';
mockResolver = jest.fn().mockResolvedValue(createCommitData(data));
wrapper = shallowMountExtended(LastCommit, {
apolloProvider: createMockApollo([[pathLastCommitQuery, mockResolver]]),
propsData: { currentPath },
mixins: [{ data: () => ({ ref: refMock }) }],
2023-05-27 22:25:52 +05:30
stubs: {
SignatureBadge,
},
2019-09-30 21:07:59 +05:30
});
2022-08-13 15:12:31 +05:30
};
afterEach(() => {
mockResolver = null;
});
2019-09-30 21:07:59 +05:30
2022-08-13 15:12:31 +05:30
describe('Repository last commit component', () => {
2019-09-30 21:07:59 +05:30
it.each`
loading | label
${true} | ${'shows'}
${false} | ${'hides'}
2022-08-13 15:12:31 +05:30
`('$label when loading icon is $loading', async ({ loading }) => {
createComponent();
2019-09-30 21:07:59 +05:30
2022-08-13 15:12:31 +05:30
if (!loading) {
await waitForPromises();
}
2021-03-11 19:13:27 +05:30
2022-08-13 15:12:31 +05:30
expect(findLoadingIcon().exists()).toBe(loading);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders commit widget', async () => {
2022-08-13 15:12:31 +05:30
createComponent();
await waitForPromises();
2019-09-30 21:07:59 +05:30
2022-08-13 15:12:31 +05:30
expect(wrapper.element).toMatchSnapshot();
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders short commit ID', async () => {
2022-08-13 15:12:31 +05:30
createComponent();
await waitForPromises();
2021-03-11 19:13:27 +05:30
2022-08-13 15:12:31 +05:30
expect(findLastCommitLabel().text()).toBe('12345678');
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('hides pipeline components when pipeline does not exist', async () => {
2022-08-13 15:12:31 +05:30
createComponent({ pipelineEdges: [] });
await waitForPromises();
2019-09-30 21:07:59 +05:30
2022-08-13 15:12:31 +05:30
expect(findPipeline().exists()).toBe(false);
2019-09-30 21:07:59 +05:30
});
2022-08-13 15:12:31 +05:30
it('renders pipeline components when pipeline exists', async () => {
createComponent();
await waitForPromises();
2021-03-11 19:13:27 +05:30
2022-08-13 15:12:31 +05:30
expect(findPipeline().exists()).toBe(true);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('hides author component when author does not exist', async () => {
2022-08-13 15:12:31 +05:30
createComponent({ author: null });
await waitForPromises();
2019-09-30 21:07:59 +05:30
2022-08-13 15:12:31 +05:30
expect(findUserLink().exists()).toBe(false);
expect(findUserAvatarLink().exists()).toBe(false);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('does not render description expander when description is null', async () => {
2022-08-13 15:12:31 +05:30
createComponent();
await waitForPromises();
2021-03-11 19:13:27 +05:30
2022-08-13 15:12:31 +05:30
expect(findTextExpander().exists()).toBe(false);
expect(findCommitRowDescription().exists()).toBe(false);
2019-09-30 21:07:59 +05:30
});
2023-06-20 00:43:36 +05:30
describe('created', () => {
it('binds `epicsListScrolled` event listener via eventHub', () => {
jest.spyOn(eventHub, '$on').mockImplementation(() => {});
createComponent();
expect(eventHub.$on).toHaveBeenCalledWith(FORK_UPDATED_EVENT, expect.any(Function));
});
});
describe('beforeDestroy', () => {
it('unbinds `epicsListScrolled` event listener via eventHub', () => {
jest.spyOn(eventHub, '$off').mockImplementation(() => {});
createComponent();
wrapper.destroy();
expect(eventHub.$off).toHaveBeenCalledWith(FORK_UPDATED_EVENT, expect.any(Function));
});
});
2022-08-13 15:12:31 +05:30
describe('when the description is present', () => {
beforeEach(async () => {
createComponent({ descriptionHtml: '
Update ADOPTERS.md' });
await waitForPromises();
});
it('strips the first newline of the description', () => {
expect(findCommitRowDescription().html()).toBe(
2022-11-25 23:54:43 +05:30
'<pre class="commit-row-description gl-mb-3 gl-white-space-pre-line">Update ADOPTERS.md</pre>',
2022-08-13 15:12:31 +05:30
);
});
it('expands commit description when clicking expander', async () => {
2022-10-11 01:57:18 +05:30
expect(findCommitRowDescription().classes('d-block')).toBe(false);
expect(findTextExpander().classes('open')).toBe(false);
expect(findTextExpander().props('selected')).toBe(false);
2022-08-13 15:12:31 +05:30
findTextExpander().vm.$emit('click');
await nextTick();
2022-10-11 01:57:18 +05:30
expect(findCommitRowDescription().classes('d-block')).toBe(true);
expect(findTextExpander().classes('open')).toBe(true);
expect(findTextExpander().props('selected')).toBe(true);
2022-08-13 15:12:31 +05:30
});
2021-03-08 18:12:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders the signature HTML as returned by the backend', async () => {
2023-05-27 22:25:52 +05:30
const signatureResponse = {
__typename: 'GpgSignature',
gpgKeyPrimaryKeyid: 'xxx',
verificationStatus: 'VERIFIED',
};
2022-08-13 15:12:31 +05:30
createComponent({
2023-05-27 22:25:52 +05:30
signature: {
...signatureResponse,
},
2022-08-13 15:12:31 +05:30
});
await waitForPromises();
2023-05-27 22:25:52 +05:30
expect(findStatusBox().props()).toMatchObject({ signature: signatureResponse });
2020-03-13 15:44:24 +05:30
});
2021-03-11 19:13:27 +05:30
it('sets correct CSS class if the commit message is empty', async () => {
2022-08-13 15:12:31 +05:30
createComponent({ message: '' });
await waitForPromises();
2021-03-11 19:13:27 +05:30
2022-08-13 15:12:31 +05:30
expect(findItemTitle().classes()).toContain('font-italic');
2019-12-21 20:55:43 +05:30
});
2019-09-30 21:07:59 +05:30
});