commit f43f910e58084aed4b1e0ecebc96081f26b6a9a5
parent 1fe47c20e74029f92f28b1443b7d1bb0bcf96268
Author: RachelM <rachieb19@gmail.com>
Date: Thu, 1 Oct 2020 21:32:39 -0400
test almost complete
Diffstat:
4 files changed, 311 insertions(+), 170 deletions(-)
diff --git a/demo/package-lock.json b/demo/package-lock.json
@@ -939,6 +939,15 @@
}
}
},
+ "@striven-erp/striven-editor": {
+ "version": "3.8.3",
+ "resolved": "https://registry.npmjs.org/@striven-erp/striven-editor/-/striven-editor-3.8.3.tgz",
+ "integrity": "sha512-8df5ICMG9wyx9oAePmp+dTmOpgiQjxFFXTe/UH7eXR3JN6YeEjVzf49lMQGs5LXlDQa4im951+I1A8F99i7SRA==",
+ "requires": {
+ "js-beautify": "^1.11.0",
+ "linkifyjs": "^2.1.9"
+ }
+ },
"@types/events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
@@ -1739,6 +1748,11 @@
"integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==",
"dev": true
},
+ "abbrev": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
+ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
+ },
"accepts": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@@ -3055,6 +3069,15 @@
"typedarray": "^0.0.6"
}
},
+ "config-chain": {
+ "version": "1.1.12",
+ "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz",
+ "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==",
+ "requires": {
+ "ini": "^1.3.4",
+ "proto-list": "~1.2.1"
+ }
+ },
"connect-history-api-fallback": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz",
@@ -4097,6 +4120,33 @@
"safer-buffer": "^2.1.0"
}
},
+ "editorconfig": {
+ "version": "0.15.3",
+ "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz",
+ "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==",
+ "requires": {
+ "commander": "^2.19.0",
+ "lru-cache": "^4.1.5",
+ "semver": "^5.6.0",
+ "sigmund": "^1.0.1"
+ },
+ "dependencies": {
+ "lru-cache": {
+ "version": "4.1.5",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
+ "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
+ "requires": {
+ "pseudomap": "^1.0.2",
+ "yallist": "^2.1.2"
+ }
+ },
+ "yallist": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
+ "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI="
+ }
+ }
+ },
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
@@ -6419,6 +6469,11 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
+ "ini": {
+ "version": "1.3.5",
+ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
+ "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
+ },
"inquirer": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz",
@@ -6852,6 +6907,25 @@
}
}
},
+ "js-beautify": {
+ "version": "1.13.0",
+ "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.13.0.tgz",
+ "integrity": "sha512-/Tbp1OVzZjbwzwJQFIlYLm9eWQ+3aYbBXLSaqb1mEJzhcQAfrqMMQYtjb6io+U6KpD0ID4F+Id3/xcjH3l/sqA==",
+ "requires": {
+ "config-chain": "^1.1.12",
+ "editorconfig": "^0.15.3",
+ "glob": "^7.1.3",
+ "mkdirp": "^1.0.4",
+ "nopt": "^5.0.0"
+ },
+ "dependencies": {
+ "mkdirp": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
+ "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
+ }
+ }
+ },
"js-levenshtein": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz",
@@ -7022,6 +7096,11 @@
"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=",
"dev": true
},
+ "linkifyjs": {
+ "version": "2.1.9",
+ "resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-2.1.9.tgz",
+ "integrity": "sha512-74ivurkK6WHvHFozVaGtQWV38FzBwSTGNmJolEgFp7QgR2bl6ArUWlvT4GcHKbPe1z3nWYi+VUdDZk16zDOVug=="
+ },
"loader-fs-cache": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/loader-fs-cache/-/loader-fs-cache-1.0.2.tgz",
@@ -7701,6 +7780,14 @@
"semver": "^5.3.0"
}
},
+ "nopt": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
+ "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==",
+ "requires": {
+ "abbrev": "1"
+ }
+ },
"normalize-package-data": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",
@@ -8888,6 +8975,11 @@
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
"integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM="
},
+ "proto-list": {
+ "version": "1.2.4",
+ "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
+ "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk="
+ },
"proxy-addr": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
@@ -8907,8 +8999,7 @@
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
- "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
- "dev": true
+ "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
},
"psl": {
"version": "1.4.0",
@@ -9544,8 +9635,7 @@
"semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
- "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
- "dev": true
+ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
},
"send": {
"version": "0.17.1",
@@ -9745,6 +9835,11 @@
"integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==",
"dev": true
},
+ "sigmund": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
+ "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA="
+ },
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
diff --git a/demo/package.json b/demo/package.json
@@ -8,6 +8,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
+ "@striven-erp/striven-editor": "^3.8.3",
"core-js": "^2.6.5",
"terser-webpack-plugin": "^2.2.2",
"tributejs": "^3.7.3",
diff --git a/demo/src/test.js b/demo/src/test.js
@@ -1,185 +1,230 @@
const { assert } = chai;
-mocha.setup('bdd');
+mocha.setup("bdd");
function getEditor() {
- const editor = [...document.getElementsByClassName('striven-editor')].pop();
- return editor.StrivenEditor();
+ const editor = [...document.getElementsByClassName("striven-editor")].pop();
+ return editor.StrivenEditor();
}
function node(content) {
- const node = document.createElement('div');
- node.innerHTML = content;
- return node;
+ const node = document.createElement("div");
+ node.innerHTML = content;
+ return node;
}
/* Regression Tests */
-describe('Regression Tests', () => {
-
- it('should not return script elements', () => {
- const se = getEditor();
-
- const content = `
+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>
`;
- 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();
-
- assert.exists(se.body.querySelector('ol'), 'an ordered 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>');
-
- 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.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 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.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();
+
+ assert.exists(
+ se.body.querySelector("ol"),
+ "an ordered 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>");
+
+ 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.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 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();
+ })
+ );
+ });
+ it("should apply strikethrough decoration to content", (done) => {
+ const se = getEditor();
+ se.setContent("<p>Strike Me Through</p>");
+ setTimeout(() => {
+ se.getRange().selectNode(se.body.querySelector("p"));
+ se.toolbar.querySelector("#toolbar-strikethrough").click();
+ assert.exists(
+ se.body.querySelector("p[text-decoration=line-through]"),
+ "strikethrough was applied"
+ );
+
+ se.clearContent();
+ done();
+ }, 200);
+ });
});
/* Internal Tests */
-describe('Internal Tests', () => {
- 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("Internal Tests", () => {
+ 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");
+ });
});
mocha.run();
diff --git a/package-lock.json b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "@striven-erp/striven-editor",
- "version": "3.6.9",
+ "version": "3.8.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {