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
128
129
130
131
132
133
134
135
136
137
138
|
import { shallowMount } from '@vue/test-utils';
import { TEST_HOST } from 'helpers/test_constants';
import ReviewerAvatarLink from '~/sidebar/components/reviewers/reviewer_avatar_link.vue';
import UncollapsedReviewerList from '~/sidebar/components/reviewers/uncollapsed_reviewer_list.vue';
const userDataMock = () => ({
id: 1,
name: 'Root',
state: 'active',
username: 'root',
webUrl: `${TEST_HOST}/root`,
avatarUrl: `${TEST_HOST}/avatar/root.png`,
mergeRequestInteraction: {
canMerge: true,
canUpdate: true,
reviewed: true,
approved: false,
},
});
describe('UncollapsedReviewerList component', () => {
let wrapper;
const reviewerApprovalIcons = () => wrapper.findAll('[data-testid="re-approved"]');
function createComponent(props = {}, glFeatures = {}) {
const propsData = {
users: [],
rootPath: TEST_HOST,
...props,
};
wrapper = shallowMount(UncollapsedReviewerList, {
propsData,
provide: {
glFeatures,
},
});
}
afterEach(() => {
wrapper.destroy();
});
describe('single reviewer', () => {
const user = userDataMock();
beforeEach(() => {
createComponent({
users: [user],
});
});
it('only has one user', () => {
expect(wrapper.findAllComponents(ReviewerAvatarLink).length).toBe(1);
});
it('shows one user with avatar, and author name', () => {
expect(wrapper.text()).toContain(user.name);
});
it('renders re-request loading icon', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ loadingStates: { 1: 'loading' } });
expect(wrapper.find('[data-testid="re-request-button"]').props('loading')).toBe(true);
});
it('renders re-request success icon', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ loadingStates: { 1: 'success' } });
expect(wrapper.find('[data-testid="re-request-success"]').exists()).toBe(true);
});
});
describe('multiple reviewers', () => {
const user = userDataMock();
const user2 = {
...user,
id: 2,
name: 'nonrooty-nonrootersen',
username: 'hello-world',
mergeRequestInteraction: {
...user.mergeRequestInteraction,
approved: true,
},
};
beforeEach(() => {
createComponent({
users: [user, user2],
});
});
it('has both users', () => {
expect(wrapper.findAllComponents(ReviewerAvatarLink).length).toBe(2);
});
it('shows both users with avatar, and author name', () => {
expect(wrapper.text()).toContain(user.name);
expect(wrapper.text()).toContain(user2.name);
});
it('renders approval icon', () => {
expect(reviewerApprovalIcons().length).toBe(1);
});
it('shows that hello-world approved', () => {
const icon = reviewerApprovalIcons().at(0);
expect(icon.attributes('title')).toEqual('Approved by @hello-world');
});
it('renders re-request loading icon', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ loadingStates: { 2: 'loading' } });
expect(wrapper.findAll('[data-testid="re-request-button"]').length).toBe(2);
expect(wrapper.findAll('[data-testid="re-request-button"]').at(1).props('loading')).toBe(
true,
);
});
it('renders re-request success icon', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ loadingStates: { 2: 'success' } });
expect(wrapper.findAll('[data-testid="re-request-button"]').length).toBe(1);
expect(wrapper.findAll('[data-testid="re-request-success"]').length).toBe(1);
expect(wrapper.find('[data-testid="re-request-success"]').exists()).toBe(true);
});
});
});
|