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

158 lines
4 KiB
JavaScript
Raw Normal View History

2019-09-30 21:07:59 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2019-09-30 21:07:59 +05:30
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'}
2021-03-11 19:13:27 +05:30
`('$label when loading icon $loading is true', async ({ loading }) => {
2019-09-30 21:07:59 +05:30
factory(createCommitData(), loading);
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.find(GlLoadingIcon).exists()).toBe(loading);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders commit widget', async () => {
2019-09-30 21:07:59 +05:30
factory();
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.element).toMatchSnapshot();
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders short commit ID', async () => {
2019-09-30 21:07:59 +05:30
factory();
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.find('[data-testid="last-commit-id-label"]').text()).toEqual('12345678');
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('hides pipeline components when pipeline does not exist', async () => {
2019-12-26 22:10:19 +05:30
factory(createCommitData({ pipeline: null }));
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.find('.js-commit-pipeline').exists()).toBe(false);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('renders pipeline components', async () => {
2019-09-30 21:07:59 +05:30
factory();
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.find('.js-commit-pipeline').exists()).toBe(true);
2019-09-30 21:07:59 +05:30
});
2021-03-11 19:13:27 +05:30
it('hides author component when author does not exist', async () => {
2019-09-30 21:07:59 +05:30
factory(createCommitData({ author: null }));
2021-03-11 19:13:27 +05:30
await 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
});
2021-03-11 19:13:27 +05:30
it('does not render description expander when description is null', async () => {
2020-10-24 23:57:45 +05:30
factory(createCommitData({ descriptionHtml: null }));
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
await 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
});
2021-03-11 19:13:27 +05:30
it('expands commit description when clicking expander', async () => {
2020-10-24 23:57:45 +05:30
factory(createCommitData({ descriptionHtml: 'Test description' }));
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
vm.find('.text-expander').vm.$emit('click');
await vm.vm.$nextTick();
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
2021-03-08 18:12:59 +05:30
it('strips the first newline of the description', async () => {
factory(createCommitData({ descriptionHtml: '
Update ADOPTERS.md' }));
await vm.vm.$nextTick();
expect(vm.find('.commit-row-description').html()).toBe(
'<pre class="commit-row-description gl-mb-3">Update ADOPTERS.md</pre>',
);
});
2021-03-11 19:13:27 +05:30
it('renders the signature HTML as returned by the backend', async () => {
2019-12-21 20:55:43 +05:30
factory(createCommitData({ signatureHtml: '<button>Verified</button>' }));
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.element).toMatchSnapshot();
2020-03-13 15:44:24 +05:30
});
2021-03-11 19:13:27 +05:30
it('sets correct CSS class if the commit message is empty', async () => {
2020-03-13 15:44:24 +05:30
factory(createCommitData({ message: '' }));
2021-03-11 19:13:27 +05:30
await vm.vm.$nextTick();
expect(vm.find('.item-title').classes()).toContain(emptyMessageClass);
2019-12-21 20:55:43 +05:30
});
2019-09-30 21:07:59 +05:30
});