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

snippet_title_spec.js « components « snippets « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e6a30885d46c318c8e23e0798e8f1686e6d47c8 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { GlSprintf, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import SnippetDescription from '~/snippets/components/snippet_description_view.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import SnippetTitle from '~/snippets/components/snippet_title.vue';

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

  function createComponent({ propsData = {} } = {}) {
    wrapper = shallowMount(SnippetTitle, {
      propsData: {
        snippet: {
          title,
          description,
          descriptionHtml,
        },
        ...propsData,
      },
      directives: {
        GlTooltip: createMockDirective('gl-tooltip'),
      },
    });
  }

  const findIcon = () => wrapper.findComponent(GlIcon);
  const findTooltip = () => getBinding(findIcon().element, 'gl-tooltip');

  describe('default state', () => {
    beforeEach(() => {
      createComponent();
    });

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

    it('does not render spam icon when author is not banned', () => {
      expect(findIcon().exists()).toBe(false);
    });

    it('renders snippets title and description', () => {
      expect(wrapper.text().trim()).toContain(title);
      expect(wrapper.findComponent(SnippetDescription).props('description')).toBe(descriptionHtml);
    });

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

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

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

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

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

  describe('when author is snippet is banned', () => {
    it('renders spam icon and tooltip when author is banned', () => {
      createComponent({
        propsData: {
          snippet: {
            hidden: true,
          },
        },
      });

      expect(findIcon().props()).toMatchObject({
        ariaLabel: 'Hidden',
        name: 'spam',
        size: 16,
      });

      expect(findIcon().attributes('title')).toBe(
        'This snippet is hidden because its author has been banned',
      );

      expect(findTooltip()).toBeDefined();
    });
  });
});