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

board_new_issue_spec.js « components « boards « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 737a18294bccc3bc485d4fba7c7afa4d018c8f77 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import BoardNewIssue from '~/boards/components/board_new_issue.vue';

import { mockList, mockGroupProjects } from '../mock_data';

const localVue = createLocalVue();

localVue.use(Vuex);

describe('Issue boards new issue form', () => {
  let wrapper;
  let vm;

  const addListNewIssuesSpy = jest.fn();

  const findSubmitButton = () => wrapper.find({ ref: 'submitButton' });
  const findCancelButton = () => wrapper.find({ ref: 'cancelButton' });
  const findSubmitForm = () => wrapper.find({ ref: 'submitForm' });

  const submitIssue = () => {
    const dummySubmitEvent = {
      preventDefault() {},
    };

    return findSubmitForm().trigger('submit', dummySubmitEvent);
  };

  beforeEach(() => {
    const store = new Vuex.Store({
      state: { selectedProject: mockGroupProjects[0] },
      actions: { addListNewIssue: addListNewIssuesSpy },
      getters: { isGroupBoard: () => false, isProjectBoard: () => true },
    });

    wrapper = shallowMount(BoardNewIssue, {
      propsData: {
        disabled: false,
        list: mockList,
      },
      store,
      localVue,
      provide: {
        groupId: null,
        weightFeatureAvailable: false,
        boardWeight: null,
      },
    });

    vm = wrapper.vm;

    return vm.$nextTick();
  });

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

  it('calls submit if submit button is clicked', async () => {
    jest.spyOn(wrapper.vm, 'submit').mockImplementation();
    wrapper.setData({ title: 'Testing Title' });

    await vm.$nextTick();
    await submitIssue();
    expect(wrapper.vm.submit).toHaveBeenCalled();
  });

  it('disables submit button if title is empty', () => {
    expect(findSubmitButton().props().disabled).toBe(true);
  });

  it('enables submit button if title is not empty', async () => {
    wrapper.setData({ title: 'Testing Title' });

    await vm.$nextTick();
    expect(wrapper.find({ ref: 'input' }).element.value).toBe('Testing Title');
    expect(findSubmitButton().props().disabled).toBe(false);
  });

  it('clears title after clicking cancel', async () => {
    findCancelButton().trigger('click');

    await vm.$nextTick();
    expect(vm.title).toBe('');
  });

  describe('submit success', () => {
    it('creates new issue', async () => {
      wrapper.setData({ title: 'submit issue' });

      await vm.$nextTick();
      await submitIssue();
      expect(addListNewIssuesSpy).toHaveBeenCalled();
    });

    it('enables button after submit', async () => {
      jest.spyOn(wrapper.vm, 'submit').mockImplementation();
      wrapper.setData({ title: 'submit issue' });

      await vm.$nextTick();
      await submitIssue();
      expect(findSubmitButton().props().disabled).toBe(false);
    });

    it('clears title after submit', async () => {
      wrapper.setData({ title: 'submit issue' });

      await vm.$nextTick();
      await submitIssue();
      await vm.$nextTick();
      expect(vm.title).toBe('');
    });
  });
});