diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-13 15:10:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-13 15:10:07 +0300 |
commit | df592d51aeadc1b566abb600e283341876a8f064 (patch) | |
tree | 6b9acbcf1da5c40cceece035b0126a354f68650a /spec/frontend/vue_shared/components | |
parent | 7ece9a7935fca35a8d91d2cb29bfad453b69be12 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components')
-rw-r--r-- | spec/frontend/vue_shared/components/form/errors_alert_spec.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/form/errors_alert_spec.js b/spec/frontend/vue_shared/components/form/errors_alert_spec.js new file mode 100644 index 00000000000..b7efe19378d --- /dev/null +++ b/spec/frontend/vue_shared/components/form/errors_alert_spec.js @@ -0,0 +1,60 @@ +import { GlAlert } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import FormErrorsAlert from '~/vue_shared/components/form/errors_alert.vue'; + +describe('FormErrorsAlert', () => { + let wrapper; + + const defaultPropsData = { + errors: ['Foo', 'Bar', 'Baz'], + }; + + function createComponent({ propsData = {} } = {}) { + wrapper = shallowMount(FormErrorsAlert, { + propsData: { + ...defaultPropsData, + ...propsData, + }, + }); + } + + const findAlert = () => wrapper.findComponent(GlAlert); + + describe('when there are no errors', () => { + it('renders nothing', () => { + createComponent({ propsData: { errors: [] } }); + + expect(wrapper.html()).toBe(''); + }); + }); + + describe('when there is one error', () => { + it('renders correct title and message', () => { + createComponent({ propsData: { errors: ['Foo'] } }); + + expect(findAlert().props('title')).toBe('The form contains the following error:'); + expect(findAlert().text()).toContain('Foo'); + }); + }); + + describe('when there are multiple errors', () => { + it('renders correct title and message', () => { + createComponent(); + + expect(findAlert().props('title')).toBe('The form contains the following errors:'); + expect(findAlert().text()).toContain('Foo'); + expect(findAlert().text()).toContain('Bar'); + expect(findAlert().text()).toContain('Baz'); + }); + }); + + describe('when alert is dismissed', () => { + it('emits input event with empty array as payload', () => { + createComponent(); + + findAlert().vm.$emit('dismiss'); + + expect(wrapper.emitted('input')).toEqual([[[]]]); + }); + }); +}); |