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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
1.8 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,
},
});
};
2022-08-27 11:52:29 +05:30
const findAlert = () => wrapper.findComponent(GlAlert);
2020-03-13 15:44:24 +05:30
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);
});
2022-01-26 12:08:38 +05:30
it('emmits alertDismissed', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.emitted()).toHaveProperty('alertDismissed');
2022-01-26 12:08:38 +05:30
});
2020-03-13 15:44:24 +05:30
});
});
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
});