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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
import { shallowMount } from '@vue/test-utils';
import SuggestionDiffRow from '~/vue_shared/components/markdown/suggestion_diff_row.vue';
const oldLine = {
can_receive_suggestion: false,
line_code: null,
meta_data: null,
new_line: null,
old_line: 5,
rich_text: 'oldrichtext',
text: 'oldplaintext',
type: 'old',
};
const newLine = {
can_receive_suggestion: false,
line_code: null,
meta_data: null,
new_line: 6,
old_line: null,
rich_text: 'newrichtext',
text: 'newplaintext',
type: 'new',
};
describe('SuggestionDiffRow', () => {
let wrapper;
const factory = (options = {}) => {
wrapper = shallowMount(SuggestionDiffRow, {
...options,
});
};
const findOldLineWrapper = () => wrapper.find('.old_line');
const findNewLineWrapper = () => wrapper.find('.new_line');
afterEach(() => {
wrapper.destroy();
});
describe('renders correctly', () => {
it('has the right classes on the wrapper', () => {
factory({
propsData: {
line: oldLine,
},
});
expect(wrapper.is('.line_holder')).toBe(true);
});
it('renders the rich text when it is available', () => {
factory({
propsData: {
line: newLine,
},
});
expect(wrapper.find('td.line_content').text()).toEqual('newrichtext');
});
it('renders the plain text when it is available but rich text is not', () => {
factory({
propsData: {
line: Object.assign({}, newLine, { rich_text: undefined }),
},
});
expect(wrapper.find('td.line_content').text()).toEqual('newplaintext');
});
it('renders a zero-width space when it has no plain or rich texts', () => {
factory({
propsData: {
line: Object.assign({}, newLine, { rich_text: undefined, text: undefined }),
},
});
expect(wrapper.find('td.line_content').text()).toEqual('\u200B');
});
});
describe('when passed line has type old', () => {
beforeEach(() => {
factory({
propsData: {
line: oldLine,
},
});
});
it('has old class when line has type old', () => {
expect(wrapper.find('td').classes()).toContain('old');
});
it('has old line number rendered', () => {
expect(findOldLineWrapper().text()).toBe('5');
});
it('has no new line number rendered', () => {
expect(findNewLineWrapper().text()).toBe('');
});
});
describe('when passed line has type new', () => {
beforeEach(() => {
factory({
propsData: {
line: newLine,
},
});
});
it('has new class when line has type new', () => {
expect(wrapper.find('td').classes()).toContain('new');
});
it('has no old line number rendered', () => {
expect(findOldLineWrapper().text()).toBe('');
});
it('has no new line number rendered', () => {
expect(findNewLineWrapper().text()).toBe('6');
});
});
});
|