debian-mirror-gitlab/spec/frontend/jobs/components/commit_block_spec.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import CommitBlock from '~/jobs/components/commit_block.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
2018-11-20 20:47:30 +05:30
describe('Commit block', () => {
2021-04-29 21:17:54 +05:30
let wrapper;
2018-11-20 20:47:30 +05:30
2021-04-29 21:17:54 +05:30
const commit = {
short_id: '1f0fb84f',
id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
commit_path: 'commit/1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
title: 'Update README.md',
};
const mergeRequest = {
iid: '!21244',
path: 'merge_requests/21244',
};
const findCommitSha = () => wrapper.findByTestId('commit-sha');
const findLinkSha = () => wrapper.findByTestId('link-commit');
const mountComponent = (props) => {
wrapper = extendedWrapper(
shallowMount(CommitBlock, {
propsData: {
commit,
...props,
},
}),
);
2018-11-20 20:47:30 +05:30
};
afterEach(() => {
2021-04-29 21:17:54 +05:30
wrapper.destroy();
2018-11-20 20:47:30 +05:30
});
2021-04-29 21:17:54 +05:30
describe('without merge request', () => {
2018-11-20 20:47:30 +05:30
beforeEach(() => {
2021-04-29 21:17:54 +05:30
mountComponent();
2018-11-20 20:47:30 +05:30
});
it('renders pipeline short sha link', () => {
2021-04-29 21:17:54 +05:30
expect(findCommitSha().attributes('href')).toBe(commit.commit_path);
expect(findCommitSha().text()).toBe(commit.short_id);
2018-11-20 20:47:30 +05:30
});
it('renders clipboard button', () => {
2021-04-29 21:17:54 +05:30
expect(wrapper.findComponent(ClipboardButton).attributes('text')).toBe(commit.id);
2018-11-20 20:47:30 +05:30
});
2018-12-13 13:39:08 +05:30
2021-04-29 21:17:54 +05:30
it('renders git commit title', () => {
expect(wrapper.text()).toContain(commit.title);
2018-11-20 20:47:30 +05:30
});
it('does not render merge request', () => {
2021-04-29 21:17:54 +05:30
expect(findLinkSha().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
});
2021-04-29 21:17:54 +05:30
describe('with merge request', () => {
it('renders merge request link and reference', () => {
mountComponent({ mergeRequest });
2018-11-20 20:47:30 +05:30
2021-04-29 21:17:54 +05:30
expect(findLinkSha().attributes('href')).toBe(mergeRequest.path);
expect(findLinkSha().text()).toBe(`!${mergeRequest.iid}`);
2018-11-20 20:47:30 +05:30
});
});
});