summaryrefslogtreecommitdiff
path: root/spec/frontend/work_items/components/work_item_detail_modal_spec.js
blob: 9f35ccb853b71f2a53bc101579576cdf3142d03c (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
import { GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import WorkItemDetail from '~/work_items/components/work_item_detail.vue';
import WorkItemDetailModal from '~/work_items/components/work_item_detail_modal.vue';
import WorkItemActions from '~/work_items/components/work_item_actions.vue';

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

  Vue.use(VueApollo);

  const findModal = () => wrapper.findComponent(GlModal);
  const findWorkItemActions = () => wrapper.findComponent(WorkItemActions);
  const findWorkItemDetail = () => wrapper.findComponent(WorkItemDetail);

  const createComponent = ({ visible = true, workItemId = '1', canUpdate = false } = {}) => {
    wrapper = shallowMount(WorkItemDetailModal, {
      propsData: { visible, workItemId, canUpdate },
      stubs: {
        GlModal,
      },
    });
  };

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

  describe.each([true, false])('when visible=%s', (visible) => {
    it(`${visible ? 'renders' : 'does not render'} modal`, () => {
      createComponent({ visible });

      expect(findModal().props('visible')).toBe(visible);
    });
  });

  it('renders heading', () => {
    createComponent();

    expect(wrapper.find('h2').text()).toBe('Work Item');
  });

  it('renders WorkItemDetail', () => {
    createComponent();

    expect(findWorkItemDetail().props()).toEqual({ workItemId: '1' });
  });

  it('shows work item actions', () => {
    createComponent({
      canUpdate: true,
    });

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