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

maven_settings_spec.js « components « group « settings « packages_and_registries « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 859d3587223a6245437cabe3ceb08a9266637046 (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
import { GlSprintf, GlToggle, GlFormGroup, GlFormInput } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import component from '~/packages_and_registries/settings/group/components/maven_settings.vue';

import {
  MAVEN_TITLE,
  MAVEN_SETTINGS_SUBTITLE,
  MAVEN_DUPLICATES_ALLOWED_DISABLED,
  MAVEN_DUPLICATES_ALLOWED_ENABLED,
  MAVEN_SETTING_EXCEPTION_TITLE,
  MAVEN_SETTINGS_EXCEPTION_LEGEND,
} from '~/packages_and_registries/settings/group/constants';

describe('Maven Settings', () => {
  let wrapper;

  const defaultProps = {
    mavenDuplicatesAllowed: false,
    mavenDuplicateExceptionRegex: 'foo',
  };

  const mountComponent = (propsData = defaultProps) => {
    wrapper = shallowMount(component, {
      propsData,
      stubs: {
        GlSprintf,
      },
    });
  };

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

  const findTitle = () => wrapper.find('h5');
  const findSubTitle = () => wrapper.find('p');
  const findToggle = () => wrapper.find(GlToggle);
  const findToggleLabel = () => wrapper.find('[data-testid="toggle-label"');

  const findInputGroup = () => wrapper.find(GlFormGroup);
  const findInput = () => wrapper.find(GlFormInput);

  it('has a title', () => {
    mountComponent();

    expect(findTitle().exists()).toBe(true);
    expect(findTitle().text()).toBe(MAVEN_TITLE);
  });

  it('has a subtitle', () => {
    mountComponent();

    expect(findSubTitle().exists()).toBe(true);
    expect(findSubTitle().text()).toBe(MAVEN_SETTINGS_SUBTITLE);
  });

  it('has a toggle', () => {
    mountComponent();

    expect(findToggle().exists()).toBe(true);
    expect(findToggle().props()).toMatchObject({
      label: component.i18n.MAVEN_TOGGLE_LABEL,
      value: defaultProps.mavenDuplicatesAllowed,
    });
  });

  it('toggle emits an update event', () => {
    mountComponent();

    findToggle().vm.$emit('change', false);

    expect(wrapper.emitted('update')).toEqual([[{ mavenDuplicatesAllowed: false }]]);
  });

  describe('when the duplicates are disabled', () => {
    it('the toggle has the disabled message', () => {
      mountComponent();

      expect(findToggleLabel().exists()).toBe(true);
      expect(findToggleLabel().text()).toMatchInterpolatedText(MAVEN_DUPLICATES_ALLOWED_DISABLED);
    });

    it('shows a form group with an input field', () => {
      mountComponent();

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

      expect(findInputGroup().attributes()).toMatchObject({
        'label-for': 'maven-duplicated-settings-regex-input',
        label: MAVEN_SETTING_EXCEPTION_TITLE,
        description: MAVEN_SETTINGS_EXCEPTION_LEGEND,
      });
    });

    it('shows an input field', () => {
      mountComponent();

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

      expect(findInput().attributes()).toMatchObject({
        id: 'maven-duplicated-settings-regex-input',
        value: defaultProps.mavenDuplicateExceptionRegex,
      });
    });

    it('input change event emits an update event', () => {
      mountComponent();

      findInput().vm.$emit('change', 'bar');

      expect(wrapper.emitted('update')).toEqual([[{ mavenDuplicateExceptionRegex: 'bar' }]]);
    });

    describe('valid state', () => {
      it('form group has correct props', () => {
        mountComponent();

        expect(findInputGroup().attributes()).toMatchObject({
          state: 'true',
          'invalid-feedback': '',
        });
      });
    });

    describe('invalid state', () => {
      it('form group has correct props', () => {
        const propsWithError = {
          ...defaultProps,
          mavenDuplicateExceptionRegexError: 'some error string',
        };

        mountComponent(propsWithError);

        expect(findInputGroup().attributes()).toMatchObject({
          'invalid-feedback': propsWithError.mavenDuplicateExceptionRegexError,
        });
      });
    });
  });

  describe('when the duplicates are enabled', () => {
    it('has the correct toggle label', () => {
      mountComponent({ ...defaultProps, mavenDuplicatesAllowed: true });

      expect(findToggleLabel().exists()).toBe(true);
      expect(findToggleLabel().text()).toMatchInterpolatedText(MAVEN_DUPLICATES_ALLOWED_ENABLED);
    });

    it('hides the form input group', () => {
      mountComponent({ ...defaultProps, mavenDuplicatesAllowed: true });

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