Commit ac271061 authored by Jose Vargas's avatar Jose Vargas Committed by Andrew Fontaine

Refactor commit_block specs

parent d1bfaeb2
...@@ -6,77 +6,65 @@ import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; ...@@ -6,77 +6,65 @@ import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
describe('Commit block', () => { describe('Commit block', () => {
let wrapper; let wrapper;
const defaults = { const commit = {
commit: { short_id: '1f0fb84f',
short_id: '1f0fb84f', id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c', commit_path: 'commit/1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
commit_path: 'commit/1f0fb84fb6770d74d97eee58118fd3909cd4f48c', title: 'Update README.md',
title: 'Update README.md', };
},
mergeRequest: { const mergeRequest = {
iid: '!21244', iid: '!21244',
path: 'merge_requests/21244', path: 'merge_requests/21244',
},
isLastBlock: true,
}; };
const findCommitSha = () => wrapper.findByTestId('commit-sha'); const findCommitSha = () => wrapper.findByTestId('commit-sha');
const findLinkSha = () => wrapper.findByTestId('link-commit'); const findLinkSha = () => wrapper.findByTestId('link-commit');
function mountComponent(props = {}) { const mountComponent = (props) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
shallowMount(CommitBlock, { shallowMount(CommitBlock, {
propsData: { propsData: {
commit,
...props, ...props,
}, },
}), }),
); );
} };
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('pipeline short sha', () => { describe('without merge request', () => {
beforeEach(() => { beforeEach(() => {
mountComponent(defaults); mountComponent();
}); });
it('renders pipeline short sha link', () => { it('renders pipeline short sha link', () => {
expect(findCommitSha().attributes('href')).toBe(defaults.commit.commit_path); expect(findCommitSha().attributes('href')).toBe(commit.commit_path);
expect(findCommitSha().text()).toBe(defaults.commit.short_id); expect(findCommitSha().text()).toBe(commit.short_id);
}); });
it('renders clipboard button', () => { it('renders clipboard button', () => {
expect(wrapper.findComponent(ClipboardButton).attributes('text')).toBe(defaults.commit.id); expect(wrapper.findComponent(ClipboardButton).attributes('text')).toBe(commit.id);
}); });
});
describe('with merge request', () => {
it('renders merge request link and reference', () => {
mountComponent(defaults);
expect(findLinkSha().attributes('href')).toBe(defaults.mergeRequest.path); it('renders git commit title', () => {
expect(findLinkSha().text()).toBe(`!${defaults.mergeRequest.iid}`); expect(wrapper.text()).toContain(commit.title);
}); });
});
describe('without merge request', () => {
it('does not render merge request', () => { it('does not render merge request', () => {
const copyProps = { ...defaults };
delete copyProps.mergeRequest;
mountComponent(copyProps);
expect(findLinkSha().exists()).toBe(false); expect(findLinkSha().exists()).toBe(false);
}); });
}); });
describe('git commit title', () => { describe('with merge request', () => {
it('renders git commit title', () => { it('renders merge request link and reference', () => {
mountComponent(defaults); mountComponent({ mergeRequest });
expect(wrapper.text()).toContain(defaults.commit.title); expect(findLinkSha().attributes('href')).toBe(mergeRequest.path);
expect(findLinkSha().text()).toBe(`!${mergeRequest.iid}`);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment