1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import { nextTick } from 'vue';
import { GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import CommitInfo from '~/repository/components/commit_info.vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
let wrapper;
const commit = {
title: 'Commit title',
titleHtml: 'Commit title html',
message: 'Commit message',
authoredDate: '2019-01-01',
authorName: 'Test authorName',
author: { name: 'Test name', avatarUrl: 'https://test.com', webPath: '/test' },
};
const findTextExpander = () => wrapper.findComponent(GlButton);
const findUserLink = () => wrapper.findByText(commit.author.name);
const findUserAvatarLink = () => wrapper.findComponent(UserAvatarLink);
const findAuthorName = () => wrapper.findByText(`${commit.authorName} authored`);
const findCommitRowDescription = () => wrapper.find('pre');
const findTitleHtml = () => wrapper.findByText(commit.titleHtml);
const createComponent = async ({ commitMock = {}, prevBlameLink } = {}) => {
wrapper = shallowMountExtended(CommitInfo, {
propsData: { commit: { ...commit, ...commitMock }, prevBlameLink },
});
await nextTick();
};
describe('Repository last commit component', () => {
it('renders author info', () => {
createComponent();
expect(findUserLink().exists()).toBe(true);
expect(findUserAvatarLink().exists()).toBe(true);
expect(findUserAvatarLink().props('imgAlt')).toBe("Test authorName's avatar");
});
it('hides author component when author does not exist', () => {
createComponent({ commitMock: { author: null } });
expect(findUserLink().exists()).toBe(false);
expect(findUserAvatarLink().exists()).toBe(false);
expect(findAuthorName().exists()).toBe(true);
});
it('does not render description expander when description is null', () => {
createComponent();
expect(findTextExpander().exists()).toBe(false);
expect(findCommitRowDescription().exists()).toBe(false);
});
describe('when the description is present', () => {
beforeEach(() => {
createComponent({ commitMock: { descriptionHtml: '
Update ADOPTERS.md' } });
});
it('strips the first newline of the description', () => {
expect(findCommitRowDescription().html()).toBe(
'<pre class="commit-row-description gl-mb-3 gl-white-space-pre-line">Update ADOPTERS.md</pre>',
);
});
it('renders commit description collapsed by default', () => {
expect(findCommitRowDescription().classes('gl-display-block!')).toBe(false);
expect(findTextExpander().classes('open')).toBe(false);
expect(findTextExpander().props('selected')).toBe(false);
});
it('expands commit description when clicking expander', async () => {
findTextExpander().vm.$emit('click');
await nextTick();
expect(findCommitRowDescription().classes('gl-display-block!')).toBe(true);
expect(findTextExpander().classes('open')).toBe(true);
expect(findTextExpander().props('selected')).toBe(true);
});
});
describe('previous blame link', () => {
const prevBlameLink = '<a>Previous blame link</a>';
it('renders a previous blame link when it is present', () => {
createComponent({ prevBlameLink });
expect(wrapper.html()).toContain(prevBlameLink);
});
it('does not render a previous blame link when it is not present', () => {
createComponent({ prevBlameLink: null });
expect(wrapper.html()).not.toContain(prevBlameLink);
});
});
it('sets correct CSS class if the commit message is empty', () => {
createComponent({ commitMock: { message: '' } });
expect(findTitleHtml().classes()).toContain('gl-font-style-italic');
});
});
|