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

jira_trigger_fields_spec.js « components « edit « integrations « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c04add61a116b451f8b3fd55c3b7726c4277869 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { GlFormCheckbox } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import JiraTriggerFields from '~/integrations/edit/components/jira_trigger_fields.vue';

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

  const defaultProps = {
    initialTriggerCommit: false,
    initialTriggerMergeRequest: false,
    initialEnableComments: false,
  };

  const createComponent = (props, isInheriting = false) => {
    wrapper = mount(JiraTriggerFields, {
      propsData: { ...defaultProps, ...props },
      computed: {
        isInheriting: () => isInheriting,
      },
    });
  };

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

  const findCommentSettings = () => wrapper.find('[data-testid="comment-settings"]');
  const findCommentDetail = () => wrapper.find('[data-testid="comment-detail"]');
  const findCommentSettingsCheckbox = () => findCommentSettings().find(GlFormCheckbox);
  const findIssueTransitionEnabled = () =>
    wrapper.find('[data-testid="issue-transition-enabled"] input[type="checkbox"]');
  const findIssueTransitionMode = () => wrapper.find('[data-testid="issue-transition-mode"]');
  const findIssueTransitionModeRadios = () =>
    findIssueTransitionMode().findAll('input[type="radio"]');
  const findIssueTransitionIdsField = () =>
    wrapper.find('input[type="text"][name="service[jira_issue_transition_id]"]');

  describe('template', () => {
    describe('initialTriggerCommit and initialTriggerMergeRequest are false', () => {
      it('does not show trigger settings', () => {
        createComponent();

        expect(findCommentSettings().isVisible()).toBe(false);
        expect(findCommentDetail().isVisible()).toBe(false);
        expect(findIssueTransitionEnabled().exists()).toBe(false);
        expect(findIssueTransitionMode().exists()).toBe(false);
      });
    });

    describe('initialTriggerCommit is true', () => {
      beforeEach(() => {
        createComponent({
          initialTriggerCommit: true,
        });
      });

      it('shows trigger settings', () => {
        expect(findCommentSettings().isVisible()).toBe(true);
        expect(findCommentDetail().isVisible()).toBe(false);
        expect(findIssueTransitionEnabled().isVisible()).toBe(true);
        expect(findIssueTransitionMode().exists()).toBe(false);
      });

      // As per https://vuejs.org/v2/guide/forms.html#Checkbox-1,
      // browsers don't include unchecked boxes in form submissions.
      it('includes comment settings as false even if unchecked', () => {
        expect(
          findCommentSettings().find('input[name="service[comment_on_event_enabled]"]').exists(),
        ).toBe(true);
      });

      describe('on enable comments', () => {
        it('shows comment detail', () => {
          findCommentSettingsCheckbox().vm.$emit('input', true);

          return wrapper.vm.$nextTick().then(() => {
            expect(findCommentDetail().isVisible()).toBe(true);
          });
        });
      });
    });

    describe('initialTriggerMergeRequest is true', () => {
      it('shows trigger settings', () => {
        createComponent({
          initialTriggerMergeRequest: true,
        });

        expect(findCommentSettings().isVisible()).toBe(true);
        expect(findCommentDetail().isVisible()).toBe(false);
        expect(findIssueTransitionEnabled().isVisible()).toBe(true);
        expect(findIssueTransitionMode().exists()).toBe(false);
      });
    });

    describe('initialTriggerCommit is true, initialEnableComments is true', () => {
      it('shows comment settings and comment detail', () => {
        createComponent({
          initialTriggerCommit: true,
          initialEnableComments: true,
        });

        expect(findCommentSettings().isVisible()).toBe(true);
        expect(findCommentDetail().isVisible()).toBe(true);
      });
    });

    describe('initialJiraIssueTransitionAutomatic is false, initialJiraIssueTransitionId is not set', () => {
      it('selects automatic transitions when enabling transitions', () => {
        createComponent({
          initialTriggerCommit: true,
          initialEnableComments: true,
        });

        const checkbox = findIssueTransitionEnabled();
        expect(checkbox.element.checked).toBe(false);
        checkbox.trigger('click');

        return wrapper.vm.$nextTick().then(() => {
          const [radio1, radio2] = findIssueTransitionModeRadios().wrappers;
          expect(radio1.element.checked).toBe(true);
          expect(radio2.element.checked).toBe(false);
        });
      });
    });

    describe('initialJiraIssueTransitionAutomatic is true', () => {
      it('uses automatic transitions', () => {
        createComponent({
          initialTriggerCommit: true,
          initialJiraIssueTransitionAutomatic: true,
        });

        expect(findIssueTransitionEnabled().element.checked).toBe(true);

        const [radio1, radio2] = findIssueTransitionModeRadios().wrappers;
        expect(radio1.element.checked).toBe(true);
        expect(radio2.element.checked).toBe(false);

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

    describe('initialJiraIssueTransitionId is set', () => {
      it('uses custom transitions', () => {
        createComponent({
          initialTriggerCommit: true,
          initialJiraIssueTransitionId: '1, 2, 3',
        });

        expect(findIssueTransitionEnabled().element.checked).toBe(true);

        const [radio1, radio2] = findIssueTransitionModeRadios().wrappers;
        expect(radio1.element.checked).toBe(false);
        expect(radio2.element.checked).toBe(true);

        const field = findIssueTransitionIdsField();
        expect(field.isVisible()).toBe(true);
        expect(field.element).toMatchObject({
          type: 'text',
          value: '1, 2, 3',
        });
      });
    });

    describe('initialJiraIssueTransitionAutomatic is true, initialJiraIssueTransitionId is set', () => {
      it('uses automatic transitions', () => {
        createComponent({
          initialTriggerCommit: true,
          initialJiraIssueTransitionAutomatic: true,
          initialJiraIssueTransitionId: '1, 2, 3',
        });

        expect(findIssueTransitionEnabled().element.checked).toBe(true);

        const [radio1, radio2] = findIssueTransitionModeRadios().wrappers;
        expect(radio1.element.checked).toBe(true);
        expect(radio2.element.checked).toBe(false);

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

    it('disables input fields if inheriting', () => {
      createComponent(
        {
          initialTriggerCommit: true,
          initialEnableComments: true,
          initialJiraIssueTransitionId: '1, 2, 3',
        },
        true,
      );

      wrapper.findAll('[type=text], [type=checkbox], [type=radio]').wrappers.forEach((input) => {
        expect(input.attributes('disabled')).toBe('disabled');
      });
    });
  });
});