Commit f5dd5463 authored by Miguel Rincon's avatar Miguel Rincon

Remove "createFlashEl" from flash exports

This change removes "createFlashEl" from exports of "~/flash" to reduce
the developer interface of createFlash.
parent 6f1082ba
...@@ -130,7 +130,6 @@ const createFlash = function createFlash({ ...@@ -130,7 +130,6 @@ const createFlash = function createFlash({
export { export {
createFlash as default, createFlash as default,
createFlashEl,
createAction, createAction,
hideFlash, hideFlash,
removeFlashClickListener, removeFlashClickListener,
......
import createFlash, { import createFlash, {
createFlashEl,
createAction, createAction,
hideFlash, hideFlash,
removeFlashClickListener, removeFlashClickListener,
FLASH_TYPES,
FLASH_CLOSED_EVENT, FLASH_CLOSED_EVENT,
} from '~/flash'; } from '~/flash';
describe('Flash', () => { describe('Flash', () => {
describe('createFlashEl', () => {
let el;
beforeEach(() => {
el = document.createElement('div');
});
afterEach(() => {
el.innerHTML = '';
});
it('creates flash element with type', () => {
el.innerHTML = createFlashEl('testing', 'alert');
expect(el.querySelector('.flash-alert')).not.toBeNull();
});
it('escapes text', () => {
el.innerHTML = createFlashEl('<script>alert("a");</script>', 'alert');
expect(el.querySelector('.flash-text').textContent.trim()).toBe(
'<script>alert("a");</script>',
);
});
});
describe('hideFlash', () => { describe('hideFlash', () => {
let el; let el;
...@@ -137,14 +111,10 @@ describe('Flash', () => { ...@@ -137,14 +111,10 @@ describe('Flash', () => {
describe('createFlash', () => { describe('createFlash', () => {
const message = 'test'; const message = 'test';
const type = 'alert';
const parent = document;
const fadeTransition = false; const fadeTransition = false;
const addBodyClass = true; const addBodyClass = true;
const defaultParams = { const defaultParams = {
message, message,
type,
parent,
actionConfig: null, actionConfig: null,
fadeTransition, fadeTransition,
addBodyClass, addBodyClass,
...@@ -171,14 +141,28 @@ describe('Flash', () => { ...@@ -171,14 +141,28 @@ describe('Flash', () => {
document.querySelector('.js-content-wrapper').remove(); document.querySelector('.js-content-wrapper').remove();
}); });
it('adds flash element into container', () => { it('adds flash alert element into the document by default', () => {
createFlash({ ...defaultParams }); createFlash({ ...defaultParams });
expect(document.querySelector('.flash-alert')).not.toBeNull(); expect(document.querySelector('.flash-container .flash-alert')).not.toBeNull();
expect(document.body.className).toContain('flash-shown');
});
it('adds flash of a warning type', () => {
createFlash({ ...defaultParams, type: FLASH_TYPES.WARNING });
expect(document.querySelector('.flash-container .flash-warning')).not.toBeNull();
expect(document.body.className).toContain('flash-shown'); expect(document.body.className).toContain('flash-shown');
}); });
it('escapes text', () => {
createFlash({ ...defaultParams, message: '<script>alert("a");</script>' });
expect(document.querySelector('.flash-text').textContent.trim()).toBe(
'<script>alert("a");</script>',
);
});
it('adds flash into specified parent', () => { it('adds flash into specified parent', () => {
createFlash({ ...defaultParams, parent: document.querySelector('.content-wrapper') }); createFlash({ ...defaultParams, parent: document.querySelector('.content-wrapper') });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment