striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 7d24bdced719ed831484d3b2d76b3e339faf2b08
parent a281141249e97d4c31b431499268b944d5bce8be
Author: Henry Unite <unitehenry@gmail.com>
Date:   Fri,  2 Oct 2020 11:02:51 -0400

denormalize camel test

Diffstat:
Ademo/.eslintignore | 1+
Mdemo/src/test.js | 331++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
2 files changed, 187 insertions(+), 145 deletions(-)

diff --git a/demo/.eslintignore b/demo/.eslintignore @@ -0,0 +1 @@ +*.js diff --git a/demo/src/test.js b/demo/src/test.js @@ -1,3 +1,4 @@ +import { denormalizeCamel } from '../../src/utils'; const { assert } = chai; mocha.setup('bdd'); @@ -15,176 +16,203 @@ function node(content) { /* Regression Tests */ describe('Regression Tests', () => { + it('should not return script elements', () => { + const se = getEditor(); - it('should not return script elements', () => { - const se = getEditor(); - - const content = ` + const content = ` <p>This is some dangerous content!</p> <script>alert('hello');</script> `; - se.setContent(content); - const script = node(se.getContent()).querySelector('script'); - - assert.notExists(script, 'script tags were pruned'); - se.clearContent(); - - }); - - it('should create an ordered list with no content', () => { - const se = getEditor(); - se.toolbar.querySelector('#toolbar-insertOrderedList').click(); + se.setContent(content); + const script = node(se.getContent()).querySelector('script'); - assert.exists(se.body.querySelector('ol'), 'an ordered list was created'); - se.clearContent(); + assert.notExists(script, 'script tags were pruned'); + se.clearContent(); + }); - }); + it('should create an ordered list with no content', () => { + const se = getEditor(); + se.toolbar.querySelector('#toolbar-insertOrderedList').click(); - it('should create an unordered list with no content', () => { - const se = getEditor(); - se.toolbar.querySelector('#toolbar-insertUnorderedList').click(); + assert.exists(se.body.querySelector('ol'), 'an ordered list was created'); + se.clearContent(); + }); - assert.exists(se.body.querySelector('ul'), 'an unordered list was created'); - se.clearContent(); + it('should create an unordered list with no content', () => { + const se = getEditor(); + se.toolbar.querySelector('#toolbar-insertUnorderedList').click(); - }); + assert.exists(se.body.querySelector('ul'), 'an unordered list was created'); + se.clearContent(); + }); - it('should apply font style to content', (done) => { - const se = getEditor(); - se.setContent('<p>Change me to Verdana</p>'); + it('should apply font style to content', done => { + const se = getEditor(); + se.setContent('<p>Change me to Verdana</p>'); - setTimeout(() => { - se.getRange().selectNode(se.body.querySelector('p')); - se.toolbar.querySelector('#toolbar-fontName').click(); - se.editor.querySelector('.se-toolbar-popup-option[style="font-family: Verdana;"]').click(); - se.body.onfocus(); - setTimeout(() => { - assert.exists(se.body.querySelector('p font[face="Verdana"]'), 'selected font style was applied'); - se.clearContent(); - done(); - }, 0); - }, 200); - - }); - - it('should apply font size to content', (done) => { - const se = getEditor(); - se.setContent('<p>Change me to 36pt size</p>'); - - setTimeout(() => { - se.getRange().selectNode(se.body.querySelector('p')); - se.toolbar.querySelector('#toolbar-fontSize').click(); - const option = [...se.editor.querySelectorAll('.se-toolbar-popup-option')].filter(opt => (opt.textContent === '36pt')).pop(); - option.click(); - se.body.onfocus(); setTimeout(() => { - assert.exists(se.body.querySelector('font[size="7"]'), 'selected font size was applied'); - se.clearContent(); - done(); - }, 0); - }, 200); - - }); - - it('should apply font format to content', (done) => { - const se = getEditor(); - se.setContent('<p>Change me to an H1 format</p>'); - - setTimeout(() => { - se.getRange().selectNode(se.body.querySelector('p')); - se.toolbar.querySelector('#toolbar-fontFormat').click(); - const option = [...se.editor.querySelectorAll('.se-toolbar-popup-option')].filter(opt => (opt.textContent === 'Heading 1')).pop(); - option.click(); - se.body.onfocus(); - setTimeout(() => { - assert.exists(se.body.querySelector('h1'), 'selected font format was applied'); - se.clearContent(); - done(); - }, 0); - }, 200); - - }); - - it('should apply a scroll bar for large content', () => { - const se = getEditor(); - se.editor.setAttribute('max-height', '300px'); - se.body.style.maxHeight = '300px'; - - let largeContent = ''; - for(let i = 0; i < 1000; i++) { - largeContent += `<p>line ${i}</p>`; - } - - se.setContent(largeContent); - se.body.blur(); - - assert.notEqual(se.body.scrollHeight, se.body.offsetHeight, 'scroll bar was set'); - se.clearContent(); - se.overflow(); - - }); - - it('should apply a scroll bar for large content after collapsing fullscreen', () => { - const se = getEditor(); - se.editor.setAttribute('max-height', '300px'); - se.body.style.maxHeight = '300px'; - - se.toolbar.querySelector('#toolbar-fullscreen').click(); - - let largeContent = ''; - for(let i = 0; i < 1000; i++) { - largeContent += `<p>line ${i}</p>`; - } + se.getRange().selectNode(se.body.querySelector('p')); + se.toolbar.querySelector('#toolbar-fontName').click(); + se.editor + .querySelector( + '.se-toolbar-popup-option[style="font-family: Verdana;"]' + ) + .click(); + se.body.onfocus(); + setTimeout(() => { + assert.exists( + se.body.querySelector('p font[face="Verdana"]'), + 'selected font style was applied' + ); + se.clearContent(); + done(); + }, 0); + }, 200); + }); - se.setContent(largeContent); - se.toolbar.querySelector('#toolbar-fullscreen').click(); + it('should apply font size to content', done => { + const se = getEditor(); + se.setContent('<p>Change me to 36pt size</p>'); - assert.notEqual(se.body.scrollHeight, se.body.offsetHeight, 'scroll bar was set'); - se.clearContent(); - se.overflow(); + setTimeout(() => { + se.getRange().selectNode(se.body.querySelector('p')); + se.toolbar.querySelector('#toolbar-fontSize').click(); + const option = [...se.editor.querySelectorAll('.se-toolbar-popup-option')] + .filter(opt => opt.textContent === '36pt') + .pop(); + option.click(); + se.body.onfocus(); + setTimeout(() => { + assert.exists( + se.body.querySelector('font[size="7"]'), + 'selected font size was applied' + ); + se.clearContent(); + done(); + }, 0); + }, 200); + }); - }); + it('should apply font format to content', done => { + const se = getEditor(); + se.setContent('<p>Change me to an H1 format</p>'); - it('should attach a file', (done) => { + setTimeout(() => { + se.getRange().selectNode(se.body.querySelector('p')); + se.toolbar.querySelector('#toolbar-fontFormat').click(); + const option = [...se.editor.querySelectorAll('.se-toolbar-popup-option')] + .filter(opt => opt.textContent === 'Heading 1') + .pop(); + option.click(); + se.body.onfocus(); + setTimeout(() => { + assert.exists( + se.body.querySelector('h1'), + 'selected font format was applied' + ); + se.clearContent(); + done(); + }, 0); + }, 200); + }); - const se = getEditor(); + it('should apply a scroll bar for large content', () => { + const se = getEditor(); + se.editor.setAttribute('max-height', '300px'); + se.body.style.maxHeight = '300px'; + + let largeContent = ''; + for (let i = 0; i < 1000; i++) { + largeContent += `<p>line ${i}</p>`; + } + + se.setContent(largeContent); + se.body.blur(); + + assert.notEqual( + se.body.scrollHeight, + se.body.offsetHeight, + 'scroll bar was set' + ); + se.clearContent(); + se.overflow(); + }); - fetch('https://raw.githubusercontent.com/striven-erp/striven-editor/master/LICENSE.txt') - .then(res => res.body.getReader().read().then(d => { - se.attachFile(new File([new Blob(d.value)], 'LICENSE.txt')); + it('should apply a scroll bar for large content after collapsing fullscreen', () => { + const se = getEditor(); + se.editor.setAttribute('max-height', '300px'); + se.body.style.maxHeight = '300px'; - const isAttached = se.getFiles().pop() instanceof File; - const elCreated = se.filesSection.querySelector('.se-file .se-file-name').textContent === 'LICENSE.txt'; + se.toolbar.querySelector('#toolbar-fullscreen').click(); - assert.isTrue(isAttached && elCreated, 'file was attached'); - se.clearFiles(); - done(); + let largeContent = ''; + for (let i = 0; i < 1000; i++) { + largeContent += `<p>line ${i}</p>`; + } - })); + se.setContent(largeContent); + se.toolbar.querySelector('#toolbar-fullscreen').click(); - }); + assert.notEqual( + se.body.scrollHeight, + se.body.offsetHeight, + 'scroll bar was set' + ); + se.clearContent(); + se.overflow(); + }); - it('should open/close link menu', (done) => { - const se = getEditor(); - var wasVisible = false; - se.openLinkMenu(); - assert.exists(document.querySelector('#link-menu'), 'menu is there'); + it('should attach a file', done => { + const se = getEditor(); + + fetch( + 'https://raw.githubusercontent.com/striven-erp/striven-editor/master/LICENSE.txt' + ).then(res => + res.body + .getReader() + .read() + .then(d => { + se.attachFile(new File([new Blob(d.value)], 'LICENSE.txt')); + + const isAttached = se.getFiles().pop() instanceof File; + const elCreated = + se.filesSection.querySelector('.se-file .se-file-name') + .textContent === 'LICENSE.txt'; + + assert.isTrue(isAttached && elCreated, 'file was attached'); + se.clearFiles(); + done(); + }) + ); + }); - se.openLinkMenu() - setTimeout(function() { - if (window.getComputedStyle(document.getElementById("link-menu")).visibility == "visible") { - wasVisible = true; - se.closeLinkMenu(); - setTimeout(function() { - if (window.getComputedStyle(document.getElementById("link-menu")).visibility == "hidden") { - assert.isTrue(wasVisible) - done(); - } - }, 500); - } - }, 250); - }); + it('should open/close link menu', done => { + const se = getEditor(); + var wasVisible = false; + se.openLinkMenu(); + assert.exists(document.querySelector('#link-menu'), 'menu is there'); + + se.openLinkMenu(); + setTimeout(function() { + if ( + window.getComputedStyle(document.getElementById('link-menu')) + .visibility == 'visible' + ) { + wasVisible = true; + se.closeLinkMenu(); + setTimeout(function() { + if ( + window.getComputedStyle(document.getElementById('link-menu')) + .visibility == 'hidden' + ) { + assert.isTrue(wasVisible); + done(); + } + }, 500); + } + }, 250); + }); }); /* Internal Tests */ @@ -202,4 +230,17 @@ describe('Internal Tests', () => { }); }); +describe('Unit Tests', () => { + it('should denormalize camel case strings', () => { + assert.equal(denormalizeCamel('helloWorld'), 'Hello World'); + assert.equal(denormalizeCamel('aVariable'), 'A Variable'); + assert.equal( + denormalizeCamel('aVeryVeryVeryVeryVeryLongVariable'), + 'A Very Very Very Very Very Long Variable' + ); + assert.equal(denormalizeCamel('nocase'), 'Nocase'); + assert.equal(denormalizeCamel('has_Underscore'), 'Has_ Underscore'); + }); +}); + mocha.run();