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 2eec304f3d41f25bc682b015fab2d7e8e423844e
parent 1fe47c20e74029f92f28b1443b7d1bb0bcf96268
Author: Henry Unite <unitehenry@gmail.com>
Date:   Fri,  2 Oct 2020 08:59:45 -0400

Merge pull request #141 from m1ga/tests

link button check
Diffstat:
Mdemo/src/test.js | 52++++++++++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/demo/src/test.js b/demo/src/test.js @@ -4,7 +4,7 @@ mocha.setup('bdd'); function getEditor() { const editor = [...document.getElementsByClassName('striven-editor')].pop(); - return editor.StrivenEditor(); + return editor.StrivenEditor(); } function node(content) { @@ -15,10 +15,10 @@ function node(content) { /* Regression Tests */ describe('Regression Tests', () => { - + it('should not return script elements', () => { const se = getEditor(); - + const content = ` <p>This is some dangerous content!</p> <script>alert('hello');</script> @@ -53,9 +53,9 @@ describe('Regression Tests', () => { 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.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(); @@ -73,7 +73,7 @@ describe('Regression Tests', () => { se.setContent('<p>Change me to 36pt size</p>'); setTimeout(() => { - se.getRange().selectNode(se.body.querySelector('p')); + 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(); @@ -92,7 +92,7 @@ describe('Regression Tests', () => { se.setContent('<p>Change me to an H1 format</p>'); setTimeout(() => { - se.getRange().selectNode(se.body.querySelector('p')); + 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(); @@ -109,7 +109,7 @@ describe('Regression Tests', () => { it('should apply a scroll bar for large content', () => { const se = getEditor(); se.editor.setAttribute('max-height', '300px'); - se.body.style.maxHeight = '300px'; + se.body.style.maxHeight = '300px'; let largeContent = ''; for(let i = 0; i < 1000; i++) { @@ -118,17 +118,17 @@ describe('Regression Tests', () => { se.setContent(largeContent); se.body.blur(); - + assert.notEqual(se.body.scrollHeight, se.body.offsetHeight, 'scroll bar was set'); se.clearContent(); - se.overflow(); + 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.body.style.maxHeight = '300px'; se.toolbar.querySelector('#toolbar-fullscreen').click(); @@ -139,10 +139,10 @@ describe('Regression Tests', () => { 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(); + se.overflow(); }); @@ -153,24 +153,44 @@ describe('Regression Tests', () => { 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(); - + })); }); + 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 */ describe('Internal Tests', () => { it('should of been created', () => { - assert.exists(getEditor().editor, 'Editor is created'); + assert.exists(getEditor().editor, 'Editor is created'); }); it('should have a body', () => {