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

Address technical debt in commit_block

This changes the specs and removes unused CSS
due to the use of utility classes
parent 4ee871cb
<script> <script>
/* eslint-disable @gitlab/vue-require-i18n-strings */
import { GlLink } from '@gitlab/ui'; import { GlLink } from '@gitlab/ui';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
...@@ -23,9 +22,9 @@ export default { ...@@ -23,9 +22,9 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<span class="font-weight-bold">{{ __('Commit') }}</span> <span class="gl-font-weight-bold">{{ __('Commit') }}</span>
<gl-link :href="commit.commit_path" class="js-commit-sha commit-sha link-commit"> <gl-link :href="commit.commit_path" class="gl-text-blue-600!" data-testid="commit-sha">
{{ commit.short_id }} {{ commit.short_id }}
</gl-link> </gl-link>
...@@ -37,8 +36,8 @@ export default { ...@@ -37,8 +36,8 @@ export default {
/> />
<span v-if="mergeRequest"> <span v-if="mergeRequest">
in {{ __('in') }}
<gl-link :href="mergeRequest.path" class="js-link-commit link-commit" <gl-link :href="mergeRequest.path" class="gl-text-blue-600!" data-testid="link-commit"
>!{{ mergeRequest.iid }}</gl-link >!{{ mergeRequest.iid }}</gl-link
> >
</span> </span>
......
...@@ -219,10 +219,6 @@ ...@@ -219,10 +219,6 @@
} }
} }
} }
.link-commit {
color: var(--blue-600, $blue-600);
}
} }
.build-sidebar { .build-sidebar {
......
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import component from '~/jobs/components/commit_block.vue'; import CommitBlock from '~/jobs/components/commit_block.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
describe('Commit block', () => { describe('Commit block', () => {
const Component = Vue.extend(component); let wrapper;
let vm;
const props = { const defaults = {
commit: { commit: {
short_id: '1f0fb84f', short_id: '1f0fb84f',
id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c', id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
...@@ -20,70 +20,63 @@ describe('Commit block', () => { ...@@ -20,70 +20,63 @@ describe('Commit block', () => {
isLastBlock: true, isLastBlock: true,
}; };
const findCommitSha = () => wrapper.findByTestId('commit-sha');
const findLinkSha = () => wrapper.findByTestId('link-commit');
function mountComponent(props = {}) {
wrapper = extendedWrapper(
shallowMount(CommitBlock, {
propsData: {
...props,
},
}),
);
}
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
describe('pipeline short sha', () => { describe('pipeline short sha', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mountComponent(defaults);
...props,
});
}); });
it('renders pipeline short sha link', () => { it('renders pipeline short sha link', () => {
expect(vm.$el.querySelector('.js-commit-sha').getAttribute('href')).toEqual( expect(findCommitSha().attributes('href')).toBe(defaults.commit.commit_path);
props.commit.commit_path, expect(findCommitSha().text()).toBe(defaults.commit.short_id);
);
expect(vm.$el.querySelector('.js-commit-sha').textContent.trim()).toEqual(
props.commit.short_id,
);
}); });
it('renders clipboard button', () => { it('renders clipboard button', () => {
expect(vm.$el.querySelector('button').getAttribute('data-clipboard-text')).toEqual( expect(wrapper.findComponent(ClipboardButton).attributes('text')).toBe(defaults.commit.id);
props.commit.id,
);
}); });
}); });
describe('with merge request', () => { describe('with merge request', () => {
it('renders merge request link and reference', () => { it('renders merge request link and reference', () => {
vm = mountComponent(Component, { mountComponent(defaults);
...props,
});
expect(vm.$el.querySelector('.js-link-commit').getAttribute('href')).toEqual(
props.mergeRequest.path,
);
expect(vm.$el.querySelector('.js-link-commit').textContent.trim()).toEqual( expect(findLinkSha().attributes('href')).toBe(defaults.mergeRequest.path);
`!${props.mergeRequest.iid}`, expect(findLinkSha().text()).toBe(`!${defaults.mergeRequest.iid}`);
);
}); });
}); });
describe('without merge request', () => { describe('without merge request', () => {
it('does not render merge request', () => { it('does not render merge request', () => {
const copyProps = { ...props }; const copyProps = { ...defaults };
delete copyProps.mergeRequest; delete copyProps.mergeRequest;
vm = mountComponent(Component, { mountComponent(copyProps);
...copyProps,
});
expect(vm.$el.querySelector('.js-link-commit')).toBeNull(); expect(findLinkSha().exists()).toBe(false);
}); });
}); });
describe('git commit title', () => { describe('git commit title', () => {
it('renders git commit title', () => { it('renders git commit title', () => {
vm = mountComponent(Component, { mountComponent(defaults);
...props,
});
expect(vm.$el.textContent).toContain(props.commit.title); expect(wrapper.text()).toContain(defaults.commit.title);
}); });
}); });
}); });
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