Commit 6c2f4921 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '3895-mlunoe-migrate-away-from-deprecated-create-flash-6' into 'master'

Chore(deprecatedCreateFlash): remove function

See merge request gitlab-org/gitlab!63903
parents 4f129f03 0b7ffc42
......@@ -125,34 +125,8 @@ const createFlash = function createFlash({
return flashContainer;
};
/*
* Flash banner supports different types of Flash configurations
* along with ability to provide actionConfig which can be used to show
* additional action or link on banner next to message
*
* @param {String} message Flash message text
* @param {String} type Type of Flash, it can be `notice`, `success`, `warning` or `alert` (default)
* @param {Object} parent Reference to parent element under which Flash needs to appear
* @param {Object} actionConfig Map of config to show action on banner
* @param {String} href URL to which action config should point to (default: '#')
* @param {String} title Title of action
* @param {Function} clickHandler Method to call when action is clicked on
* @param {Boolean} fadeTransition Boolean to determine whether to fade the alert out
*/
const deprecatedCreateFlash = function deprecatedCreateFlash(
message,
type,
parent,
actionConfig,
fadeTransition,
addBodyClass,
) {
return createFlash({ message, type, parent, actionConfig, fadeTransition, addBodyClass });
};
export {
createFlash as default,
deprecatedCreateFlash,
createFlashEl,
createAction,
hideFlash,
......
import createFlash, {
deprecatedCreateFlash,
createFlashEl,
createAction,
hideFlash,
......@@ -125,120 +124,6 @@ describe('Flash', () => {
});
});
describe('deprecatedCreateFlash', () => {
const message = 'test';
const type = 'alert';
const parent = document;
const actionConfig = null;
const fadeTransition = false;
const addBodyClass = true;
const defaultParams = [message, type, parent, actionConfig, fadeTransition, addBodyClass];
describe('no flash-container', () => {
it('does not add to the DOM', () => {
const flashEl = deprecatedCreateFlash(message);
expect(flashEl).toBeNull();
expect(document.querySelector('.flash-alert')).toBeNull();
});
});
describe('with flash-container', () => {
beforeEach(() => {
setFixtures(
'<div class="content-wrapper js-content-wrapper"><div class="flash-container"></div></div>',
);
});
afterEach(() => {
document.querySelector('.js-content-wrapper').remove();
});
it('adds flash element into container', () => {
deprecatedCreateFlash(...defaultParams);
expect(document.querySelector('.flash-alert')).not.toBeNull();
expect(document.body.className).toContain('flash-shown');
});
it('adds flash into specified parent', () => {
deprecatedCreateFlash(
message,
type,
document.querySelector('.content-wrapper'),
actionConfig,
fadeTransition,
addBodyClass,
);
expect(document.querySelector('.content-wrapper .flash-alert')).not.toBeNull();
expect(document.querySelector('.content-wrapper').innerText.trim()).toEqual(message);
});
it('adds container classes when inside content-wrapper', () => {
deprecatedCreateFlash(...defaultParams);
expect(document.querySelector('.flash-text').className).toBe('flash-text');
expect(document.querySelector('.content-wrapper').innerText.trim()).toEqual(message);
});
it('does not add container when outside of content-wrapper', () => {
document.querySelector('.content-wrapper').className = 'js-content-wrapper';
deprecatedCreateFlash(...defaultParams);
expect(document.querySelector('.flash-text').className.trim()).toContain('flash-text');
});
it('removes element after clicking', () => {
deprecatedCreateFlash(...defaultParams);
document.querySelector('.flash-alert .js-close-icon').click();
expect(document.querySelector('.flash-alert')).toBeNull();
expect(document.body.className).not.toContain('flash-shown');
});
describe('with actionConfig', () => {
it('adds action link', () => {
const newActionConfig = { title: 'test' };
deprecatedCreateFlash(
message,
type,
parent,
newActionConfig,
fadeTransition,
addBodyClass,
);
expect(document.querySelector('.flash-action')).not.toBeNull();
});
it('calls actionConfig clickHandler on click', () => {
const newActionConfig = {
title: 'test',
clickHandler: jest.fn(),
};
deprecatedCreateFlash(
message,
type,
parent,
newActionConfig,
fadeTransition,
addBodyClass,
);
document.querySelector('.flash-action').click();
expect(newActionConfig.clickHandler).toHaveBeenCalled();
});
});
});
});
describe('createFlash', () => {
const message = 'test';
const type = 'alert';
......
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