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
|
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import Component from '~/sidebar/components/reviewers/reviewer_title.vue';
describe('ReviewerTitle component', () => {
let wrapper;
const createComponent = (props) => {
return shallowMount(Component, {
propsData: {
numberOfReviewers: 0,
editable: false,
...props,
},
});
};
describe('reviewer title', () => {
it('renders reviewer', () => {
wrapper = createComponent({
numberOfReviewers: 1,
editable: false,
});
expect(wrapper.vm.$el.innerText.trim()).toEqual('Reviewer');
});
it('renders 2 reviewers', () => {
wrapper = createComponent({
numberOfReviewers: 2,
editable: false,
});
expect(wrapper.vm.$el.innerText.trim()).toEqual('2 Reviewers');
});
});
it('does not render spinner by default', () => {
wrapper = createComponent({
numberOfReviewers: 0,
editable: false,
});
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
});
it('renders spinner when loading', () => {
wrapper = createComponent({
loading: true,
numberOfReviewers: 0,
editable: false,
});
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
});
it('does not render edit link when not editable', () => {
wrapper = createComponent({
numberOfReviewers: 0,
editable: false,
});
expect(wrapper.vm.$el.querySelector('.edit-link')).toBeNull();
});
it('renders edit link when editable', () => {
wrapper = createComponent({
numberOfReviewers: 0,
editable: true,
});
expect(wrapper.vm.$el.querySelector('.edit-link')).not.toBeNull();
});
it('tracks the event when edit is clicked', () => {
wrapper = createComponent({
numberOfReviewers: 0,
editable: true,
});
const spy = mockTracking('_category_', wrapper.element, jest.spyOn);
triggerEvent('.js-sidebar-dropdown-toggle');
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
label: 'right_sidebar',
property: 'reviewer',
});
});
});
|