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

89 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import Vue from 'vue';
import component from '~/jobs/components/commit_block.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
describe('Commit block', () => {
const Component = Vue.extend(component);
let vm;
const props = {
2018-12-05 23:21:45 +05:30
commit: {
short_id: '1f0fb84f',
commit_path: 'commit/1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
title: 'Update README.md',
},
mergeRequest: {
iid: '!21244',
path: 'merge_requests/21244',
},
isLastBlock: true,
2018-11-20 20:47:30 +05:30
};
afterEach(() => {
vm.$destroy();
});
describe('pipeline short sha', () => {
beforeEach(() => {
vm = mountComponent(Component, {
...props,
});
});
it('renders pipeline short sha link', () => {
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.js-commit-sha').getAttribute('href')).toEqual(
props.commit.commit_path,
);
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.js-commit-sha').textContent.trim()).toEqual(
props.commit.short_id,
);
2018-11-20 20:47:30 +05:30
});
it('renders clipboard button', () => {
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('button').getAttribute('data-clipboard-text')).toEqual(
props.commit.short_id,
);
2018-11-20 20:47:30 +05:30
});
});
describe('with merge request', () => {
it('renders merge request link and reference', () => {
vm = mountComponent(Component, {
...props,
});
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.js-link-commit').getAttribute('href')).toEqual(
props.mergeRequest.path,
);
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.js-link-commit').textContent.trim()).toEqual(
`!${props.mergeRequest.iid}`,
);
2018-11-20 20:47:30 +05:30
});
});
describe('without merge request', () => {
it('does not render merge request', () => {
const copyProps = Object.assign({}, props);
2018-12-05 23:21:45 +05:30
delete copyProps.mergeRequest;
2018-11-20 20:47:30 +05:30
vm = mountComponent(Component, {
...copyProps,
});
expect(vm.$el.querySelector('.js-link-commit')).toBeNull();
});
});
describe('git commit title', () => {
it('renders git commit title', () => {
vm = mountComponent(Component, {
...props,
});
2018-12-05 23:21:45 +05:30
expect(vm.$el.textContent).toContain(props.commit.title);
2018-11-20 20:47:30 +05:30
});
});
});