diff options
Diffstat (limited to 'spec/frontend/vue_shared/components/dismissible_alert_spec.js')
-rw-r--r-- | spec/frontend/vue_shared/components/dismissible_alert_spec.js | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/spec/frontend/vue_shared/components/dismissible_alert_spec.js b/spec/frontend/vue_shared/components/dismissible_alert_spec.js index cfa6d1064e5..fcd004d35a7 100644 --- a/spec/frontend/vue_shared/components/dismissible_alert_spec.js +++ b/spec/frontend/vue_shared/components/dismissible_alert_spec.js @@ -5,18 +5,12 @@ import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue'; const TEST_HTML = 'Hello World! <strong>Foo</strong>'; describe('vue_shared/components/dismissible_alert', () => { - const testAlertProps = { - primaryButtonText: 'Lorem ipsum', - primaryButtonLink: '/lorem/ipsum', - }; - let wrapper; const createComponent = (props = {}) => { wrapper = shallowMount(DismissibleAlert, { propsData: { html: TEST_HTML, - ...testAlertProps, ...props, }, }); @@ -28,16 +22,13 @@ describe('vue_shared/components/dismissible_alert', () => { const findAlert = () => wrapper.find(GlAlert); - describe('with default', () => { + describe('default', () => { beforeEach(() => { createComponent(); }); it('shows alert', () => { - const alert = findAlert(); - - expect(alert.exists()).toBe(true); - expect(alert.props()).toEqual(expect.objectContaining(testAlertProps)); + expect(findAlert().exists()).toBe(true); }); it('shows given HTML', () => { @@ -54,4 +45,32 @@ describe('vue_shared/components/dismissible_alert', () => { }); }); }); + + describe('with additional props', () => { + const testAlertProps = { + dismissible: true, + title: 'Mock Title', + primaryButtonText: 'Lorem ipsum', + primaryButtonLink: '/lorem/ipsum', + variant: 'warning', + }; + + beforeEach(() => { + createComponent(testAlertProps); + }); + + it('passes other props', () => { + expect(findAlert().props()).toEqual(expect.objectContaining(testAlertProps)); + }); + }); + + describe('with unsafe HTML', () => { + beforeEach(() => { + createComponent({ html: '<a onclick="alert("XSS")">Link</a>' }); + }); + + it('removes unsafe HTML', () => { + expect(findAlert().html()).toContain('<a>Link</a>'); + }); + }); }); |