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

work_item_links_spec.js « work_item_links « components « work_items « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 774e9198992c3ee35fe20cf160c24613b72bdbf1 (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
import Vue, { nextTick } from 'vue';
import { GlBadge } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import WorkItemLinks from '~/work_items/components/work_item_links/work_item_links.vue';
import getWorkItemLinksQuery from '~/work_items/graphql/work_item_links.query.graphql';
import { workItemHierarchyResponse, workItemHierarchyEmptyResponse } from '../../mock_data';

Vue.use(VueApollo);

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

  const createComponent = async ({ response = workItemHierarchyResponse } = {}) => {
    wrapper = shallowMountExtended(WorkItemLinks, {
      apolloProvider: createMockApollo([
        [getWorkItemLinksQuery, jest.fn().mockResolvedValue(response)],
      ]),
      propsData: { issuableId: 1 },
    });

    await waitForPromises();
  };

  const findToggleButton = () => wrapper.findByTestId('toggle-links');
  const findLinksBody = () => wrapper.findByTestId('links-body');
  const findEmptyState = () => wrapper.findByTestId('links-empty');
  const findToggleAddFormButton = () => wrapper.findByTestId('toggle-add-form');
  const findAddLinksForm = () => wrapper.findByTestId('add-links-form');

  beforeEach(async () => {
    await createComponent();
  });

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

  it('is expanded by default', () => {
    expect(findToggleButton().props('icon')).toBe('chevron-lg-up');
    expect(findLinksBody().exists()).toBe(true);
  });

  it('expands on click toggle button', async () => {
    findToggleButton().vm.$emit('click');
    await nextTick();

    expect(findToggleButton().props('icon')).toBe('chevron-lg-down');
    expect(findLinksBody().exists()).toBe(false);
  });

  describe('when no child links', () => {
    beforeEach(async () => {
      await createComponent({ response: workItemHierarchyEmptyResponse });
    });

    it('displays empty state if there are no children', () => {
      expect(findEmptyState().exists()).toBe(true);
    });

    describe('add link form', () => {
      it('displays form on click add button and hides form on cancel', async () => {
        expect(findEmptyState().exists()).toBe(true);

        findToggleAddFormButton().vm.$emit('click');
        await nextTick();

        expect(findAddLinksForm().exists()).toBe(true);

        findAddLinksForm().vm.$emit('cancel');
        await nextTick();

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

  it('renders all hierarchy widget children', () => {
    expect(findLinksBody().exists()).toBe(true);

    const children = wrapper.findAll('[data-testid="links-child"]');

    expect(children).toHaveLength(4);
    expect(children.at(0).findComponent(GlBadge).text()).toBe('Open');
  });
});