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

issuable_item_spec.js « components « issuable_list « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a96a4e15e6c0f1de848c3d747a52c9db2528ea60 (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
import { shallowMount } from '@vue/test-utils';
import { GlLink, GlLabel } from '@gitlab/ui';

import IssuableItem from '~/issuable_list/components/issuable_item.vue';

import { mockIssuable, mockRegularLabel, mockScopedLabel } from '../mock_data';

const createComponent = ({ issuableSymbol = '#', issuable = mockIssuable } = {}) =>
  shallowMount(IssuableItem, {
    propsData: {
      issuableSymbol,
      issuable,
    },
  });

describe('IssuableItem', () => {
  const mockLabels = mockIssuable.labels.nodes;
  const mockAuthor = mockIssuable.author;
  let wrapper;

  beforeEach(() => {
    wrapper = createComponent();
  });

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

  describe('computed', () => {
    describe('author', () => {
      it('returns `issuable.author` reference', () => {
        expect(wrapper.vm.author).toEqual(mockIssuable.author);
      });
    });

    describe('authorId', () => {
      it.each`
        authorId                 | returnValue
        ${1}                     | ${1}
        ${'1'}                   | ${1}
        ${'gid://gitlab/User/1'} | ${'1'}
        ${'foo'}                 | ${''}
      `(
        'returns $returnValue when value of `issuable.author.id` is $authorId',
        async ({ authorId, returnValue }) => {
          wrapper.setProps({
            issuable: {
              ...mockIssuable,
              author: {
                ...mockAuthor,
                id: authorId,
              },
            },
          });

          await wrapper.vm.$nextTick();

          expect(wrapper.vm.authorId).toBe(returnValue);
        },
      );
    });

    describe('labels', () => {
      it('returns `issuable.labels.nodes` reference when it is available', () => {
        expect(wrapper.vm.labels).toEqual(mockLabels);
      });

      it('returns `issuable.labels` reference when it is available', async () => {
        wrapper.setProps({
          issuable: {
            ...mockIssuable,
            labels: mockLabels,
          },
        });

        await wrapper.vm.$nextTick();

        expect(wrapper.vm.labels).toEqual(mockLabels);
      });

      it('returns empty array when none of `issuable.labels.nodes` or `issuable.labels` are available', async () => {
        wrapper.setProps({
          issuable: {
            ...mockIssuable,
            labels: null,
          },
        });

        await wrapper.vm.$nextTick();

        expect(wrapper.vm.labels).toEqual([]);
      });
    });

    describe('createdAt', () => {
      it('returns string containing timeago string based on `issuable.createdAt`', () => {
        expect(wrapper.vm.createdAt).toContain('created');
        expect(wrapper.vm.createdAt).toContain('ago');
      });
    });

    describe('updatedAt', () => {
      it('returns string containing timeago string based on `issuable.updatedAt`', () => {
        expect(wrapper.vm.updatedAt).toContain('updated');
        expect(wrapper.vm.updatedAt).toContain('ago');
      });
    });
  });

  describe('methods', () => {
    describe('scopedLabel', () => {
      it.each`
        label               | labelType    | returnValue
        ${mockRegularLabel} | ${'regular'} | ${false}
        ${mockScopedLabel}  | ${'scoped'}  | ${true}
      `(
        'return $returnValue when provided label param is a $labelType label',
        ({ label, returnValue }) => {
          expect(wrapper.vm.scopedLabel(label)).toBe(returnValue);
        },
      );
    });
  });

  describe('template', () => {
    it('renders issuable title', () => {
      const titleEl = wrapper.find('[data-testid="issuable-title"]');

      expect(titleEl.exists()).toBe(true);
      expect(titleEl.find(GlLink).attributes('href')).toBe(mockIssuable.webUrl);
      expect(titleEl.find(GlLink).text()).toBe(mockIssuable.title);
    });

    it('renders issuable reference', () => {
      const referenceEl = wrapper.find('[data-testid="issuable-reference"]');

      expect(referenceEl.exists()).toBe(true);
      expect(referenceEl.text()).toBe(`#${mockIssuable.iid}`);
    });

    it('renders issuable createdAt info', () => {
      const createdAtEl = wrapper.find('[data-testid="issuable-created-at"]');

      expect(createdAtEl.exists()).toBe(true);
      expect(createdAtEl.attributes('title')).toBe('Jun 29, 2020 1:52pm GMT+0000');
      expect(createdAtEl.text()).toBe(wrapper.vm.createdAt);
    });

    it('renders issuable author info', () => {
      const authorEl = wrapper.find('[data-testid="issuable-author"]');

      expect(authorEl.exists()).toBe(true);
      expect(authorEl.attributes()).toMatchObject({
        'data-user-id': wrapper.vm.authorId,
        'data-username': mockAuthor.username,
        'data-name': mockAuthor.name,
        'data-avatar-url': mockAuthor.avatarUrl,
        href: mockAuthor.webUrl,
      });
      expect(authorEl.text()).toBe(mockAuthor.name);
    });

    it('renders gl-label component for each label present within `issuable` prop', () => {
      const labelsEl = wrapper.findAll(GlLabel);

      expect(labelsEl.exists()).toBe(true);
      expect(labelsEl).toHaveLength(mockLabels.length);
      expect(labelsEl.at(0).props()).toMatchObject({
        backgroundColor: mockLabels[0].color,
        title: mockLabels[0].title,
        description: mockLabels[0].description,
        scoped: false,
        size: 'sm',
      });
    });

    it('renders issuable updatedAt info', () => {
      const updatedAtEl = wrapper.find('[data-testid="issuable-updated-at"]');

      expect(updatedAtEl.exists()).toBe(true);
      expect(updatedAtEl.find('span').attributes('title')).toBe('Sep 10, 2020 11:41am GMT+0000');
      expect(updatedAtEl.text()).toBe(wrapper.vm.updatedAt);
    });
  });
});