Refactoring
[fnpeditor.git] / modules / documentCanvas / tests / canvas.test.js
index 0589c11..12fb8a5 100644 (file)
@@ -61,6 +61,22 @@ define([
             assertDomEqual(c.getContent(), '<div wlxml-tag="section"><div wlxml-tag="header">H<span wlxml-tag="aside">eader</span> 1</div></div>');\r
         });\r
         \r
+        test('wrap text in node - text not a first node', function() {\r
+            var c = canvas.create('<div wlxml-tag="header">Alice <span wlxml-tag="span">has a</span> cat</div>');\r
+            var header = c.findNodes({tag: 'header'})[0];\r
+            var wrapper = canvasNode.create({tag: 'aside'});\r
+            c.nodeWrap({inside: header, _with: wrapper, offsetStart: 1, offsetEnd: 4, textNodeIdx: 2});\r
+            assertDomEqual(c.getContent(), '<div wlxml-tag="header">Alice <span wlxml-tag="span">has a</span> <span wlxml-tag="aside">cat</span></div>');\r
+        });\r
+        \r
+        test('wrap text with nodes inside', function() {\r
+            var c = canvas.create('<div wlxml-tag="header">Alice has a <span wlxml-tag="span">small</span> cat</div>');\r
+            var header = c.findNodes({tag: 'header'})[0];\r
+            var wrapper = canvasNode.create({tag: 'aside'});\r
+            c.nodeWrap({inside: header, _with: wrapper, offsetStart: 6, offsetEnd: 4, textNodeIdx: [0,2]})\r
+            assertDomEqual(c.getContent(), '<div wlxml-tag="header">Alice <span wlxml-tag="aside">has a <span wlxml-tag="span">small</span> cat</span></div>');            \r
+        });\r
+        \r
         test('split node', function() {\r
             var c = canvas.create('<div wlxml-tag="section"><div wlxml-tag="header">Header 1</div></div>');\r
             var header = c.findNodes({tag: 'header'})[0];\r
@@ -174,5 +190,76 @@ define([
                     <div wlxml-tag="div">cat</div>\\r
                 </div>'));\r
         });\r
+        \r
+        test('checking if node is inside a list', function() {\r
+            var c = canvas.create(utils.cleanUp('\\r
+                <div wlxml-tag="section">\\r
+                    <div wlxml-tag="div" wlxml-class="list-items-enum">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice <span wlxml-tag="span"></span</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                    </div>\\r
+                </div>'));\r
+            assert.ok(c.nodeInsideList({node: c.findNodes({klass: 'item'})[1]}), 'item is inside a list');\r
+            assert.ok(c.nodeInsideList({node: c.findNodes({tag: 'span'})[0]}), 'things nested in item are inside a list');\r
+        });\r
+        \r
+        test('moving items to nested list', function() {\r
+            var listHTML = utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>');\r
+            var c = canvas.create(listHTML);\r
+            var items = c.findNodes({klass: 'item'});\r
+            var cat_item = items[1];\r
+            var dog_item = items[2];\r
+            \r
+            c.listCreate({start: cat_item, end: dog_item});\r
+            \r
+            assertDomEqual(c.getContent(), utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item" class="canvas-silent-item">\\r
+                            <div wlxml-tag="div" wlxml-class="list-items">\\r
+                                <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                                <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                            </div>\\r
+                        </div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>'\r
+            ));\r
+        });\r
+        \r
+        test('removing nested list', function() {\r
+            var nestedList = utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">\\r
+                            <div wlxml-tag="div" wlxml-class="list-items">\\r
+                                <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                                <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                            </div>\\r
+                        </div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>');\r
+                    \r
+            var c = canvas.create(nestedList);\r
+            var dog_item = c.findNodes('[wlxml-class=list-items] [wlxml-class=list-items] > div')[1];\r
+            assert.equal(dog_item.getContent(), 'dog');\r
+            \r
+            c.listRemove({pointer: dog_item});\r
+            \r
+            assertDomEqual(c.getContent(), utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>'));\r
+            \r
+            \r
+        });\r
     });\r
 });
\ No newline at end of file