From 67ab7e1b82b836a115d911fbbef9156984ebf09f Mon Sep 17 00:00:00 2001 From: Chupurnov Valeriy Date: Tue, 6 Feb 2018 20:25:04 +0500 Subject: [PATCH] Fix a lot of bugs with backspace keypressing --- package.json | 2 +- src/modules/Dom.ts | 23 ++- src/plugins/backspace.ts | 295 +++++++++++++++++++++++----- test/tests/dialogTest.js | 11 +- test/tests/enterTest.js | 386 +++++++++++++++++++++++++++++++++---- test/tests/iframeTest.js | 11 +- test/tests/imageTest.js | 19 +- test/tests/mirrorTest.js | 4 - test/tests/mobileTest.js | 6 +- test/tests/pluginsTest.js | 42 ++-- test/tests/tableTest.js | 99 +++++----- test/tests/undoredoTest.js | 11 +- 12 files changed, 703 insertions(+), 206 deletions(-) diff --git a/package.json b/package.json index 2118ab98f..18cbc1e2d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jodit", "version": "3.1.27", "description": "Jodit is awesome and usefully wysiwyg editor with filebrowser", - "main": "index.js", + "main": "build/jodit.min.js", "scripts": { "newversion": "npm test && npm version patch --no-git-tag-version && npm run build && npm run newversiongit && npm publish ./", "newversiongit": "git add --all && git commit -m \"New version %npm_package_version%. Read more https://github.com/xdan/jodit/releases/tag/%npm_package_version% \" && git tag %npm_package_version% && git push --tags origin HEAD:master", diff --git a/src/modules/Dom.ts b/src/modules/Dom.ts index d41ad4c27..699d38a80 100644 --- a/src/modules/Dom.ts +++ b/src/modules/Dom.ts @@ -429,8 +429,8 @@ export class Dom { * @param elm * @param newElement */ - static after(elm: HTMLElement, newElement: HTMLElement|DocumentFragment) { - const parentNode: Node|null = elm.parentNode; + static after(elm: HTMLElement, newElement: HTMLElement | DocumentFragment) { + const parentNode: Node | null = elm.parentNode; if (!parentNode) { return; @@ -443,6 +443,25 @@ export class Dom { } } + /** + * Move all content to another element + * + * @param {Node} from + * @param {Node} to + * @param {boolean} inStart + */ + static moveContent(from: Node, to: Node, inStart: boolean = false) { + const fragment: DocumentFragment = from.ownerDocument.createDocumentFragment(); + [].slice.call(from.childNodes).forEach((node: Node) => { + fragment.appendChild(node); + }); + if (!inStart || !to.firstChild) { + to.appendChild(fragment); + } else { + to.insertBefore(fragment, to.firstChild); + } + } + static all(node: Node, condition: (element: Node) => boolean|void, prev: boolean = false): Node|void { let nodes: Node[] = node.childNodes ? Array.prototype.slice.call(node.childNodes) : []; diff --git a/src/plugins/backspace.ts b/src/plugins/backspace.ts index f9b2da1d1..799903850 100644 --- a/src/plugins/backspace.ts +++ b/src/plugins/backspace.ts @@ -6,7 +6,7 @@ import {Jodit} from '../Jodit'; import * as consts from '../constants'; -import {trim} from '../modules/Helpers'; +import {css, trim} from '../modules/Helpers'; import {Dom} from "../modules/Dom"; /** @@ -28,6 +28,91 @@ export function backspace(editor: Jodit) { } } }); + const removeEmptyBlocks = (container: HTMLElement) => { + let box: HTMLElement | null = container, parent: Node | null; + do { + const html: string = box.innerHTML.replace(consts.INVISIBLE_SPACE_REG_EXP, ''); + + if ((!html.length || html === '
') && !Dom.isCell(box, editor.editorWindow) && box.parentNode && container !== editor.editor) { + parent = box.parentNode; + box.parentNode.removeChild(box); + } else { + break; + } + + box = parent; + } while (box && box !== editor.editor); + }; + const removeChar = (box: {node : Node | null}, toLeft: boolean, range: Range) : void | false => { + if (box.node && box.node.nodeType === Node.TEXT_NODE && typeof box.node.nodeValue === 'string') { + // remove invisible spaces + let startOffset: number = toLeft ? box.node.nodeValue.length : 0; + let startOffsetInRange: number = startOffset; + let value: string = box.node.nodeValue, + increment: number = toLeft ? -1 : 1; + + while (startOffset >= 0 && startOffset <= value.length && value[startOffset + (toLeft ? -1 : 0)] === consts.INVISIBLE_SPACE) { + startOffset += increment; + } + + if (startOffset !== startOffsetInRange) { + if (toLeft) { + value = value.substr(0, startOffset) + value.substr(startOffsetInRange); + } else { + value = value.substr(0, startOffsetInRange) + value.substr(startOffset); + startOffset = startOffsetInRange; + } + + box.node.nodeValue = value; + } + + range.setStart(box.node, startOffset); + range.collapse(true); + + let nextElement: Node | null = toLeft ? box.node.previousSibling : box.node.nextSibling; + + if (value.length) { + if (toLeft) { + if (startOffset) { + box.node.nodeValue = value.substr(0, startOffset - 1) + value.substr(startOffset); + if (!box.node.nodeValue.length) { + box.node.nodeValue = consts.INVISIBLE_SPACE; + } + range.setStart(box.node, startOffset - 1); + range.collapse(true); + return false; + } + } else { + if (startOffset < value.length) { + box.node.nodeValue = value.substr(0, startOffset) + value.substr(startOffset + 1); + if (!box.node.nodeValue.length) { + box.node.nodeValue = consts.INVISIBLE_SPACE; + } + range.setStart(box.node, startOffset); + range.collapse(true); + return false; + } + } + } else { + range.setStartBefore(box.node); + range.collapse(true); + + box.node && box.node.parentNode && box.node.parentNode.removeChild(box.node); + + box.node = nextElement; + } + + if (nextElement) { + if (nextElement.nodeType === Node.ELEMENT_NODE && ['inline', 'inline-block'].indexOf(css(nextElement, 'display').toString()) !== -1) { + nextElement = toLeft ? nextElement.lastChild : nextElement.firstChild; + } + if (nextElement && nextElement.nodeType === Node.TEXT_NODE) { + box.node = nextElement; + return removeChar(box, toLeft, range); + } + } + } + }; editor.events.on('keydown', (event: KeyboardEvent): false | void => { if (event.which === consts.KEY_BACKSPACE || event.keyCode === consts.KEY_DELETE) { @@ -39,75 +124,187 @@ export function backspace(editor: Jodit) { } const sel: Selection = editor.editorWindow.getSelection(), - range: Range|false = sel.rangeCount ? sel.getRangeAt(0) : false; + range: Range | false = sel.rangeCount ? sel.getRangeAt(0) : false; - if (range) { - const textNode: Node = range.startContainer.nodeType === Node.TEXT_NODE ? range.startContainer : range.startContainer.childNodes[range.startOffset]; - const startOffsetInRange: number = range.startContainer.nodeType === Node.TEXT_NODE ? range.startOffset : 0; - let startOffset: number = startOffsetInRange; + if (!range) { + return false; + } + const fakeNode: Node = editor.ownerDocument.createTextNode(consts.INVISIBLE_SPACE); + try { + range.insertNode(fakeNode); - if (!Dom.isOrContains(editor.editor, textNode) || textNode === editor.editor) { - return; - } + let container: HTMLElement | null = Dom.up(fakeNode, Dom.isBlock, editor.editor); - if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue) { - let value: string = textNode.nodeValue, - increment: number = toLeft ? -1 : 1; + let workElement: Node | null; + workElement = toLeft ? fakeNode.previousSibling : fakeNode.nextSibling; - while (startOffset >= 0 && startOffset <= value.length && value[startOffset + increment] === consts.INVISIBLE_SPACE) { - startOffset += increment; + if (workElement) { + const box = {node: workElement}; + if (removeChar(box, toLeft, range) === false) { + return false; } - if (startOffset !== startOffsetInRange) { - if (toLeft) { - value = value.substr(0, startOffset) + value.substr(startOffsetInRange); - } else { - value = value.substr(0, startOffsetInRange) + value.substr(startOffset); - } - textNode.nodeValue = value; - if (value) { - range.setStart(textNode, startOffset); - return; - } + workElement = box.node || fakeNode.parentNode; + + if (workElement === editor.editor) { + return false; } + + if (workElement && workElement.nodeName.match(/^(IMG|BR|IFRAME|SCRIPT|INPUT|TEXTAREA|TABLE|HR)$/)) { + workElement.parentNode && workElement.parentNode.removeChild(workElement); + return false; + } + } + + if (container && container.nodeName.match(/^(TD)$/)) { + return false; } - if (startOffset === 0 && toLeft && textNode) { - const prevBox: Node | false = Dom.prev(textNode, Dom.isBlock, editor.editor); + let prevBox: Node | false | null = toLeft ? Dom.prev(workElement || fakeNode, Dom.isBlock, editor.editor) : Dom.next(workElement || fakeNode, Dom.isBlock, editor.editor); + + if (!prevBox && container && container.parentNode) { + prevBox = editor.editorDocument.createElement(editor.options.enter); + let box: Node = container; - if (prevBox) { - editor.selection.setCursorIn(prevBox, false); + while (box && box.parentNode && box.parentNode !== editor.editor) { + box = box.parentNode; } - try { - const container: HTMLElement | null = Dom.up(range.startContainer, Dom.isBlock, editor.editor); + box.parentNode && box.parentNode.insertBefore(prevBox, box); + } - if (container) { - const html: string = container.innerHTML.replace(consts.INVISIBLE_SPACE_REG_EXP, ''); - if ((!html.length || html == '
') && !Dom.isCell(container, editor.editorWindow) && container.parentNode && container !== editor.editor) { - container.parentNode.removeChild(container); + prevBox && editor.selection.setCursorIn(prevBox, !toLeft); - return false; - } + if (container) { + removeEmptyBlocks(container); + + if (prevBox && container.parentNode) { + if ( + container.nodeName === prevBox.nodeName && + container.parentNode && prevBox.parentNode && + container.parentNode !== editor.editor && prevBox.parentNode !== editor.editor && + container.parentNode !== prevBox.parentNode && + container.parentNode.nodeName === prevBox.parentNode.nodeName + ) { + container = container.parentNode; + prevBox = prevBox.parentNode; } - } finally { - // Ul near with UL - if (prevBox && prevBox.nodeName === 'LI') { - const UL: Node | false = Dom.closest(prevBox, 'Ul|OL', editor.editor); - if (UL) { - const nextBox: Node | null = UL.nextSibling; - if (nextBox && nextBox.nodeName === UL.nodeName) { - [].slice.call(nextBox.childNodes).forEach(function (node: HTMLLIElement) { - UL.appendChild(node); - }); - nextBox.parentNode && nextBox.parentNode.removeChild(nextBox); - } + Dom.moveContent(container, prevBox, !toLeft); + } + + if (prevBox && prevBox.nodeName === 'LI') { + const UL: Node | false = Dom.closest(prevBox, 'Ul|OL', editor.editor); + if (UL) { + const nextBox: Node | null = UL.nextSibling; + if (nextBox && nextBox.nodeName === UL.nodeName && UL !== nextBox) { + Dom.moveContent(nextBox, UL, !toLeft); + nextBox.parentNode && nextBox.parentNode.removeChild(nextBox); } } } + + removeEmptyBlocks(container); + + return false; } + } finally { + fakeNode.parentNode && fakeNode.parentNode.removeChild(fakeNode); } + + + + // let currentNode: Node | null = null, + // startOffset: number = 0; + // + // if (range.startContainer.nodeType === Node.TEXT_NODE) { + // currentNode = range.startContainer; + // startOffset = range.startOffset; + // } else { + // if (toLeft) { + // currentNode = range.startContainer.childNodes[range.startOffset - 1]; + // if (currentNode && currentNode.nodeType === Node.TEXT_NODE && currentNode.nodeValue) { + // startOffset = currentNode.nodeValue.length; + // } + // } else { + // currentNode = range.startContainer.childNodes[range.startOffset]; + // } + // if (!currentNode) { + // + // } + // } + // + // if (currentNode && currentNode.nodeType === Node.TEXT_NODE) { + // if (removeChar(currentNode, startOffset, startOffset, toLeft, range) === false) { + // return false; + // } + // } + + + + // const textNode: Node = range.startContainer.nodeType === Node.TEXT_NODE ? range.startContainer : range.startContainer.childNodes[range.startOffset]; + // const startOffsetInRange: number = range.startContainer.nodeType === Node.TEXT_NODE ? range.startOffset : 0; + // + // let startOffset: number = startOffsetInRange; + // + // if (!Dom.isOrContains(editor.editor, textNode) || textNode === editor.editor) { + // return false; + // } + // + // const nextElement: Node | null | false = removeChar(textNode, startOffset, startOffsetInRange, toLeft, range); + // + // if (nextElement === false) { + // return false; + // } + // + // if (nextElement && nextElement.nodeName.match(/^(IMG|BR|IFRAME|SCRIPT|INPUT|TEXTAREA|TABLE)$/)) { + // nextElement.parentNode && nextElement.parentNode.removeChild(nextElement); + // return false; + // } + + + + // if (startOffset === 0 && toLeft && textNode) { + // const prevBox: Node | false = Dom.prev(textNode, Dom.isBlock, editor.editor); + // + // if (prevBox) { + // editor.selection.setCursorIn(prevBox, false); + // } + // + // try { + // const container: HTMLElement | null = Dom.up(range.startContainer, Dom.isBlock, editor.editor); + // + // if (container) { + // const html: string = container.innerHTML.replace(consts.INVISIBLE_SPACE_REG_EXP, ''); + // if ((!html.length || html === '
') && !Dom.isCell(container, editor.editorWindow) && container.parentNode && container !== editor.editor) { + // container.parentNode.removeChild(container); + // + // return false; + // } + // + // if (container && container.nodeName === 'LI') { + // + // } + // } + // } finally { + // // Ul near with UL + // if (prevBox && prevBox.nodeName === 'LI') { + // const UL: Node | false = Dom.closest(prevBox, 'Ul|OL', editor.editor); + // if (UL) { + // const nextBox: Node | null = UL.nextSibling; + // if (nextBox && nextBox.nodeName === UL.nodeName && UL !== nextBox) { + // [].slice.call(nextBox.childNodes).forEach(function (node: HTMLLIElement) { + // UL.appendChild(node); + // }); + // nextBox.parentNode && nextBox.parentNode.removeChild(nextBox); + // } + // } + // } + // } + // } + + + return false; } }) } \ No newline at end of file diff --git a/test/tests/dialogTest.js b/test/tests/dialogTest.js index 89fe5ed36..1c93981f2 100644 --- a/test/tests/dialogTest.js +++ b/test/tests/dialogTest.js @@ -1,9 +1,8 @@ describe('Dialog system tests', function() { - appendTestArea('dialog_area', true); describe('About dialog', function() { it('Should be opened when use clicks on the About button', function () { getBox().style.width = '100%'; - var editor = new Jodit('#dialog_area', { + var editor = new Jodit(appendTestArea(), { disablePlugins: 'mobile' }); @@ -48,7 +47,7 @@ describe('Dialog system tests', function() { describe('Dialog image', function () { describe('Opened dialog image', function () { it('Should disable margin inputs for left, bottom, right if element has equals margins(margin:10px;)', function () { - var editor = new Jodit('#dialog_area', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 }, @@ -65,7 +64,7 @@ describe('Dialog system tests', function() { expect(dialog.querySelectorAll('input.margins[disabled]').length).to.equal(3); }); it('Should enable margin inputs for left, bottom, right if element has not equals margins(margin:10px 5px;)', function () { - var editor = new Jodit('#dialog_area', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 }, @@ -83,13 +82,11 @@ describe('Dialog system tests', function() { }); }); }); - after(function() { - dialog_area.parentNode.removeChild(dialog_area); - }); afterEach(function () { var i, keys = Object.keys(Jodit.instances); for (i = 0; i < keys.length; i += 1) { Jodit.instances[keys[i]].destruct(); } + removeStuff(); }); }); \ No newline at end of file diff --git a/test/tests/enterTest.js b/test/tests/enterTest.js index 7c1f1ca57..0a56c0914 100644 --- a/test/tests/enterTest.js +++ b/test/tests/enterTest.js @@ -1,55 +1,287 @@ describe('Enter behavior Jodit Editor Tests', function() { - describe('Backspace key', function () { - it('Should return in first

after pressing enter', function () { - var editor = new Jodit(appendTestArea()) + describe('Backspace/Delete key', function () { + describe('inside empty TD', function () { + it('Should doing nothing', function () { + var editor = new Jodit(appendTestArea()) - editor.setEditorValue('test'); + editor.setEditorValue('' + + '' + + '
'); - var range = editor.editorDocument.createRange(); - // set cursor in start of element - range.selectNodeContents(editor.editor.firstChild); - range.collapse(false); - editor.editorWindow.getSelection().removeAllRanges(); - editor.editorWindow.getSelection().addRange(range); + editor.selection.setCursorIn(editor.editor.querySelector('td')); + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + expect('' + + '' + + '
').to.be.equal(editor.getEditorValue()); - simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor); - simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + editor.selection.insertNode(editor.editorDocument.createTextNode(' 2 ')); + + expect('' + + '' + + '
2
').to.be.equal(editor.getEditorValue()); + }); + }); + + describe('inside empty P', function () { + it('Should remove empty tag and set cursor in previous element', function () { + var editor = new Jodit(appendTestArea()) + + editor.setEditorValue('' + + '' + + '


'); + + var range = editor.editorDocument.createRange(); + + + // set cursor in start of element + + range.selectNodeContents(editor.editor.lastChild); + range.collapse(true); + editor.editorWindow.getSelection().removeAllRanges(); + editor.editorWindow.getSelection().addRange(range); - editor.selection.insertNode(editor.editorDocument.createTextNode(' 2 ')); - expect(editor.getEditorValue()).to.be.equal('

test 2

'); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + editor.selection.insertNode(editor.editorDocument.createTextNode(' 2 ')); + + expect(editor.getEditorValue()).to.be.equal('' + + '' + + '
2
'); + }); }); - it('Should remove empty tag and set cursor in previous element', function () { - var editor = new Jodit(appendTestArea()) - editor.setEditorValue('' + - '' + - '


'); + describe('In text node', function () { + describe('Backspace key', function () { + describe('in the middle', function () { + it('Should delete one char before cursor', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('test'); - var range = editor.editorDocument.createRange(); + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + range.setStart(editor.editor.firstChild, 2); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); - // set cursor in start of element + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); - range.selectNodeContents(editor.editor.lastChild); - range.collapse(true); - editor.editorWindow.getSelection().removeAllRanges(); - editor.editorWindow.getSelection().addRange(range); + expect('tst').to.be.equal(editor.getEditorValue()); + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('t a st').to.be.equal(editor.getEditorValue()); + }) + }); + describe('after SPAN', function () { + it('Should move cursor in SPAN and delete one char inside that', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('testopst'); - simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); - editor.selection.insertNode(editor.editorDocument.createTextNode(' 2 ')); + range.setStart(editor.editor.lastChild, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); - expect(editor.getEditorValue()).to.be.equal('' + - '' + - '
2
'); + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('testost').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('testo a st').to.be.equal(editor.getEditorValue()); + }) + }); + describe('in the start of some text node after text node', function () { + it('Should delete one char before cursor in previous text node', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('test'); + + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild, 4); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + var node = editor.ownerDocument.createTextNode('stop'); + editor.selection.insertNode(node, false); + expect('teststop').to.be.equal(editor.getEditorValue()); + + range.setStart(node, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('tesstop').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a '), false) + expect('tes a stop').to.be.equal(editor.getEditorValue()); + }) + }); + }); + describe('Delete key', function () { + describe('in the middle', function () { + it('Should delete one char after cursor', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('test'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild, 2); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + + expect('tet').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a '), false) + expect('te a t').to.be.equal(editor.getEditorValue()); + }) + describe('before SPAN', function () { + it('Should move cursor in SPAN and delete one char inside that', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('testopst'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild, 2); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + + expect('tetopst').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('te a topst').to.be.equal(editor.getEditorValue()); + }) + }); + }); + describe('in the end of some text node before text node', function () { + it('Should delete one char after cursor in next text node', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('test'); + + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild, 4); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + var node = editor.ownerDocument.createTextNode('stop'); + editor.selection.insertNode(node, false); + expect('teststop').to.be.equal(editor.getEditorValue()); + + range.setStart(editor.editor.firstChild, 4); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + + expect('testtop').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a '), false) + expect('test a top').to.be.equal(editor.getEditorValue()); + }) + }); + }); + }); + describe('Cursor after/before element', function () { + describe('Backspace key', function () { + it('Should remove that element', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('

test

'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStartAfter(editor.editor.firstChild.firstChild); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('

test

').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('

a test

').to.be.equal(editor.getEditorValue()); + }); + }); + describe('Delete key', function () { + it('Should remove that element', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('

test

'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStartBefore(editor.editor.querySelector('img')); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + + expect('

test

').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('

test a

').to.be.equal(editor.getEditorValue()); + }); + }); }); describe('Enter backspace in the middle of two UL elements', function () { + describe('In first LI of second UL', function () { + it('Should connect both UL in one element', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('
  • Test
  • Some text
'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.lastChild.firstChild.firstChild, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('
  • Test
  • Some text
').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('
  • Test a
  • Some text
').to.be.equal(editor.getEditorValue()); + }) + }); describe('In the P element', function () { it('Should connect both UL in one element', function () { var editor = new Jodit(appendTestArea()) @@ -65,38 +297,112 @@ describe('Enter behavior Jodit Editor Tests', function() { simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor); - expect(editor.getEditorValue()).to.be.equal('
  • Test

  • Some text
'); + expect('
  • Test

  • Some text
').to.be.equal(editor.getEditorValue()); simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); - expect(editor.getEditorValue()).to.be.equal('
  • Test
  • Some text
'); + expect('
  • Test
  • Some text
').to.be.equal(editor.getEditorValue()); editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) - expect(editor.getEditorValue()).to.be.equal('
  • Test a
  • Some text
'); + expect('
  • Test a
  • Some text
').to.be.equal(editor.getEditorValue()); }) }); - describe('In the empty space', function () { - it('Should connect both UL in one element', function () { + }); + describe('Enter backspace/delete in the start of some LI', function () { + describe('in first LI', function () { + describe('Enter backspace', function () { + it('Should remove this LI and move all conntent in P', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('
  • Test
  • Some text
'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild.firstChild.firstChild, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('

Test

  • Some text
').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('

a Test

  • Some text
').to.be.equal(editor.getEditorValue()); + }); + }); + describe('Enter delete', function () { + it('Should remove all text content and after this remove that LI', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('
  • Test
  • Some text
'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild.firstChild.firstChild, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + expect('
  • est
  • Some text
').to.be.equal(editor.getEditorValue()); + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + expect('
  • st
  • Some text
').to.be.equal(editor.getEditorValue()); + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + expect('
  • t
  • Some text
').to.be.equal(editor.getEditorValue()); + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + expect('
  • Some text
').to.be.equal(editor.getEditorValue()); + simulateEvent('keydown', Jodit.KEY_DELETE, editor.editor); + expect('
  • Some text
').to.be.equal(editor.getEditorValue()); + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect('
  • a Some text
').to.be.equal(editor.getEditorValue()); + }); + }); + }); + describe('in alone LI', function () { + it('Should remove this LI and UL and move all conntent in P', function () { var editor = new Jodit(appendTestArea()) - editor.setEditorValue('
  • Test
  • Some text
'); + editor.setEditorValue('
  • Test
'); var sel = editor.editorWindow.getSelection(), range = editor.editorDocument.createRange(); - range.setStartBefore(editor.editor.childNodes[1]); + range.setStart(editor.editor.firstChild.childNodes[0].firstChild, 0); range.collapse(true); sel.removeAllRanges(); sel.addRange(range); simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); - expect(editor.getEditorValue()).to.be.equal('
  • Test
  • Some text
'); + expect('

Test

').to.be.equal(editor.getEditorValue()); editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) - expect(editor.getEditorValue()).to.be.equal('
  • Test a
  • Some text
'); - }) + expect('

a Test

').to.be.equal(editor.getEditorValue()); + }); + }); + it('Should connect this LI with previous', function () { + var editor = new Jodit(appendTestArea()) + editor.setEditorValue('
  • Test
  • Some text
'); + + var sel = editor.editorWindow.getSelection(), + range = editor.editorDocument.createRange(); + + range.setStart(editor.editor.firstChild.childNodes[1].firstChild, 0); + range.collapse(true); + sel.removeAllRanges(); + sel.addRange(range); + + simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); + + expect('
  • TestSome text
').to.be.equal(editor.getEditorValue()); + + + editor.selection.insertNode(editor.editorDocument.createTextNode(' a ')) + expect(editor.getEditorValue()).to.be.equal('
  • Test a Some text
'); }); }); }); diff --git a/test/tests/iframeTest.js b/test/tests/iframeTest.js index 570bf2db2..01b0ffec5 100644 --- a/test/tests/iframeTest.js +++ b/test/tests/iframeTest.js @@ -1,8 +1,7 @@ describe('Iframe mode', function() { - appendTestArea('iframe_textarea', true); describe('Create editor with iframe node', function () { it('Should create editable area in another document', function() { - var editor = new Jodit('#iframe_textarea', { + var editor = new Jodit(appendTestArea(), { iframe: true, }); @@ -10,7 +9,7 @@ describe('Iframe mode', function() { expect('true').to.be.equal(editor.editorDocument.body.getAttribute('contenteditable')); }); it('Should have same direction and language', function() { - var editor = new Jodit('#iframe_textarea', { + var editor = new Jodit(appendTestArea(), { iframe: true, direction: 'rtl', language: 'de', @@ -21,7 +20,7 @@ describe('Iframe mode', function() { }); describe('And exec command', function () { it('Should use body like editor area', function() { - var editor = new Jodit('#iframe_textarea', { + var editor = new Jodit(appendTestArea(), { iframe: true, }); editor.setEditorValue('test test stop') @@ -37,13 +36,11 @@ describe('Iframe mode', function() { }); }); }); - after(function() { - iframe_textarea.parentNode.removeChild(iframe_textarea); - }); afterEach(function () { var i, keys = Object.keys(Jodit.instances); for (i = 0; i < keys.length; i += 1) { Jodit.instances[keys[i]].destruct(); } + removeStuff(); }); }); \ No newline at end of file diff --git a/test/tests/imageTest.js b/test/tests/imageTest.js index ae6fbccac..af869ec00 100644 --- a/test/tests/imageTest.js +++ b/test/tests/imageTest.js @@ -1,7 +1,6 @@ describe('Test image', function() { - appendTestArea('table_editor_image', true); it('Double click on image should open image properties dialog', function () { - var editor = new Jodit('#table_editor_image'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('') simulateEvent('dblclick', 0, editor.editor.querySelector('img')); @@ -10,7 +9,7 @@ describe('Test image', function() { expect(dialogs.length).to.equal(1); }); it('Double click on image then openOnDblClick=false should select image', function () { - var editor = new Jodit('#table_editor_image', { + var editor = new Jodit(appendTestArea(), { image: { openOnDblClick: false } }); editor.setEditorValue('') @@ -22,26 +21,27 @@ describe('Test image', function() { expect(editor.selection.current().tagName).to.equal('IMG'); }); it('One click on image should show resizer', function () { - var editor = new Jodit('#table_editor_image'); + + var editor = new Jodit(appendTestArea()); editor.setEditorValue('') var img = editor.editor.querySelector('img'); simulateEvent('mousedown', 0, img); - var resizer = document.querySelector('.jodit_resizer[data-editor_id=table_editor_image]'); + var resizer = document.querySelector('.jodit_resizer[data-editor_id=' + editor.id + ']'); expect(resizer.style.display === 'block').to.equal(true); }); it('One click inside table cell should show resizer', function () { - var editor = new Jodit('#table_editor_image'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
1
') var td = editor.editor.querySelector('td'); simulateEvent('mousedown', 0, td); - var resizer = document.querySelector('.jodit_resizer[data-editor_id=table_editor_image]'); + var resizer = document.querySelector('.jodit_resizer[data-editor_id=' + editor.id + ']'); expect(resizer.style.display === 'block').to.equal(true); }); @@ -112,15 +112,12 @@ describe('Test image', function() { }); }); - after(function() { - table_editor_image.parentNode.removeChild(table_editor_image); - }); afterEach(function () { var i, keys = Object.keys(Jodit.instances); for (i = 0; i < keys.length; i += 1) { Jodit.instances[keys[i]].destruct(); } - table_editor_image.value = ''; + removeStuff(); }); }); \ No newline at end of file diff --git a/test/tests/mirrorTest.js b/test/tests/mirrorTest.js index 07396df3d..941d9aa64 100644 --- a/test/tests/mirrorTest.js +++ b/test/tests/mirrorTest.js @@ -1,5 +1,4 @@ describe('CodeMirror editor source code', function() { - appendTestArea('codemirror', true); describe('Init', function() { it('After init container must has codeeditor container', function(done) { var timeout, @@ -32,7 +31,4 @@ describe('CodeMirror editor source code', function() { }); }).timeout(6000); }); - after(function() { - codemirror.parentNode.removeChild(codemirror); - }); }); \ No newline at end of file diff --git a/test/tests/mobileTest.js b/test/tests/mobileTest.js index 42b6c66aa..72885c9c1 100644 --- a/test/tests/mobileTest.js +++ b/test/tests/mobileTest.js @@ -1,11 +1,10 @@ describe('Test mobile mode', function () { - appendTestArea('editor_mobile_test', true); getBox().style.width = 'auto'; describe('Toollbar', function () { it('Should have different count buttons for different container sizes', function () { getBox().style.width = '1000px'; - var editor = new Jodit(editor_mobile_test, { + var editor = new Jodit(appendTestArea(), { buttons: [ 'source', '|', @@ -61,9 +60,6 @@ describe('Test mobile mode', function () { }); }); - after(function() { - editor_mobile_test.parentNode.removeChild(editor_mobile_test); - }); afterEach(function () { removeStuff(); diff --git a/test/tests/pluginsTest.js b/test/tests/pluginsTest.js index 0d976bb1a..d96b656dd 100644 --- a/test/tests/pluginsTest.js +++ b/test/tests/pluginsTest.js @@ -1,10 +1,9 @@ describe('Test plugins', function () { - appendTestArea('editor_plugins_test', true); getBox().style.width = 'auto'; describe('Copy format plugin', function () { it('Should copy fontWeight from element and paste it in new selection', function () { getBox().style.width = 'auto'; - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('text test post'); editor.selection.setCursorIn(editor.editor.querySelector('strong')); expect(editor.container.querySelectorAll('.jodit_toolbar_btn-copyformat').length).to.equal(1); @@ -27,7 +26,7 @@ describe('Test plugins', function () { }); it('Should copy fontSize from element and paste it in new selection', function () { getBox().style.width = 'auto'; - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('text test post'); editor.selection.setCursorIn(editor.editor.querySelector('span')); @@ -51,7 +50,7 @@ describe('Test plugins', function () { }); it('Should copy fontSize and color from element and paste it in new selection', function () { getBox().style.width = 'auto'; - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('text test post'); editor.selection.setCursorIn(editor.editor.querySelector('span')); expect(editor.container.querySelectorAll('.jodit_toolbar_btn-copyformat').length).to.equal(1); @@ -74,7 +73,7 @@ describe('Test plugins', function () { }); it('Should toggle active state after double click', function () { getBox().style.width = 'auto'; - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('text test post'); editor.selection.setCursorIn(editor.editor.querySelector('span')); expect(editor.container.querySelectorAll('.jodit_toolbar_btn-copyformat').length).to.equal(1); @@ -103,7 +102,7 @@ describe('Test plugins', function () { describe('Set cursor inside em[style=background] > strong elements', function () { it('Should copy fontWeight from strong element, copy italic and background style from em and paste it in new selection', function () { getBox().style.width = 'auto'; - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('text test post'); editor.selection.setCursorIn(editor.editor.querySelector('strong')); @@ -135,11 +134,11 @@ describe('Test plugins', function () { }); describe('Add new Line plugin', function () { it('Should add new line element in container', function () { - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); expect(editor.container.querySelectorAll('.jodit-add-new-line').length).to.equal(1); }); it('Should show .jodit-add-new-line after user move mouse under Table,Ifrmae or IMG ', function () { - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + '' + @@ -162,7 +161,7 @@ describe('Test plugins', function () { expect(newline.style.display).to.equal('block'); }); it('Should add new paragraph after user clicked on newline ', function () { - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
1
2
' + '' + '' + @@ -193,7 +192,7 @@ describe('Test plugins', function () { '
2
2
'); }); it('Should add new paragraph after user clicked on newline below table', function () { - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + '' + @@ -221,7 +220,7 @@ describe('Test plugins', function () { '
3
2

'); }); it('Should add new paragraph after user clicked on newline below table in IFRAME mode', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { ifarme: true }); editor.setEditorValue('' + @@ -252,7 +251,7 @@ describe('Test plugins', function () { }); describe('Insert line on top of IMG element that was inside P element', function () { it('Should insert new P before parent P element', function () { - var editor = new Jodit('#editor_plugins_test'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('

'); window.scrollTo(0, 100000000) // elementFromPoint works only with visible part of view @@ -575,7 +574,7 @@ describe('Test plugins', function () { describe('Search plugin', function () { describe('CTRL + F', function () { it('Should show search form and query field must have focus', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -591,7 +590,7 @@ describe('Test plugins', function () { }); describe('CTRL + R', function () { it('Should show search and replace form and query field must have focus', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -608,7 +607,7 @@ describe('Test plugins', function () { }); describe('Press Replace button', function () { it('Should replace value form query field to value from replace field in editor', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -644,7 +643,7 @@ describe('Test plugins', function () { describe('F3 after search', function () { it('Should find a next match', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -691,7 +690,7 @@ describe('Test plugins', function () { }); it('Should find the next match in a circle', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -745,7 +744,7 @@ describe('Test plugins', function () { describe('with SHIFT key', function () { it('Should find a previous match', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -795,7 +794,7 @@ describe('Test plugins', function () { }); describe('Esc in query field', function () { it('Should hide search form and restore selection', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -889,7 +888,7 @@ describe('Test plugins', function () { }); describe('Fire search event', function () { it('Should select some elements which consists query string', function () { - var editor = new Jodit('#editor_plugins_test', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -1433,9 +1432,6 @@ describe('Test plugins', function () { }); }); }); - after(function() { - editor_plugins_test.parentNode.removeChild(editor_plugins_test); - }); afterEach(function () { removeStuff(); var i, keys = Object.keys(Jodit.instances); diff --git a/test/tests/tableTest.js b/test/tests/tableTest.js index faef0f0fa..6505ce4f9 100644 --- a/test/tests/tableTest.js +++ b/test/tests/tableTest.js @@ -2,14 +2,14 @@ describe('Tables Jodit Editor Tests', function() { appendTestArea('table_editor', true); describe('Methods', function() { it('After init container must has one element .jodit_table_resizer', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); expect(editor.editor.querySelector('.jodit_table_resizer')).to.equal(null); editor.selection.insertNode(Jodit.modules.Dom.create('table', '', editor.editorDocument)); editor.selection.insertNode(Jodit.modules.Dom.create('table', '', editor.editorDocument)); expect(editor.container.querySelectorAll('.jodit_table_resizer').length).to.equal(1); }); it('Process wrong tabel', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
' + '' + '' + @@ -25,7 +25,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.container.querySelectorAll('.jodit_table_resizer').length).to.equal(1); }); it('Method getRowsCount should return TR count', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
1
' + [1,2,3,4].map(function () { @@ -40,7 +40,7 @@ describe('Tables Jodit Editor Tests', function() { expect(Jodit.modules.Table.getRowsCount(editor.editor.firstChild)).to.equal(4); }); it('Method getColumnsCount should return maximum of TH or TD in one row in table', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
' + '' + @@ -53,7 +53,7 @@ describe('Tables Jodit Editor Tests', function() { expect(Jodit.modules.Table.getColumnsCount(editor.editor.firstChild)).to.equal(4); }); it('Method appendRow should append one row in the end of table', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
123
' + '' + @@ -64,7 +64,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
123
123
'); }); it('Method appendRow with second argument should append one row after row', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -76,7 +76,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
123
123
234
'); }); it('Method appendRow with second=TR and third=false arguments should append and one row before row', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -89,7 +89,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
123
123
234
'); }); it('Method appendColumn should append column in the end', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -106,7 +106,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Method appendColumn with second argument should append column after that column', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -123,7 +123,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Method appendColumn with second argument and third = false should append column before that column', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -140,7 +140,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove row should delete TR from table', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -161,7 +161,7 @@ describe('Tables Jodit Editor Tests', function() { }); describe('Method merge selected cells', function() { it('Simple should merge all selected cells into one ', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
123
' + '' + @@ -187,7 +187,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('With colspan and rowspan into one ', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
12
' + '' + @@ -217,7 +217,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('A few cells with colspan and rowspan', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
1
' + @@ -261,7 +261,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('Merge cells in center', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -305,7 +305,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('Normalize merged cells', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -336,7 +336,7 @@ describe('Tables Jodit Editor Tests', function() { }) describe('Split selected cells', function() { it('Split cell by Horizontal', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -361,7 +361,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('Split cell with rowspan by horizontal ', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -397,7 +397,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('Split cell with rowspan by horizontal 2', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -433,7 +433,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('Split cell by vertical', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '
' + @@ -460,7 +460,7 @@ describe('Tables Jodit Editor Tests', function() { }); describe('Work with tables', function() { it('Create table and insert into cell some text', function() { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue(''); @@ -480,7 +480,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
ok
'); }); it('After insert table like html without tbody, it should be appear', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -492,7 +492,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
12
'); }); it('After press Tab button cursor should be in next cell in table', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -510,7 +510,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
1test
'); }) it('After press Tab + Shift buttons cursor should be in next cell in table', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -531,7 +531,7 @@ describe('Tables Jodit Editor Tests', function() { }) it('After press Right arrow not in the end of cell it should do nothing', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
' + '' + @@ -549,7 +549,7 @@ describe('Tables Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('
test12
'); }) it('After press Left arrow in the start of cell it should work like tab + shift', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -572,7 +572,7 @@ describe('Tables Jodit Editor Tests', function() { '
'); }) it('After press Top arrow in the first cell\'s line cursor should move into top cell', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -606,7 +606,7 @@ describe('Tables Jodit Editor Tests', function() { '
'); }) it('After press Bottom arrow in the first cell\'s line cursor should move into bottom cell', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -637,7 +637,7 @@ describe('Tables Jodit Editor Tests', function() { '
'); }) it('After press Tab in last table\'s cell in table should add new row and move into first cell form it', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -665,7 +665,7 @@ describe('Tables Jodit Editor Tests', function() { }) describe('Remove row', function () { it('Remove simple row without rowspan should simple remove row', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
' + '' + @@ -682,7 +682,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove row which not consists td, because of in previous row was cell with rowspan should simple remove row and decrement rowspan', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -699,7 +699,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove row which not consists td, because of in previous row was cell with rowspan and colspan should simple remove row and decrement rowspan once time', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -720,7 +720,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove row which consists td with rowspan should simple remove row and decrement rowspan and move that cell into next row', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -737,7 +737,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove row which consists td with rowspan and colspan should simple remove row and decrement rowspan and move that cell into next row', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -757,7 +757,7 @@ describe('Tables Jodit Editor Tests', function() { }); it('Remove row which consists last td with rowspan and colspan should simple remove row and decrement rowspan and move that cell into next row in last position', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
12
' + '' + @@ -779,7 +779,7 @@ describe('Tables Jodit Editor Tests', function() { }); describe('Remove column', function () { it('Remove simple column without colspan should simple remove all cells in column', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
123
' + '' + @@ -799,7 +799,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove column which consists td with colspan should remove all cells in column but that td should decrement colspan', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -819,7 +819,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove column which not consists td with colspan should remove all cells in column but that td should decrement colspan too', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -839,7 +839,7 @@ describe('Tables Jodit Editor Tests', function() { '
12
'); }); it('Remove column part of that td (colspan and rowspan) in another column should remove all cells in column but that td should decrement colspan once time', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('' + '' + @@ -866,7 +866,7 @@ describe('Tables Jodit Editor Tests', function() { }); describe('Select cells', function () { it('When we press mouse button over cell and move mouse to another cell, it should select all cells in bound', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
1234
' + '' + @@ -898,7 +898,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('When we press mouse button over cell in subtable and move mouse to another cell, it should select all cells in bound in that table', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
12
' + '' + @@ -924,7 +924,7 @@ describe('Tables Jodit Editor Tests', function() { expect(sortAtrtibutes(editor.editor.innerHTML)).to.equal('
12
12
3
12
34
56
56
'); }); it('When we press mouse button over cell and move mouse to another cell, it should select all cells in bound even if between be colspan and rowspan', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue( '' + @@ -952,7 +952,7 @@ describe('Tables Jodit Editor Tests', function() { }); describe('Resize column', function () { it('When move mouse over edge of cell jodit should show resizer element', function (done) { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
' + '' + @@ -977,7 +977,7 @@ describe('Tables Jodit Editor Tests', function() { done(); }); it('When move mouse over left edge of cell and press mouse button and move cursor to right in 500 pixels - resizer should be nearby next edge', function (done) { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
12
' + '' + @@ -1007,7 +1007,7 @@ describe('Tables Jodit Editor Tests', function() { done(); }); it('When move mouse over left edge of cell and press mouse button and move cursor to right in 5 pixels - the width of the right column should decrease, the width of the left column should increase', function (done) { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); editor.setEditorValue('
12345
' + '' + @@ -1051,7 +1051,7 @@ describe('Tables Jodit Editor Tests', function() { done(); }); it('When move mouse over right edge of last cell and press mouse button and move cursor to right in 50 pixels - the width of the whole table should increase', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); getBox().style.width = '202px'; @@ -1088,7 +1088,7 @@ describe('Tables Jodit Editor Tests', function() { ); }); it('When move mouse over left edge of first cell and press mouse button and move cursor to left in 50 pixels - the width of the whole table should increase', function () { - var editor = new Jodit('#table_editor'); + var editor = new Jodit(appendTestArea()); getBox().style.width = '202px'; editor.setEditorValue('
1234
' + @@ -1166,13 +1166,12 @@ describe('Tables Jodit Editor Tests', function() { }); }); }); - after(function() { - table_editor.parentNode.removeChild(table_editor); - }); + afterEach(function () { var i, keys = Object.keys(Jodit.instances); for (i = 0; i < keys.length; i += 1) { Jodit.instances[keys[i]].destruct(); } + removeStuff(); }); }); \ No newline at end of file diff --git a/test/tests/undoredoTest.js b/test/tests/undoredoTest.js index 800b82c80..0c9585d96 100644 --- a/test/tests/undoredoTest.js +++ b/test/tests/undoredoTest.js @@ -1,8 +1,7 @@ describe('Undo/Redo behaviors', function() { - appendTestArea('table_editor_undoredo', true); describe('Commands', function () { it('Undo. Enter text wait and again enter text. After execute "undo" command. First text should be returned', function() { - var editor = new Jodit('#table_editor_undoredo', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 // disable delay } @@ -15,7 +14,7 @@ describe('Undo/Redo behaviors', function() { expect(editor.getEditorValue()).to.equal('test'); }); it('Redo. Enter text wait and again enter text. After execute "undo" + "redo" command in editor should be second text', function() { - var editor = new Jodit('#table_editor_undoredo', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -29,7 +28,7 @@ describe('Undo/Redo behaviors', function() { expect(editor.getEditorValue()).to.equal('test2'); }); it('Check react UndoRedo to another changes', function() { - var editor = new Jodit('#table_editor_undoredo', { + var editor = new Jodit(appendTestArea(), { observer: { timeout: 0 } @@ -52,13 +51,11 @@ describe('Undo/Redo behaviors', function() { expect(editor.getEditorValue()).to.equal('testtest2'); }); }); - after(function() { - table_editor_undoredo.parentNode.removeChild(table_editor_undoredo); - }); afterEach(function () { var i, keys = Object.keys(Jodit.instances); for (i = 0; i < keys.length; i += 1) { Jodit.instances[keys[i]].destruct(); } + removeStuff(); }); }); \ No newline at end of file