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

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: c329ca8522f2a677e36803c7b6c3440cd4322393 (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
import { GlFormGroup, GlFormCheckbox, GlFormInput } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper';

import TriggerFields from '~/integrations/edit/components/trigger_fields.vue';

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

  const defaultProps = {
    type: 'slack',
  };

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

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

  const findTriggerLabel = () => wrapper.findByTestId('trigger-fields-group').find('label');
  const findAllGlFormGroups = () => wrapper.find('#trigger-fields').findAllComponents(GlFormGroup);
  const findAllGlFormCheckboxes = () => wrapper.findAllComponents(GlFormCheckbox);
  const findAllGlFormInputs = () => wrapper.findAllComponents(GlFormInput);

  describe.each([true, false])('template, isInheriting = `%p`', (isInheriting) => {
    it('renders a label with text "Trigger"', () => {
      createComponent();

      const triggerLabel = findTriggerLabel();
      expect(triggerLabel.exists()).toBe(true);
      expect(triggerLabel.text()).toBe('Trigger');
    });

    describe('events without field property', () => {
      const events = [
        {
          title: 'Push',
          name: 'push_event',
          description: 'Event on push',
          value: true,
        },
        {
          title: 'Merge request',
          name: 'merge_requests_event',
          description: 'Event on merge_request',
          value: false,
        },
      ];

      beforeEach(() => {
        createComponent(
          {
            events,
          },
          isInheriting,
        );
      });

      it('does not render GlFormInput for each event', () => {
        expect(findAllGlFormInputs().exists()).toBe(false);
      });

      it('renders GlFormInput with description for each event', () => {
        const groups = findAllGlFormGroups();

        expect(groups).toHaveLength(2);
        groups.wrappers.forEach((group, index) => {
          expect(group.find('small').text()).toBe(events[index].description);
        });
      });

      it(`renders GlFormCheckbox and corresponding hidden input for each event, which ${
        isInheriting ? 'is' : 'is not'
      } disabled`, () => {
        const checkboxes = findAllGlFormGroups();
        const expectedResults = [
          { labelText: 'Push', inputName: 'service[push_event]' },
          { labelText: 'Merge request', inputName: 'service[merge_requests_event]' },
        ];
        expect(checkboxes).toHaveLength(2);

        checkboxes.wrappers.forEach((checkbox, index) => {
          const checkBox = checkbox.findComponent(GlFormCheckbox);

          expect(checkbox.find('label').text()).toBe(expectedResults[index].labelText);
          expect(checkbox.find('[type=hidden]').attributes('name')).toBe(
            expectedResults[index].inputName,
          );
          expect(checkbox.find('[type=hidden]').attributes('value')).toBe(
            events[index].value.toString(),
          );
          expect(checkBox.vm.$attrs.disabled).toBe(isInheriting);
          expect(checkBox.vm.$attrs.checked).toBe(events[index].value);
        });
      });
    });

    describe('events with field property, isInheriting = `%p`', () => {
      const events = [
        {
          field: {
            name: 'push_channel',
            value: '',
          },
        },
        {
          field: {
            name: 'merge_request_channel',
            value: 'gitlab-development',
          },
        },
      ];

      beforeEach(() => {
        createComponent(
          {
            events,
          },
          isInheriting,
        );
      });

      it('renders GlFormCheckbox for each event', () => {
        expect(findAllGlFormCheckboxes()).toHaveLength(2);
      });

      it(`renders GlFormInput for each event, which ${
        isInheriting ? 'is' : 'is not'
      } readonly`, () => {
        const fields = findAllGlFormInputs();
        const expectedResults = [
          {
            name: 'service[push_channel]',
            placeholder: '#general, #development',
          },
          {
            name: 'service[merge_request_channel]',
            placeholder: '#general, #development',
          },
        ];

        expect(fields).toHaveLength(2);

        fields.wrappers.forEach((field, index) => {
          expect(field.attributes()).toMatchObject(expectedResults[index]);
          expect(field.vm.$attrs.readonly).toBe(isInheriting);
          expect(field.vm.$attrs.value).toBe(events[index].field.value);
        });
      });
    });
  });
});