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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
import { GlLink, GlSprintf } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { sprintf } from '~/locale';
import UserDetails from '~/admin/abuse_report/components/user_details.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { USER_DETAILS_I18N } from '~/admin/abuse_report/constants';
import { mockAbuseReport } from '../mock_data';
describe('UserDetails', () => {
let wrapper;
const { user } = mockAbuseReport;
const findUserDetail = (attribute) => wrapper.findByTestId(attribute);
const findUserDetailLabel = (attribute) => findUserDetail(attribute).props('label');
const findUserDetailValue = (attribute) => findUserDetail(attribute).props('value');
const findLinkIn = (component) => component.findComponent(GlLink);
const findLinkFor = (attribute) => findLinkIn(findUserDetail(attribute));
const findTimeIn = (component) => component.findComponent(TimeAgoTooltip).props('time');
const findTimeFor = (attribute) => findTimeIn(findUserDetail(attribute));
const findOtherReport = (index) => wrapper.findByTestId(`other-report-${index}`);
const createComponent = (props = {}) => {
wrapper = shallowMountExtended(UserDetails, {
propsData: {
user,
...props,
},
stubs: {
GlSprintf,
},
});
};
beforeEach(() => {
createComponent();
});
describe('createdAt', () => {
it('renders the users createdAt with the correct label', () => {
expect(findUserDetailLabel('createdAt')).toBe(USER_DETAILS_I18N.createdAt);
expect(findTimeFor('createdAt')).toBe(user.createdAt);
});
});
describe('email', () => {
it('renders the users email with the correct label', () => {
expect(findUserDetailLabel('email')).toBe(USER_DETAILS_I18N.email);
expect(findLinkFor('email').attributes('href')).toBe(`mailto:${user.email}`);
expect(findLinkFor('email').text()).toBe(user.email);
});
});
describe('plan', () => {
it('renders the users plan with the correct label', () => {
expect(findUserDetailLabel('plan')).toBe(USER_DETAILS_I18N.plan);
expect(findUserDetailValue('plan')).toBe(user.plan);
});
});
describe('verification', () => {
it('renders the users verification with the correct label', () => {
expect(findUserDetailLabel('verification')).toBe(USER_DETAILS_I18N.verification);
expect(findUserDetailValue('verification')).toBe('Email, Credit card');
});
});
describe('creditCard', () => {
it('renders the correct label', () => {
expect(findUserDetailLabel('creditCard')).toBe(USER_DETAILS_I18N.creditCard);
});
it('renders the users name', () => {
expect(findUserDetail('creditCard').text()).toContain(
sprintf(USER_DETAILS_I18N.registeredWith, { ...user.creditCard }),
);
expect(findUserDetail('creditCard').text()).toContain(user.creditCard.name);
});
describe('similar credit cards', () => {
it('renders the number of similar records', () => {
expect(findUserDetail('creditCard').text()).toContain(
sprintf('Card matches %{similarRecordsCount} accounts', { ...user.creditCard }),
);
});
it('renders a link to the matching cards', () => {
expect(findLinkFor('creditCard').attributes('href')).toBe(user.creditCard.cardMatchesLink);
expect(findLinkFor('creditCard').text()).toBe(
sprintf('%{similarRecordsCount} accounts', { ...user.creditCard }),
);
expect(findLinkFor('creditCard').text()).toContain(
user.creditCard.similarRecordsCount.toString(),
);
});
describe('when the number of similar credit cards is less than 2', () => {
beforeEach(() => {
createComponent({
user: { ...user, creditCard: { ...user.creditCard, similarRecordsCount: 1 } },
});
});
it('does not render the number of similar records', () => {
expect(findUserDetail('creditCard').text()).not.toContain(
sprintf('Card matches %{similarRecordsCount} accounts', { ...user.creditCard }),
);
});
it('does not render a link to the matching cards', () => {
expect(findLinkFor('creditCard').exists()).toBe(false);
});
});
});
describe('when the users creditCard is blank', () => {
beforeEach(() => {
createComponent({
user: { ...user, creditCard: undefined },
});
});
it('does not render the users creditCard', () => {
expect(findUserDetail('creditCard').exists()).toBe(false);
});
});
});
describe('otherReports', () => {
it('renders the correct label', () => {
expect(findUserDetailLabel('otherReports')).toBe(USER_DETAILS_I18N.otherReports);
});
describe.each(user.otherReports)('renders a line for report %#', (otherReport) => {
const index = user.otherReports.indexOf(otherReport);
it('renders the category', () => {
expect(findOtherReport(index).text()).toContain(
sprintf('Reported for %{category}', { ...otherReport }),
);
});
it('renders a link to the report', () => {
expect(findLinkIn(findOtherReport(index)).attributes('href')).toBe(otherReport.reportPath);
});
it('renders the time it was created', () => {
expect(findTimeIn(findOtherReport(index))).toBe(otherReport.createdAt);
});
});
describe('when the users otherReports is empty', () => {
beforeEach(() => {
createComponent({
user: { ...user, otherReports: [] },
});
});
it('does not render the users otherReports', () => {
expect(findUserDetail('otherReports').exists()).toBe(false);
});
});
});
describe('normalLocation', () => {
it('renders the correct label', () => {
expect(findUserDetailLabel('normalLocation')).toBe(USER_DETAILS_I18N.normalLocation);
});
describe('when the users mostUsedIp is blank', () => {
it('renders the users lastSignInIp', () => {
expect(findUserDetailValue('normalLocation')).toBe(user.lastSignInIp);
});
});
describe('when the users mostUsedIp is not blank', () => {
const mostUsedIp = '127.0.0.1';
beforeEach(() => {
createComponent({
user: { ...user, mostUsedIp },
});
});
it('renders the users mostUsedIp', () => {
expect(findUserDetailValue('normalLocation')).toBe(mostUsedIp);
});
});
});
describe('lastSignInIp', () => {
it('renders the users lastSignInIp with the correct label', () => {
expect(findUserDetailLabel('lastSignInIp')).toBe(USER_DETAILS_I18N.lastSignInIp);
expect(findUserDetailValue('lastSignInIp')).toBe(user.lastSignInIp);
});
});
it.each(['snippets', 'groups', 'notes'])(
'renders the users %s with the correct label',
(attribute) => {
expect(findUserDetailLabel(attribute)).toBe(USER_DETAILS_I18N[attribute]);
expect(findUserDetailValue(attribute)).toBe(
USER_DETAILS_I18N[`${attribute}Count`](user[`${attribute}Count`]),
);
},
);
});
|