Welcome to mirror list, hosted at ThFree Co, Russian Federation.

activity_history_item_spec.js « components « abuse_report « admin « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f430b0143e10a6fcf24a179b310e9c53ec63365 (plain)
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
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { sprintf } from '~/locale';
import AcitivityHistoryItem from '~/admin/abuse_report/components/activity_history_item.vue';
import HistoryItem from '~/vue_shared/components/registry/history_item.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { mockAbuseReport } from '../mock_data';

describe('AcitivityHistoryItem', () => {
  let wrapper;

  const { report } = mockAbuseReport;

  const findHistoryItem = () => wrapper.findComponent(HistoryItem);
  const findTimeAgo = () => wrapper.findComponent(TimeAgoTooltip);

  const createComponent = (props = {}) => {
    wrapper = shallowMount(AcitivityHistoryItem, {
      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('Reported by %{name} for %{category}.', {
        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('Reported by %{name} for %{category}.', {
          name: 'No user found',
          category: report.category,
        });
        expect(findHistoryItem().text()).toContain(title);
      });
    });
  });

  it('renders the time-ago tooltip', () => {
    expect(findTimeAgo().props('time')).toBe(report.reportedAt);
  });
});