debian-mirror-gitlab/spec/frontend/repository/components/last_commit_spec.js

150 lines
3.9 KiB
JavaScript
Raw Normal View History

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-13 15:44:24 +05:30
const defaultData = {
2019-09-30 21:07:59 +05:30
sha: '123456789',
title: 'Commit title',
2020-05-24 23:13:21 +05:30
titleHtml: 'Commit title',
2019-09-30 21:07:59 +05:30
message: 'Commit message',
2020-10-24 23:57:45 +05:30
webPath: '/commit/123',
2019-09-30 21:07:59 +05:30
authoredDate: '2019-01-01',
author: {
name: 'Test',
avatarUrl: 'https://test.com',
2020-10-24 23:57:45 +05:30
webPath: '/test',
2019-09-30 21:07:59 +05:30
},
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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +05:30
return vm.vm.$nextTick(() => {
2021-01-03 14:25:43 +05:30
expect(vm.find('[data-testid="last-commit-id-label"]').text()).toEqual('12345678');
2020-03-13 15:44:24 +05:30
});
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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +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', () => {
2020-10-24 23:57:45 +05:30
factory(createCommitData({ descriptionHtml: null }));
2019-09-30 21:07:59 +05:30
2020-03-13 15:44:24 +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', () => {
2020-10-24 23:57:45 +05:30
factory(createCommitData({ descriptionHtml: 'Test description' }));
2019-09-30 21:07:59 +05:30
2020-03-13 15:44:24 +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-13 15:44:24 +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
});