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 e24010c0a03326418d8639403fba5225e8134748
parent 7c19fbe490c3db3bff1dadcf9a3bb2ca1c982ab7
Author: Henry Unite <unitehenry@gmail.com>
Date:   Mon,  7 Sep 2020 16:37:42 -0400

unit testing started

Diffstat:
Mdemo/public/index.html | 12+++++++++---
Mdemo/src/App.vue | 3++-
Ademo/src/test.js | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/demo/public/index.html b/demo/public/index.html @@ -6,6 +6,7 @@ <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="icon" href="<%= BASE_URL %>favicon.png"> + <link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" /> <title>Striven Editor</title> </head> @@ -14,7 +15,9 @@ <strong>We're sorry but demo doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> </noscript> - <div id="app"></div> + <div id="mocha"> + <div id="app"></div> + </div> <a href="https://github.com/striven-erp/striven-editor" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"> @@ -60,6 +63,10 @@ } </style> <!-- built files will be auto injected --> + <style> ul#mocha-stats { margin-right: 10vw; } </style> + + <script src="https://unpkg.com/chai/chai.js"></script> + <script src="https://unpkg.com/mocha/mocha.js"></script> </body> -</html> -\ No newline at end of file +</html> diff --git a/demo/src/App.vue b/demo/src/App.vue @@ -21,7 +21,7 @@ <!-- <button @click="chromeOut">isChrome</button> --> <!-- <button @click="insertList">insertUnorderedList</button> --> - <div v-html="content"></div> + <!-- <div v-html="content"></div> --> <!-- <div ref="customButton" style="display: flex; align-items: flex-end;"> --> <!-- <div class="custom-button" @click="sendContent">Send</div> --> <!-- </div> --> @@ -30,6 +30,7 @@ <script> /* eslint-disable */ +import './test'; import { VueStrivenEditor as StrivenEditor } from "@striven-erp/striven-editor"; export default { diff --git a/demo/src/test.js b/demo/src/test.js @@ -0,0 +1,67 @@ +const { assert } = chai; + +mocha.setup('bdd'); + +function getEditor() { + const editor = [...document.getElementsByClassName('striven-editor')].pop(); + return editor.StrivenEditor(); +} + +function node(content) { + const node = document.createElement('div'); + node.innerHTML = content; + return node; +} + +describe('Editor Initilization', () => { + it('should of been created', () => { + assert.exists(getEditor().editor, 'Editor is created'); + }); + + it('should have a body', () => { + assert.exists(getEditor().body, 'Editor contains a body'); + }); + + it('should have a toolbar', () => { + assert.exists(getEditor().toolbar, 'Editor contains a body'); + }); +}); + +describe('Quality Assurance', () => { + it('should insert a link that will open in a new window', () => { + const se = getEditor(); + const { editor, body } = se; + body.focus(); + + const menu = editor.querySelector('#link-menu'); + + const url = menu.querySelector('input'); + url.value = 'https://striven.com/'; + + menu.querySelector('button').click(); + const link = body.querySelector('a[target="_blank"]'); + + assert.exists(link, 'will open in new window'); + se.clearContent(); + + }); + + it('should not return script elements', () => { + const se = getEditor(); + + 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(); + + }); + +}) + +mocha.run();