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

sticky_header_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: a909084956f6448eea467921ab9ba2f441d14166 (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
import { GlIcon, GlLink } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import HiddenBadge from '~/issuable/components/hidden_badge.vue';
import LockedBadge from '~/issuable/components/locked_badge.vue';
import {
  issuableStatusText,
  STATUS_CLOSED,
  STATUS_OPEN,
  STATUS_REOPENED,
  TYPE_EPIC,
  TYPE_INCIDENT,
  TYPE_ISSUE,
} from '~/issues/constants';
import StickyHeader from '~/issues/show/components/sticky_header.vue';
import ConfidentialityBadge from '~/vue_shared/components/confidentiality_badge.vue';

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

  const findConfidentialBadge = () => wrapper.findComponent(ConfidentialityBadge);
  const findHiddenBadge = () => wrapper.findComponent(HiddenBadge);
  const findLockedBadge = () => wrapper.findComponent(LockedBadge);
  const findTitle = () => wrapper.findComponent(GlLink);

  const createComponent = (props = {}) => {
    wrapper = shallowMountExtended(StickyHeader, {
      propsData: {
        issuableStatus: STATUS_OPEN,
        issuableType: TYPE_ISSUE,
        show: true,
        title: 'A sticky issue',
        ...props,
      },
    });
  };

  it.each`
    issuableType     | issuableStatus   | statusIcon
    ${TYPE_INCIDENT} | ${STATUS_OPEN}   | ${'issues'}
    ${TYPE_INCIDENT} | ${STATUS_CLOSED} | ${'issue-closed'}
    ${TYPE_ISSUE}    | ${STATUS_OPEN}   | ${'issues'}
    ${TYPE_ISSUE}    | ${STATUS_CLOSED} | ${'issue-closed'}
    ${TYPE_EPIC}     | ${STATUS_OPEN}   | ${'epic'}
    ${TYPE_EPIC}     | ${STATUS_CLOSED} | ${'epic-closed'}
  `(
    'shows with state icon "$statusIcon" for $issuableType when status is $issuableStatus',
    ({ issuableType, issuableStatus, statusIcon }) => {
      createComponent({ issuableType, issuableStatus });

      expect(wrapper.findComponent(GlIcon).props('name')).toBe(statusIcon);
    },
  );

  it.each`
    title                                        | issuableStatus
    ${'shows with Open when status is opened'}   | ${STATUS_OPEN}
    ${'shows with Closed when status is closed'} | ${STATUS_CLOSED}
    ${'shows with Open when status is reopened'} | ${STATUS_REOPENED}
  `('$title', ({ issuableStatus }) => {
    createComponent({ issuableStatus });

    expect(wrapper.text()).toContain(issuableStatusText[issuableStatus]);
  });

  it.each`
    title                                                                | isConfidential
    ${'does not show confidential badge when issue is not confidential'} | ${false}
    ${'shows confidential badge when issue is confidential'}             | ${true}
  `('$title', ({ isConfidential }) => {
    createComponent({ isConfidential });
    const confidentialBadge = findConfidentialBadge();

    expect(confidentialBadge.exists()).toBe(isConfidential);

    if (isConfidential) {
      expect(confidentialBadge.props()).toMatchObject({
        workspaceType: 'project',
        issuableType: 'issue',
      });
    }
  });

  it.each`
    title                                                    | isLocked
    ${'does not show locked badge when issue is not locked'} | ${false}
    ${'shows locked badge when issue is locked'}             | ${true}
  `('$title', ({ isLocked }) => {
    createComponent({ isLocked });
    const lockedBadge = findLockedBadge();

    expect(lockedBadge.exists()).toBe(isLocked);
  });

  it.each`
    title                                                    | isHidden
    ${'does not show hidden badge when issue is not hidden'} | ${false}
    ${'shows hidden badge when issue is hidden'}             | ${true}
  `('$title', ({ isHidden }) => {
    createComponent({ isHidden });
    const hiddenBadge = findHiddenBadge();

    expect(hiddenBadge.exists()).toBe(isHidden);
  });

  it('shows with title', () => {
    createComponent();
    const title = findTitle();

    expect(title.text()).toContain('A sticky issue');
    expect(title.attributes('href')).toBe('#top');
  });
});