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

issuable_header_spec.js « components « show « issuable « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d08ad54e58c593702f1a194b1310aa78d2e98dd (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import { GlBadge, GlButton, GlIcon, GlLink, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { resetHTMLFixture, setHTMLFixture } from 'helpers/fixtures';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import {
  STATUS_CLOSED,
  STATUS_OPEN,
  STATUS_REOPENED,
  TYPE_ISSUE,
  WORKSPACE_PROJECT,
} from '~/issues/constants';
import { __ } from '~/locale';
import ConfidentialityBadge from '~/vue_shared/components/confidentiality_badge.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import IssuableHeader from '~/vue_shared/issuable/show/components/issuable_header.vue';
import WorkItemTypeIcon from '~/work_items/components/work_item_type_icon.vue';
import { mockIssuable, mockIssuableShowProps } from '../mock_data';

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

  const findConfidentialityBadge = () => wrapper.findComponent(ConfidentialityBadge);
  const findStatusBadge = () => wrapper.findComponent(GlBadge);
  const findToggleButton = () => wrapper.findComponent(GlButton);
  const findAuthorLink = () => wrapper.findComponent(GlLink);
  const findTimeAgoTooltip = () => wrapper.findComponent(TimeAgoTooltip);
  const findWorkItemTypeIcon = () => wrapper.findComponent(WorkItemTypeIcon);
  const findGlIconWithName = (name) =>
    wrapper.findAllComponents(GlIcon).filter((component) => component.props('name') === name);
  const findIcon = (name) =>
    findGlIconWithName(name).exists() ? findGlIconWithName(name).at(0) : undefined;
  const findBlockedIcon = () => findIcon('lock');
  const findHiddenIcon = () => findIcon('spam');
  const findExternalLinkIcon = () => findIcon('external-link');
  const findFirstContributionIcon = () => findIcon('first-contribution');
  const findComponentTooltip = (component) => getBinding(component.element, 'gl-tooltip');

  const createComponent = (props = {}, { stubs } = {}) => {
    wrapper = shallowMount(IssuableHeader, {
      directives: {
        GlTooltip: createMockDirective('gl-tooltip'),
      },
      propsData: {
        ...mockIssuable,
        ...mockIssuableShowProps,
        issuableState: STATUS_OPEN,
        issuableType: TYPE_ISSUE,
        workspaceType: WORKSPACE_PROJECT,
        ...props,
      },
      slots: {
        'header-actions': `Header actions slot`,
      },
      stubs: {
        GlSprintf,
        ...stubs,
      },
    });
  };

  describe('status badge', () => {
    describe('variant', () => {
      it('is `success` when status is open', () => {
        createComponent({ issuableState: STATUS_OPEN });

        expect(findStatusBadge().props('variant')).toBe('success');
      });

      it('is `success` when status is reopened', () => {
        createComponent({ issuableState: STATUS_REOPENED });

        expect(findStatusBadge().props('variant')).toBe('success');
      });

      it('is `info` when status is closed', () => {
        createComponent({ issuableState: STATUS_CLOSED });

        expect(findStatusBadge().props('variant')).toBe('info');
      });
    });

    describe('icon', () => {
      it('renders when statusIcon prop exists', () => {
        createComponent({ statusIcon: 'issues' });

        expect(findStatusBadge().findComponent(GlIcon).props('name')).toBe('issues');
      });

      it('does not render when statusIcon prop does not exist', () => {
        createComponent({ statusIcon: '' });

        expect(findStatusBadge().findComponent(GlIcon).exists()).toBe(false);
      });
    });

    it('renders status text', () => {
      createComponent();

      expect(findStatusBadge().text()).toBe(__('Open'));
    });
  });

  describe('confidential badge', () => {
    it('renders when issuable is confidential', () => {
      createComponent({ confidential: true });

      expect(findConfidentialityBadge().props()).toEqual({
        issuableType: 'issue',
        workspaceType: 'project',
      });
    });

    it('does not render when issuable is not confidential', () => {
      createComponent({ confidential: false });

      expect(findConfidentialityBadge().exists()).toBe(false);
    });
  });

  describe('blocked icon', () => {
    it('renders when issuable is blocked', () => {
      createComponent({ blocked: true });

      expect(findBlockedIcon().props('ariaLabel')).toBe('Blocked');
    });

    it('has tooltip', () => {
      createComponent({ blocked: true });

      expect(findComponentTooltip(findBlockedIcon())).toBeDefined();
      expect(findBlockedIcon().attributes('title')).toBe(
        'This issue is locked. Only project members can comment.',
      );
    });

    it('does not render when issuable is not blocked', () => {
      createComponent({ blocked: false });

      expect(findBlockedIcon()).toBeUndefined();
    });
  });

  describe('hidden icon', () => {
    it('renders when issuable is hidden', () => {
      createComponent({ isHidden: true });

      expect(findHiddenIcon().props('ariaLabel')).toBe('Hidden');
    });

    it('has tooltip', () => {
      createComponent({ isHidden: true });

      expect(findComponentTooltip(findHiddenIcon())).toBeDefined();
      expect(findHiddenIcon().attributes('title')).toBe(
        'This issue is hidden because its author has been banned',
      );
    });

    it('does not render when issuable is not hidden', () => {
      createComponent({ isHidden: false });

      expect(findHiddenIcon()).toBeUndefined();
    });
  });

  describe('work item type icon', () => {
    it('renders when showWorkItemTypeIcon=true and work item type exists', () => {
      createComponent({ showWorkItemTypeIcon: true, issuableType: 'issue' });

      expect(findWorkItemTypeIcon().props()).toMatchObject({
        showText: true,
        workItemType: 'ISSUE',
      });
    });

    it('does not render when showWorkItemTypeIcon=false', () => {
      createComponent({ showWorkItemTypeIcon: false });

      expect(findWorkItemTypeIcon().exists()).toBe(false);
    });
  });

  describe('timeago tooltip', () => {
    it('renders', () => {
      createComponent();

      expect(findTimeAgoTooltip().props('time')).toBe('2020-06-29T13:52:56Z');
    });
  });

  describe('author', () => {
    it('renders link', () => {
      createComponent();

      expect(findAuthorLink().text()).toContain('Administrator');
      expect(findAuthorLink().attributes()).toMatchObject({
        href: 'http://0.0.0.0:3000/root',
        'data-user-id': '1',
      });
      expect(findAuthorLink().classes()).toContain('js-user-link');
    });

    describe('when author exists outside of GitLab', () => {
      it('renders external link icon', () => {
        createComponent({ author: { webUrl: 'https://example.com/test-user' } });

        expect(findExternalLinkIcon().props('ariaLabel')).toBe('external link');
      });
    });
  });

  describe('first contribution icon', () => {
    it('renders when isFirstContribution=true', () => {
      createComponent({ isFirstContribution: true });

      expect(findFirstContributionIcon().props('ariaLabel')).toBe('1st contribution!');
    });

    it('has tooltip', () => {
      createComponent({ isFirstContribution: true });

      expect(findComponentTooltip(findFirstContributionIcon())).toBeDefined();
      expect(findFirstContributionIcon().attributes('title')).toBe('1st contribution!');
    });

    it('does not render when isFirstContribution=false', () => {
      createComponent({ isFirstContribution: false });

      expect(findFirstContributionIcon()).toBeUndefined();
    });
  });

  describe('task status', () => {
    it('renders task status text when `taskCompletionStatus` prop is defined', () => {
      createComponent();

      expect(wrapper.text()).toContain('0 of 5 checklist items completed');
    });

    it('does not render task status text when tasks count is 0', () => {
      createComponent({ taskCompletionStatus: { count: 0, completedCount: 0 } });

      expect(wrapper.text()).not.toContain('checklist item');
    });
  });

  describe('sidebar toggle button', () => {
    beforeEach(() => {
      setHTMLFixture('<button class="js-toggle-right-sidebar-button">Collapse sidebar</button>');
      createComponent();
    });

    afterEach(() => {
      resetHTMLFixture();
    });

    it('renders', () => {
      expect(findToggleButton().props('icon')).toBe('chevron-double-lg-left');
      expect(findToggleButton().attributes('aria-label')).toBe('Expand sidebar');
    });

    describe('when clicked', () => {
      it('emits a "toggle" event', () => {
        findToggleButton().vm.$emit('click');

        expect(wrapper.emitted('toggle')).toEqual([[]]);
      });

      it('dispatches `click` event on sidebar toggle button', () => {
        const toggleSidebarButton = document.querySelector('.js-toggle-right-sidebar-button');
        const dispatchEvent = jest
          .spyOn(toggleSidebarButton, 'dispatchEvent')
          .mockImplementation(jest.fn);

        findToggleButton().vm.$emit('click');

        expect(dispatchEvent).toHaveBeenCalledWith(expect.objectContaining({ type: 'click' }));
      });
    });
  });

  describe('header actions', () => {
    it('renders slot', () => {
      createComponent();

      expect(wrapper.text()).toContain('Header actions slot');
    });
  });
});