Fix setting zero width space
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / canvas.test.js
index 5c36f90..10a2376 100644 (file)
@@ -19,6 +19,9 @@ var getCanvasFromXML = function(xml) {
     return canvas.fromXMLDocument(wlxml.WLXMLDocumentFromXML(xml));
 };
 
+var wait = function(callback, timeout) {
+    return window.setTimeout(callback, timeout || 0.5);
+}
 
 describe('new Canvas', function() {
     it('abc', function() {
@@ -29,6 +32,21 @@ describe('new Canvas', function() {
     });
 })
 
+describe('Handling empty text nodes', function() {
+    it('puts zero width space into node with about to be remove text', function(done) {
+        var c = getCanvasFromXML('<section>Alice</section>'),
+            textElement = c.doc().children()[0];
+        textElement.setText('');
+
+        /* Wait for MutationObserver to kick in. */
+        wait(function() {
+            expect(textElement.getText({raw:true})).to.equal(utils.unicode.ZWS, 'ZWS in canvas');
+            expect(c.wlxmlDocument.root.contents()[0].getText()).to.equal('', 'empty string in a document');
+            done();
+        });
+    });
+});
+
 describe('Cursor', function() {
 
     var getSelection;