Commit fcd842b5 authored by Phil Hughes's avatar Phil Hughes

fixed notes specs

changed how the container class is added onto the text element
more specs
parent cbfc97b1
...@@ -12,6 +12,7 @@ const hideFlash = (flashEl, fadeTransition = true) => { ...@@ -12,6 +12,7 @@ const hideFlash = (flashEl, fadeTransition = true) => {
flashEl.remove(); flashEl.remove();
}, { }, {
once: true, once: true,
passive: true,
}); });
if (!fadeTransition) flashEl.dispatchEvent(new Event('transitionend')); if (!fadeTransition) flashEl.dispatchEvent(new Event('transitionend'));
...@@ -27,12 +28,12 @@ const createAction = config => ` ...@@ -27,12 +28,12 @@ const createAction = config => `
</a> </a>
`; `;
const createFlashEl = (message, type) => ` const createFlashEl = (message, type, isInContentWrapper = false) => `
<div <div
class="flash-${type}" class="flash-${type}"
> >
<div <div
class="flash-text" class="flash-text ${isInContentWrapper ? 'container-fluid container-limited' : ''}"
> >
${_.escape(message)} ${_.escape(message)}
</div> </div>
...@@ -64,7 +65,9 @@ const createFlash = function createFlash( ...@@ -64,7 +65,9 @@ const createFlash = function createFlash(
if (!flashContainer) return null; if (!flashContainer) return null;
flashContainer.innerHTML = createFlashEl(message, type); const isInContentWrapper = flashContainer.parentNode.classList.contains('content-wrapper');
flashContainer.innerHTML = createFlashEl(message, type, isInContentWrapper);
const flashEl = flashContainer.querySelector(`.flash-${type}`); const flashEl = flashContainer.querySelector(`.flash-${type}`);
flashEl.addEventListener('click', () => hideFlash(flashEl, fadeTransition)); flashEl.addEventListener('click', () => hideFlash(flashEl, fadeTransition));
...@@ -77,11 +80,6 @@ const createFlash = function createFlash( ...@@ -77,11 +80,6 @@ const createFlash = function createFlash(
} }
} }
if (flashContainer.parentNode.classList.contains('content-wrapper')) {
const flashText = flashEl.querySelector('.flash-text');
flashText.className = `${flashText.className} container-fluid container-limited`;
}
flashContainer.style.display = 'block'; flashContainer.style.display = 'block';
return flashContainer; return flashContainer;
......
...@@ -1213,13 +1213,13 @@ export default class Notes { ...@@ -1213,13 +1213,13 @@ export default class Notes {
} }
addFlash(...flashParams) { addFlash(...flashParams) {
this.flashInstance = new Flash(...flashParams); this.flashContainer = new Flash(...flashParams);
} }
clearFlash() { clearFlash() {
if (this.flashInstance && this.flashInstance.flashContainer) { if (this.flashContainer) {
this.flashInstance.flashContainer.hide(); this.flashContainer.style.display = 'none';
this.flashInstance = null; this.flashContainer = null;
} }
} }
......
...@@ -31,6 +31,17 @@ describe('Flash', () => { ...@@ -31,6 +31,17 @@ describe('Flash', () => {
el.querySelector('.flash-text').textContent.trim(), el.querySelector('.flash-text').textContent.trim(),
).toBe('<script>alert("a");</script>'); ).toBe('<script>alert("a");</script>');
}); });
it('adds container classes when inside content wrapper', () => {
el.innerHTML = createFlashEl('testing', 'alert', true);
expect(
el.querySelector('.flash-text').classList.contains('container-fluid'),
).toBeTruthy();
expect(
el.querySelector('.flash-text').classList.contains('container-limited'),
).toBeTruthy();
});
}); });
describe('hideFlash', () => { describe('hideFlash', () => {
...@@ -57,6 +68,17 @@ describe('Flash', () => { ...@@ -57,6 +68,17 @@ describe('Flash', () => {
).toBe('0'); ).toBe('0');
}); });
it('does not set styles when fadeTransition is false', () => {
hideFlash(el, false);
expect(
el.style.opacity,
).toBe('');
expect(
el.style.transition,
).toBe('');
});
it('removes element after transitionend', () => { it('removes element after transitionend', () => {
document.body.appendChild(el); document.body.appendChild(el);
...@@ -192,7 +214,7 @@ describe('Flash', () => { ...@@ -192,7 +214,7 @@ describe('Flash', () => {
flash('test'); flash('test');
expect( expect(
document.querySelector('.flash-text').className, document.querySelector('.flash-text').className.trim(),
).toBe('flash-text'); ).toBe('flash-text');
}); });
......
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