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
|
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { sprintf } from '~/locale';
import HistoryItems from '~/admin/abuse_report/components/history_items.vue';
import HistoryItem from '~/vue_shared/components/registry/history_item.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { HISTORY_ITEMS_I18N } from '~/admin/abuse_report/constants';
import { mockAbuseReport } from '../mock_data';
describe('HistoryItems', () => {
let wrapper;
const { report } = mockAbuseReport;
const findHistoryItem = () => wrapper.findComponent(HistoryItem);
const findTimeAgo = () => wrapper.findComponent(TimeAgoTooltip);
const createComponent = (props = {}) => {
wrapper = shallowMount(HistoryItems, {
propsData: {
report,
...props,
},
stubs: {
GlSprintf,
},
});
};
beforeEach(() => {
createComponent();
});
it('renders the icon', () => {
expect(findHistoryItem().props('icon')).toBe('warning');
});
describe('rendering the title', () => {
it('renders the reporters name and the category', () => {
const title = sprintf(HISTORY_ITEMS_I18N.reportedByForCategory, {
name: report.reporter.name,
category: report.category,
});
expect(findHistoryItem().text()).toContain(title);
});
describe('when the reporter is not defined', () => {
beforeEach(() => {
createComponent({ report: { ...report, reporter: undefined } });
});
it('renders the `No user found` as the reporters name and the category', () => {
const title = sprintf(HISTORY_ITEMS_I18N.reportedByForCategory, {
name: HISTORY_ITEMS_I18N.deletedReporter,
category: report.category,
});
expect(findHistoryItem().text()).toContain(title);
});
});
});
it('renders the time-ago tooltip', () => {
expect(findTimeAgo().props('time')).toBe(report.reportedAt);
});
});
|