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
|
import { GlSprintf, GlFormGroup, GlFormInput } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import component from '~/packages_and_registries/settings/group/components/exceptions_input.vue';
import { DUPLICATES_SETTING_EXCEPTION_TITLE } from '~/packages_and_registries/settings/group/constants';
describe('Exceptions Input', () => {
let wrapper;
const defaultProps = {
duplicatesAllowed: false,
duplicateExceptionRegex: 'foo',
id: 'maven-duplicated-settings-regex-input',
name: 'exceptionModel',
};
const mountComponent = (propsData = defaultProps) => {
wrapper = shallowMount(component, {
propsData,
stubs: {
GlSprintf,
},
});
};
afterEach(() => {
wrapper.destroy();
});
const findInputGroup = () => wrapper.findComponent(GlFormGroup);
const findInput = () => wrapper.findComponent(GlFormInput);
it('shows a form group with an input field', () => {
mountComponent();
expect(findInputGroup().exists()).toBe(true);
expect(findInputGroup().attributes()).toMatchObject({
'label-for': defaultProps.id,
label: DUPLICATES_SETTING_EXCEPTION_TITLE,
'label-sr-only': '',
});
});
it('shows an input field', () => {
mountComponent();
expect(findInput().exists()).toBe(true);
expect(findInput().attributes()).toMatchObject({
id: 'maven-duplicated-settings-regex-input',
value: defaultProps.duplicateExceptionRegex,
});
});
it('input change event emits an update event', () => {
mountComponent();
findInput().vm.$emit('change', 'bar');
expect(wrapper.emitted('update')).toStrictEqual([[{ [defaultProps.name]: 'bar' }]]);
});
describe('valid state', () => {
beforeEach(() => {
mountComponent();
});
it('form group has correct props', () => {
expect(findInputGroup().attributes('input-feedback')).toBeUndefined();
});
it('form input has correct props', () => {
expect(findInput().attributes('state')).toBe('true');
});
});
describe('invalid state', () => {
const propsWithError = {
...defaultProps,
duplicateExceptionRegexError: 'some error string',
};
beforeEach(() => {
mountComponent(propsWithError);
});
it('form group has correct props', () => {
expect(findInputGroup().attributes('invalid-feedback')).toBe(
propsWithError.duplicateExceptionRegexError,
);
});
it('form input has correct props', () => {
expect(findInput().attributes('state')).toBeUndefined();
});
});
describe('loading', () => {
beforeEach(() => {
mountComponent({ ...defaultProps, loading: true });
});
it('disables the form input', () => {
expect(findInput().attributes('disabled')).toBe('true');
});
});
});
|