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
|
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import ListboxInput from '~/vue_shared/components/listbox_input/listbox_input.vue';
import NotificationEmailListboxInput from '~/notifications/components/notification_email_listbox_input.vue';
describe('NotificationEmailListboxInput', () => {
let wrapper;
// Props
const label = 'label';
const name = 'name';
const emails = ['test@gitlab.com'];
const emptyValueText = 'emptyValueText';
const value = 'value';
const disabled = false;
// Finders
const findListboxInput = () => wrapper.findComponent(ListboxInput);
const createComponent = (attachTo) => {
wrapper = shallowMount(NotificationEmailListboxInput, {
provide: {
label,
name,
emails,
emptyValueText,
value,
disabled,
},
attachTo,
});
};
describe('props', () => {
beforeEach(() => {
createComponent();
});
it.each`
propName | propValue
${'label'} | ${label}
${'name'} | ${name}
${'selected'} | ${value}
${'disabled'} | ${disabled}
`('passes the $propName prop to ListboxInput', ({ propName, propValue }) => {
expect(findListboxInput().props(propName)).toBe(propValue);
});
it('passes the options to ListboxInput', () => {
expect(findListboxInput().props('items')).toStrictEqual([
{ text: emptyValueText, value: '' },
{ text: emails[0], value: emails[0] },
]);
});
});
describe('form', () => {
let form;
beforeEach(() => {
form = document.createElement('form');
const root = document.createElement('div');
form.appendChild(root);
createComponent(root);
});
afterEach(() => {
form = null;
});
it('submits the parent form when the value changes', async () => {
jest.spyOn(form, 'submit');
expect(form.submit).not.toHaveBeenCalled();
findListboxInput().vm.$emit('select');
await nextTick();
expect(form.submit).toHaveBeenCalled();
});
});
});
|