2019-09-30 21:07:59 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import LastCommit from '~/repository/components/last_commit.vue';
|
|
|
|
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
|
|
|
|
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
function createCommitData(data = {}) {
|
2020-03-09 13:42:32 +05:30
|
|
|
const defaultData = {
|
2019-09-30 21:07:59 +05:30
|
|
|
sha: '123456789',
|
|
|
|
title: 'Commit title',
|
|
|
|
message: 'Commit message',
|
|
|
|
webUrl: 'https://test.com/commit/123',
|
|
|
|
authoredDate: '2019-01-01',
|
|
|
|
author: {
|
|
|
|
name: 'Test',
|
|
|
|
avatarUrl: 'https://test.com',
|
|
|
|
webUrl: 'https://test.com/test',
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
pipeline: {
|
2019-09-30 21:07:59 +05:30
|
|
|
detailedStatus: {
|
|
|
|
detailsPath: 'https://test.com/pipeline',
|
|
|
|
icon: 'failed',
|
|
|
|
tooltip: 'failed',
|
|
|
|
text: 'failed',
|
|
|
|
group: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-03-09 13:42:32 +05:30
|
|
|
return Object.assign(defaultData, data);
|
2019-09-30 21:07:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function factory(commit = createCommitData(), loading = false) {
|
|
|
|
vm = shallowMount(LastCommit, {
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
commit: {
|
|
|
|
loading: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
vm.setData({ commit });
|
|
|
|
vm.vm.$apollo.queries.commit.loading = loading;
|
|
|
|
}
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
const emptyMessageClass = 'font-italic';
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe('Repository last commit component', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
vm.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
loading | label
|
|
|
|
${true} | ${'shows'}
|
|
|
|
${false} | ${'hides'}
|
|
|
|
`('$label when loading icon $loading is true', ({ loading }) => {
|
|
|
|
factory(createCommitData(), loading);
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find(GlLoadingIcon).exists()).toBe(loading);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders commit widget', () => {
|
|
|
|
factory();
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.element).toMatchSnapshot();
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders short commit ID', () => {
|
|
|
|
factory();
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find('.label-monospace').text()).toEqual('12345678');
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hides pipeline components when pipeline does not exist', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
factory(createCommitData({ pipeline: null }));
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find('.js-commit-pipeline').exists()).toBe(false);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipeline components', () => {
|
|
|
|
factory();
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find('.js-commit-pipeline').exists()).toBe(true);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hides author component when author does not exist', () => {
|
|
|
|
factory(createCommitData({ author: null }));
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find('.js-user-link').exists()).toBe(false);
|
|
|
|
expect(vm.find(UserAvatarLink).exists()).toBe(false);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render description expander when description is null', () => {
|
|
|
|
factory(createCommitData({ description: null }));
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find('.text-expander').exists()).toBe(false);
|
|
|
|
expect(vm.find('.commit-row-description').exists()).toBe(false);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('expands commit description when clicking expander', () => {
|
|
|
|
factory(createCommitData({ description: 'Test description' }));
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
vm.find('.text-expander').vm.$emit('click');
|
|
|
|
return vm.vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.find('.commit-row-description').isVisible()).toBe(true);
|
|
|
|
expect(vm.find('.text-expander').classes('open')).toBe(true);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it('renders the signature HTML as returned by the backend', () => {
|
|
|
|
factory(createCommitData({ signatureHtml: '<button>Verified</button>' }));
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
return vm.vm.$nextTick().then(() => {
|
|
|
|
expect(vm.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets correct CSS class if the commit message is empty', () => {
|
|
|
|
factory(createCommitData({ message: '' }));
|
|
|
|
|
|
|
|
return vm.vm.$nextTick().then(() => {
|
|
|
|
expect(vm.find('.item-title').classes()).toContain(emptyMessageClass);
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|