diff options
Diffstat (limited to 'spec/frontend/abuse_reports/components/links_to_spam_input_spec.js')
-rw-r--r-- | spec/frontend/abuse_reports/components/links_to_spam_input_spec.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/frontend/abuse_reports/components/links_to_spam_input_spec.js b/spec/frontend/abuse_reports/components/links_to_spam_input_spec.js new file mode 100644 index 00000000000..c0c87dd1383 --- /dev/null +++ b/spec/frontend/abuse_reports/components/links_to_spam_input_spec.js @@ -0,0 +1,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', + }); + }); + }); + }); +}); |