2020-04-08 14:13:33 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-11-18 22:05:49 +05:30
|
|
|
import getDiffWithCommit from 'test_fixtures/merge_request_diffs/with_commit.json';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import { trimText } from 'helpers/text_helper';
|
|
|
|
import Component from '~/diffs/components/commit_item.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { getTimeago } from '~/lib/utils/datetime_utility';
|
2020-04-08 14:13:33 +05:30
|
|
|
import CommitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue';
|
|
|
|
|
|
|
|
const TEST_AUTHOR_NAME = 'test';
|
|
|
|
const TEST_AUTHOR_EMAIL = 'test+test@gitlab.com';
|
|
|
|
const TEST_AUTHOR_GRAVATAR = `${TEST_HOST}/avatar/test?s=40`;
|
2023-04-23 21:23:45 +05:30
|
|
|
const TEST_SIGNATURE_HTML = `<a class="btn signature-badge" data-content="signature-content" data-html="true" data-placement="top" data-title="signature-title" data-toggle="popover" role="button" tabindex="0">
|
|
|
|
<span class="gl-badge badge badge-pill badge-success md">Verified</span>
|
2022-06-21 17:19:12 +05:30
|
|
|
</a>`;
|
2020-04-08 14:13:33 +05:30
|
|
|
const TEST_PIPELINE_STATUS_PATH = `${TEST_HOST}/pipeline/status`;
|
|
|
|
|
|
|
|
describe('diffs/components/commit_item', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const timeago = getTimeago();
|
2021-11-18 22:05:49 +05:30
|
|
|
const { commit } = getDiffWithCommit;
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
const getTitleElement = () => wrapper.find('.commit-row-message.item-title');
|
|
|
|
const getDescElement = () => wrapper.find('pre.commit-row-description');
|
2020-11-24 15:15:51 +05:30
|
|
|
const getDescExpandElement = () => wrapper.find('.commit-content .js-toggle-button');
|
2021-01-03 14:25:43 +05:30
|
|
|
const getShaElement = () => wrapper.find('[data-testid="commit-sha-group"]');
|
2020-04-08 14:13:33 +05:30
|
|
|
const getAvatarElement = () => wrapper.find('.user-avatar-link');
|
|
|
|
const getCommitterElement = () => wrapper.find('.committer');
|
|
|
|
const getCommitActionsElement = () => wrapper.find('.commit-actions');
|
2022-10-11 01:57:18 +05:30
|
|
|
const getCommitPipelineStatus = () => wrapper.findComponent(CommitPipelineStatus);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const mountComponent = (propsData) => {
|
2020-04-08 14:13:33 +05:30
|
|
|
wrapper = mount(Component, {
|
2020-04-22 19:07:51 +05:30
|
|
|
propsData: {
|
|
|
|
commit,
|
|
|
|
...propsData,
|
|
|
|
},
|
2020-04-08 14:13:33 +05:30
|
|
|
stubs: {
|
|
|
|
CommitPipelineStatus: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('default state', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders commit title', () => {
|
|
|
|
const titleElement = getTitleElement();
|
|
|
|
|
|
|
|
expect(titleElement.attributes('href')).toBe(commit.commit_url);
|
|
|
|
expect(titleElement.text()).toBe(commit.title_html);
|
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it('renders commit description', () => {
|
2020-04-08 14:13:33 +05:30
|
|
|
const descElement = getDescElement();
|
|
|
|
const descExpandElement = getDescExpandElement();
|
|
|
|
|
|
|
|
const expected = commit.description_html.replace(/
/g, '');
|
|
|
|
|
|
|
|
expect(trimText(descElement.text())).toEqual(trimText(expected));
|
|
|
|
expect(descExpandElement.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders commit sha', () => {
|
|
|
|
const shaElement = getShaElement();
|
2021-02-22 17:27:13 +05:30
|
|
|
const labelElement = shaElement.find('[data-testid="commit-sha-short-id"]');
|
2021-01-03 14:25:43 +05:30
|
|
|
const buttonElement = shaElement.find('button.input-group-text');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(labelElement.text()).toEqual(commit.short_id);
|
|
|
|
expect(buttonElement.props('text')).toBe(commit.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders author avatar', () => {
|
|
|
|
const avatarElement = getAvatarElement();
|
|
|
|
const imgElement = avatarElement.find('img');
|
|
|
|
|
|
|
|
expect(avatarElement.attributes('href')).toBe(commit.author.web_url);
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(imgElement.classes()).toContain('gl-avatar-s32');
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(imgElement.attributes('alt')).toBe(commit.author.name);
|
|
|
|
expect(imgElement.attributes('src')).toBe(commit.author.avatar_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders committer text', () => {
|
|
|
|
const committerElement = getCommitterElement();
|
|
|
|
const nameElement = committerElement.find('a');
|
|
|
|
|
|
|
|
const expectTimeText = timeago.format(commit.authored_date);
|
|
|
|
const expectedText = `${commit.author.name} authored ${expectTimeText}`;
|
|
|
|
|
|
|
|
expect(trimText(committerElement.text())).toEqual(expectedText);
|
|
|
|
expect(nameElement.attributes('href')).toBe(commit.author.web_url);
|
|
|
|
expect(nameElement.text()).toBe(commit.author.name);
|
|
|
|
expect(nameElement.classes()).toContain('js-user-link');
|
|
|
|
expect(nameElement.attributes('data-user-id')).toEqual(commit.author.id.toString());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without commit description', () => {
|
|
|
|
beforeEach(() => {
|
2020-04-22 19:07:51 +05:30
|
|
|
mountComponent({ commit: { ...commit, description_html: '' } });
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hides description', () => {
|
|
|
|
const descElement = getDescElement();
|
|
|
|
const descExpandElement = getDescExpandElement();
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(descElement.exists()).toBe(false);
|
|
|
|
expect(descExpandElement.exists()).toBe(false);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with no matching user', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent({
|
|
|
|
commit: {
|
2020-04-22 19:07:51 +05:30
|
|
|
...commit,
|
2020-04-08 14:13:33 +05:30
|
|
|
author: null,
|
|
|
|
author_email: TEST_AUTHOR_EMAIL,
|
|
|
|
author_name: TEST_AUTHOR_NAME,
|
|
|
|
author_gravatar_url: TEST_AUTHOR_GRAVATAR,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders author avatar', () => {
|
|
|
|
const avatarElement = getAvatarElement();
|
|
|
|
const imgElement = avatarElement.find('img');
|
|
|
|
|
|
|
|
expect(avatarElement.attributes('href')).toBe(`mailto:${TEST_AUTHOR_EMAIL}`);
|
|
|
|
expect(imgElement.attributes('alt')).toBe(TEST_AUTHOR_NAME);
|
|
|
|
expect(imgElement.attributes('src')).toBe(TEST_AUTHOR_GRAVATAR);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders committer text', () => {
|
|
|
|
const committerElement = getCommitterElement();
|
|
|
|
const nameElement = committerElement.find('a');
|
|
|
|
|
|
|
|
expect(nameElement.attributes('href')).toBe(`mailto:${TEST_AUTHOR_EMAIL}`);
|
|
|
|
expect(nameElement.text()).toBe(TEST_AUTHOR_NAME);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with signature', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent({
|
2020-04-22 19:07:51 +05:30
|
|
|
commit: { ...commit, signature_html: TEST_SIGNATURE_HTML },
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders signature html', () => {
|
|
|
|
const actionsElement = getCommitActionsElement();
|
2023-04-23 21:23:45 +05:30
|
|
|
const signatureElement = actionsElement.find('.signature-badge');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(signatureElement.html()).toBe(TEST_SIGNATURE_HTML);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with pipeline status', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent({
|
2020-04-22 19:07:51 +05:30
|
|
|
commit: { ...commit, pipeline_status_path: TEST_PIPELINE_STATUS_PATH },
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipeline status', () => {
|
|
|
|
expect(getCommitPipelineStatus().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|