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

edited_spec.js « components « show « issues « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8a240c38b5f18496c3b16ff9c8190d2a38ffe85c (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
import { shallowMount } from '@vue/test-utils';
import Edited from '~/issues/show/components/edited.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';

describe('Edited component', () => {
  let wrapper;

  const findAuthorLink = () => wrapper.find('a');
  const findTimeAgoTooltip = () => wrapper.findComponent(TimeAgoTooltip);
  const formatText = (text) => text.trim().replace(/\s\s+/g, ' ');

  const mountComponent = (propsData) => shallowMount(Edited, { propsData });

  afterEach(() => {
    wrapper.destroy();
  });

  it('renders an edited at+by string', () => {
    wrapper = mountComponent({
      updatedAt: '2017-05-15T12:31:04.428Z',
      updatedByName: 'Some User',
      updatedByPath: '/some_user',
    });

    expect(formatText(wrapper.text())).toBe('Edited by Some User');
    expect(findAuthorLink().attributes('href')).toBe('/some_user');
    expect(findTimeAgoTooltip().exists()).toBe(true);
  });

  it('if no updatedAt is provided, no time element will be rendered', () => {
    wrapper = mountComponent({
      updatedByName: 'Some User',
      updatedByPath: '/some_user',
    });

    expect(formatText(wrapper.text())).toBe('Edited by Some User');
    expect(findAuthorLink().attributes('href')).toBe('/some_user');
    expect(findTimeAgoTooltip().exists()).toBe(false);
  });

  it('if no updatedByName and updatedByPath is provided, no user element will be rendered', () => {
    wrapper = mountComponent({
      updatedAt: '2017-05-15T12:31:04.428Z',
    });

    expect(formatText(wrapper.text())).toBe('Edited');
    expect(findAuthorLink().exists()).toBe(false);
    expect(findTimeAgoTooltip().exists()).toBe(true);
  });
});