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
|
import { GlButton, GlFormGroup, GlFormInput } from '@gitlab/ui';
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import LinksToSpamInput from '~/abuse_reports/components/links_to_spam_input.vue';
describe('LinksToSpamInput', () => {
let wrapper;
const createComponent = (props) => {
wrapper = shallowMountExtended(LinksToSpamInput, {
propsData: {
...props,
},
});
};
beforeEach(() => {
createComponent();
});
const findAllFormGroups = () => wrapper.findAllComponents(GlFormGroup);
const findLinkInput = () => wrapper.findComponent(GlFormInput);
const findAddAnotherButton = () => wrapper.findComponent(GlButton);
describe('Form Input', () => {
it('renders only one input field initially', () => {
expect(findAllFormGroups()).toHaveLength(1);
});
it('is of type URL and has a name attribute', () => {
expect(findLinkInput().attributes()).toMatchObject({
type: 'url',
name: 'abuse_report[links_to_spam][]',
value: '',
});
});
describe('when add another link button is clicked', () => {
it('adds another input', async () => {
findAddAnotherButton().vm.$emit('click');
await nextTick();
expect(findAllFormGroups()).toHaveLength(2);
});
});
describe('when previously added links are passed to the form as props', () => {
beforeEach(() => {
createComponent({ previousLinks: ['https://gitlab.com'] });
});
it('renders the input field with the value of the link pre-filled', () => {
expect(findAllFormGroups()).toHaveLength(1);
expect(findLinkInput().attributes()).toMatchObject({
type: 'url',
name: 'abuse_report[links_to_spam][]',
value: 'https://gitlab.com',
});
});
});
});
});
|