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: e00bb184535e63bc85913dd46bcc2df9a3f7d59c (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
import { GlBadge, GlIcon, GlAvatarLabeled } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import IssuableHeader from '~/vue_shared/issuable/show/components/issuable_header.vue';

import { mockIssuableShowProps, mockIssuable } from '../mock_data';

const issuableHeaderProps = {
  ...mockIssuable,
  ...mockIssuableShowProps,
};

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

  const findTaskStatusEl = () => wrapper.findByTestId('task-status');

  const createComponent = (props = {}, { stubs } = {}) => {
    wrapper = shallowMountExtended(IssuableHeader, {
      propsData: {
        ...issuableHeaderProps,
        ...props,
      },
      slots: {
        'status-badge': 'Open',
        'header-actions': `
        <button class="js-close">Close issuable</button>
        <a class="js-new" href="/gitlab-org/gitlab-shell/-/issues/new">New issuable</a>
      `,
      },
      stubs,
    });
  };

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

  describe('computed', () => {
    describe('authorId', () => {
      it('returns numeric ID from GraphQL ID of `author` prop', () => {
        createComponent();
        expect(wrapper.vm.authorId).toBe(1);
      });
    });
  });

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

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

      wrapper.vm.handleRightSidebarToggleClick();

      expect(wrapper.vm.toggleSidebarButtonEl.dispatchEvent).toHaveBeenCalledWith(
        expect.objectContaining({
          type: 'click',
        }),
      );
    });
  });

  describe('template', () => {
    it('renders issuable status icon and text', () => {
      createComponent();
      const statusBoxEl = wrapper.findComponent(GlBadge);
      const statusIconEl = statusBoxEl.findComponent(GlIcon);

      expect(statusBoxEl.exists()).toBe(true);
      expect(statusIconEl.props('name')).toBe(mockIssuableShowProps.statusIcon);
      expect(statusIconEl.attributes('class')).toBe(mockIssuableShowProps.statusIconClass);
      expect(statusBoxEl.text()).toContain('Open');
    });

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

      const blockedEl = wrapper.findByTestId('blocked');

      expect(blockedEl.exists()).toBe(true);
      expect(blockedEl.find(GlIcon).props('name')).toBe('lock');
    });

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

      const confidentialEl = wrapper.findByTestId('confidential');

      expect(confidentialEl.exists()).toBe(true);
      expect(confidentialEl.find(GlIcon).props('name')).toBe('eye-slash');
    });

    it('renders issuable author avatar', () => {
      createComponent();
      const { username, name, webUrl, avatarUrl } = mockIssuable.author;
      const avatarElAttrs = {
        'data-user-id': '1',
        'data-username': username,
        'data-name': name,
        href: webUrl,
        target: '_blank',
      };
      const avatarEl = wrapper.findByTestId('avatar');
      expect(avatarEl.exists()).toBe(true);
      expect(avatarEl.attributes()).toMatchObject(avatarElAttrs);
      expect(avatarEl.find(GlAvatarLabeled).attributes()).toMatchObject({
        size: '24',
        src: avatarUrl,
        label: name,
      });
      expect(avatarEl.find(GlAvatarLabeled).find(GlIcon).exists()).toBe(false);
    });

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

      expect(findTaskStatusEl().exists()).toBe(true);
      expect(findTaskStatusEl().text()).toContain('0 of 5 tasks completed');
    });

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

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

    it('renders sidebar toggle button', () => {
      createComponent();
      const toggleButtonEl = wrapper.findByTestId('sidebar-toggle');

      expect(toggleButtonEl.exists()).toBe(true);
      expect(toggleButtonEl.props('icon')).toBe('chevron-double-lg-left');
    });

    it('renders header actions', () => {
      createComponent();
      const actionsEl = wrapper.findByTestId('header-actions');

      expect(actionsEl.find('button.js-close').exists()).toBe(true);
      expect(actionsEl.find('a.js-new').exists()).toBe(true);
    });

    describe('when author exists outside of GitLab', () => {
      it("renders 'external-link' icon in avatar label", () => {
        createComponent(
          {
            author: {
              ...issuableHeaderProps.author,
              webUrl: 'https://jira.com/test-user/author.jpg',
            },
          },
          {
            stubs: {
              GlAvatarLabeled,
            },
          },
        );

        const avatarEl = wrapper.findComponent(GlAvatarLabeled);
        const icon = avatarEl.find(GlIcon);

        expect(icon.exists()).toBe(true);
        expect(icon.props('name')).toBe('external-link');
      });
    });
  });
});