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
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import setWindowLocation from 'helpers/set_window_location_helper';
import AbuseReportRow from '~/admin/abuse_reports/components/abuse_report_row.vue';
import ListItem from '~/vue_shared/components/registry/list_item.vue';
import { getTimeago } from '~/lib/utils/datetime_utility';
import { SORT_UPDATED_AT } from '~/admin/abuse_reports/constants';
import { mockAbuseReports } from '../mock_data';
describe('AbuseReportRow', () => {
let wrapper;
const mockAbuseReport = mockAbuseReports[0];
const findListItem = () => wrapper.findComponent(ListItem);
const findTitle = () => wrapper.findByTestId('title');
const findDisplayedDate = () => wrapper.findByTestId('abuse-report-date');
const createComponent = (props = {}) => {
wrapper = shallowMountExtended(AbuseReportRow, {
propsData: {
report: mockAbuseReport,
...props,
},
});
};
beforeEach(() => {
createComponent();
});
it('renders a ListItem', () => {
expect(findListItem().exists()).toBe(true);
});
describe('title', () => {
const { reporter, reportedUser, category, reportPath } = mockAbuseReport;
it('displays correctly formatted title', () => {
expect(findTitle().text()).toMatchInterpolatedText(
`${reportedUser.name} reported for ${category} by ${reporter.name}`,
);
});
it('links to the details page', () => {
expect(findTitle().attributes('href')).toEqual(reportPath);
});
describe('when the reportedUser is missing', () => {
beforeEach(() => {
createComponent({ report: { ...mockAbuseReport, reportedUser: null } });
});
it('displays correctly formatted title', () => {
expect(findTitle().text()).toMatchInterpolatedText(
`Deleted user reported for ${category} by ${reporter.name}`,
);
});
});
describe('when the reporter is missing', () => {
beforeEach(() => {
createComponent({ report: { ...mockAbuseReport, reporter: null } });
});
it('displays correctly formatted title', () => {
expect(findTitle().text()).toMatchInterpolatedText(
`${reportedUser.name} reported for ${category} by Deleted user`,
);
});
});
});
describe('displayed date', () => {
it('displays correctly formatted created at', () => {
expect(findDisplayedDate().text()).toMatchInterpolatedText(
`Created ${getTimeago().format(mockAbuseReport.createdAt)}`,
);
});
describe('when sorted by updated_at', () => {
it('displays correctly formatted updated at', () => {
setWindowLocation(`?sort=${SORT_UPDATED_AT.sortDirection.ascending}`);
createComponent();
expect(findDisplayedDate().text()).toMatchInterpolatedText(
`Updated ${getTimeago().format(mockAbuseReport.updatedAt)}`,
);
});
});
});
});
|