summaryrefslogtreecommitdiff
path: root/spec/frontend/snippets/components/snippet_title_spec.js
blob: 48fb51ce7039b2ede8cb6d36237dc6f122492eed (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
65
66
67
68
69
70
71
72
73
74
75
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import SnippetDescription from '~/snippets/components/snippet_description_view.vue';
import SnippetTitle from '~/snippets/components/snippet_title.vue';

describe('Snippet header component', () => {
  let wrapper;
  const title = 'The property of Thor';
  const description = 'Do not touch this hammer';
  const descriptionHtml = `<h2>${description}</h2>`;
  const snippet = {
    snippet: {
      title,
      description,
      descriptionHtml,
    },
  };

  function createComponent({ props = snippet } = {}) {
    const defaultProps = { ...props };

    wrapper = shallowMount(SnippetTitle, {
      propsData: {
        ...defaultProps,
      },
    });
  }

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

  it('renders itself', () => {
    createComponent();
    expect(wrapper.find('.snippet-header').exists()).toBe(true);
  });

  it('renders snippets title and description', () => {
    createComponent();

    expect(wrapper.text().trim()).toContain(title);
    expect(wrapper.find(SnippetDescription).props('description')).toBe(descriptionHtml);
  });

  it('does not render recent changes time stamp if there were no updates', () => {
    createComponent();
    expect(wrapper.find(GlSprintf).exists()).toBe(false);
  });

  it('does not render recent changes time stamp if the time for creation and updates match', () => {
    const props = Object.assign(snippet, {
      snippet: {
        ...snippet.snippet,
        createdAt: '2019-12-16T21:45:36Z',
        updatedAt: '2019-12-16T21:45:36Z',
      },
    });
    createComponent({ props });

    expect(wrapper.find(GlSprintf).exists()).toBe(false);
  });

  it('renders translated string with most recent changes timestamp if changes were made', () => {
    const props = Object.assign(snippet, {
      snippet: {
        ...snippet.snippet,
        createdAt: '2019-12-16T21:45:36Z',
        updatedAt: '2019-15-16T21:45:36Z',
      },
    });
    createComponent({ props });

    expect(wrapper.find(GlSprintf).exists()).toBe(true);
  });
});