debian-mirror-gitlab/spec/frontend/vue_shared/components/dismissible_alert_spec.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { GlAlert } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-03-13 15:44:24 +05:30
import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue';
const TEST_HTML = 'Hello World! <strong>Foo</strong>';
describe('vue_shared/components/dismissible_alert', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = shallowMount(DismissibleAlert, {
propsData: {
html: TEST_HTML,
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
const findAlert = () => wrapper.find(GlAlert);
2021-09-30 23:02:18 +05:30
describe('default', () => {
2020-03-13 15:44:24 +05:30
beforeEach(() => {
createComponent();
});
it('shows alert', () => {
2021-09-30 23:02:18 +05:30
expect(findAlert().exists()).toBe(true);
2020-03-13 15:44:24 +05:30
});
it('shows given HTML', () => {
expect(findAlert().html()).toContain(TEST_HTML);
});
describe('when dismissed', () => {
beforeEach(() => {
findAlert().vm.$emit('dismiss');
});
it('hides the alert', () => {
expect(findAlert().exists()).toBe(false);
});
});
});
2021-09-30 23:02:18 +05:30
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>');
});
});
2020-03-13 15:44:24 +05:30
});