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
|
import { shallowMount } from '@vue/test-utils';
import TitleSuggestions from '~/issues/new/components/title_suggestions.vue';
import TitleSuggestionsItem from '~/issues/new/components/title_suggestions_item.vue';
describe('Issue title suggestions component', () => {
let wrapper;
function createComponent(search = 'search') {
wrapper = shallowMount(TitleSuggestions, {
propsData: {
search,
projectPath: 'project',
},
});
}
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
it('does not render with empty search', () => {
wrapper.setProps({ search: '' });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.isVisible()).toBe(false);
});
});
describe('with data', () => {
let data;
beforeEach(() => {
data = { issues: [{ id: 1 }, { id: 2 }] };
});
it('renders component', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
expect(wrapper.findAll('li').length).toBe(data.issues.length);
});
});
it('does not render with empty search', () => {
wrapper.setProps({ search: '' });
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
});
it('does not render when loading', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({
...data,
loading: 1,
});
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
});
it('does not render with empty issues data', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({ issues: [] });
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
});
it('renders list of issues', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
expect(wrapper.findAll(TitleSuggestionsItem).length).toBe(2);
});
});
it('adds margin class to first item', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
expect(wrapper.findAll('li').at(0).classes()).toContain('gl-mb-3');
});
});
it('does not add margin class to last item', () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
expect(wrapper.findAll('li').at(1).classes()).not.toContain('gl-mb-3');
});
});
});
});
|