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

work_item_created_updated_spec.js « components « work_items « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f14615e17377f33dd3f789592d616828bab1d4c (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
import { GlAvatarLink, GlSprintf, GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import WorkItemCreatedUpdated from '~/work_items/components/work_item_created_updated.vue';
import ConfidentialityBadge from '~/vue_shared/components/confidentiality_badge.vue';
import WorkItemTypeIcon from '~/work_items/components/work_item_type_icon.vue';
import groupWorkItemByIidQuery from '~/work_items/graphql/group_work_item_by_iid.query.graphql';
import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql';
import {
  groupWorkItemByIidResponseFactory,
  mockAssignees,
  workItemByIidResponseFactory,
} from '../mock_data';

describe('WorkItemCreatedUpdated component', () => {
  let wrapper;
  let successHandler;
  let groupSuccessHandler;

  Vue.use(VueApollo);

  const findCreatedAt = () => wrapper.find('[data-testid="work-item-created"]');
  const findUpdatedAt = () => wrapper.find('[data-testid="work-item-updated"]');

  const findCreatedAtText = () => findCreatedAt().text().replace(/\s+/g, ' ');
  const findWorkItemTypeIcon = () => wrapper.findComponent(WorkItemTypeIcon);
  const findConfidentialityBadge = () => wrapper.findComponent(ConfidentialityBadge);
  const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);

  const createComponent = async ({
    workItemIid = '1',
    author = null,
    updatedAt,
    confidential = false,
    updateInProgress = false,
    isGroup = false,
  } = {}) => {
    const workItemQueryResponse = workItemByIidResponseFactory({ author, updatedAt, confidential });
    const groupWorkItemQueryResponse = groupWorkItemByIidResponseFactory({
      author,
      updatedAt,
      confidential,
    });

    successHandler = jest.fn().mockResolvedValue(workItemQueryResponse);
    groupSuccessHandler = jest.fn().mockResolvedValue(groupWorkItemQueryResponse);

    wrapper = shallowMount(WorkItemCreatedUpdated, {
      apolloProvider: createMockApollo([
        [workItemByIidQuery, successHandler],
        [groupWorkItemByIidQuery, groupSuccessHandler],
      ]),
      provide: {
        isGroup,
      },
      propsData: {
        fullPath: '/some/project',
        workItemIid,
        updateInProgress,
      },
      stubs: {
        GlAvatarLink,
        GlSprintf,
      },
    });

    await waitForPromises();
  };

  describe('when project context', () => {
    it('calls the project work item query', async () => {
      await createComponent();

      expect(successHandler).toHaveBeenCalled();
    });

    it('skips calling the group work item query', async () => {
      await createComponent();

      expect(groupSuccessHandler).not.toHaveBeenCalled();
    });

    it('skips calling the project work item query when workItemIid is not defined', async () => {
      await createComponent({ workItemIid: null });

      expect(successHandler).not.toHaveBeenCalled();
    });
  });

  describe('when group context', () => {
    it('skips calling the project work item query', async () => {
      await createComponent({ isGroup: true });

      expect(successHandler).not.toHaveBeenCalled();
    });

    it('calls the group work item query', async () => {
      await createComponent({ isGroup: true });

      expect(groupSuccessHandler).toHaveBeenCalled();
    });

    it('skips calling the group work item query when workItemIid is not defined', async () => {
      await createComponent({ isGroup: true, workItemIid: null });

      expect(groupSuccessHandler).not.toHaveBeenCalled();
    });
  });

  it('shows work item type metadata with type and icon', async () => {
    await createComponent();

    const {
      data: { workspace: { workItems } = {} },
    } = workItemByIidResponseFactory();

    expect(findWorkItemTypeIcon().props()).toMatchObject({
      showText: true,
      workItemIconName: workItems.nodes[0].workItemType.iconName,
      workItemType: workItems.nodes[0].workItemType.name,
    });
  });

  it('shows author name and link', async () => {
    const author = mockAssignees[0];
    await createComponent({ author });

    expect(findCreatedAtText()).toBe(`created by ${author.name}`);
  });

  it('shows created time when author is null', async () => {
    await createComponent({ author: null });

    expect(findCreatedAtText()).toBe('created');
  });

  it('shows updated time', async () => {
    await createComponent();

    expect(findUpdatedAt().exists()).toBe(true);
  });

  it('does not show updated time for new work items', async () => {
    await createComponent({ updatedAt: null });

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

  describe('confidential badge', () => {
    it('renders badge when the work item is confidential', async () => {
      await createComponent({ confidential: true });

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

    it('does not render badge when the work item is confidential', async () => {
      await createComponent({ confidential: false });

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

    it('shows loading icon badge when the work item is confidential', async () => {
      await createComponent({ updateInProgress: true });

      expect(findLoadingIcon().exists()).toBe(true);
    });
  });
});