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
|
import { nextTick } from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import SuggestionsComponent from '~/vue_shared/components/markdown/suggestions.vue';
const MOCK_DATA = {
suggestions: [
{
id: 1,
appliable: true,
applied: false,
current_user: {
can_apply: true,
},
diff_lines: [
{
can_receive_suggestion: false,
line_code: null,
meta_data: null,
new_line: null,
old_line: 5,
rich_text: '-test',
text: '-test',
type: 'old',
},
{
can_receive_suggestion: true,
line_code: null,
meta_data: null,
new_line: 5,
old_line: null,
rich_text: '+new test',
text: '+new test',
type: 'new',
},
],
},
],
noteHtml: `
<div class="suggestion">
<div class="line">-oldtest</div>
</div>
<div class="suggestion">
<div class="line">+newtest</div>
</div>
`,
isApplied: false,
helpPagePath: 'path_to_docs',
defaultCommitMessage: 'Apply suggestion',
};
describe('Suggestion component', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = mountExtended(SuggestionsComponent, {
propsData: {
...MOCK_DATA,
...props,
},
});
};
const findSuggestionsContainer = () => wrapper.findByTestId('suggestions-container');
beforeEach(async () => {
createComponent();
await nextTick();
});
describe('mounted', () => {
it('renders a flash container', () => {
expect(wrapper.find('.js-suggestions-flash').exists()).toBe(true);
});
it('renders a container for suggestions', () => {
expect(findSuggestionsContainer().exists()).toBe(true);
});
it('renders suggestions', () => {
expect(findSuggestionsContainer().text()).toContain('oldtest');
expect(findSuggestionsContainer().text()).toContain('newtest');
});
});
});
|