bringing back wrapping text with nodes
[fnpeditor.git] / modules / documentCanvas / tests / canvas.test.js
index a948787..35f0d85 100644 (file)
@@ -54,6 +54,20 @@ define([
             assert.equal(header.tag, 'header');\r
             assert.equal(header.klass, 'some-class');\r
         });\r
             assert.equal(header.tag, 'header');\r
             assert.equal(header.klass, 'some-class');\r
         });\r
+        \r
+        test('getting previous node', function() {\r
+            var c = new canvas.Canvas('<section><div class="some.class">Div 1</div><div class="some.other.class">Div 2</div></section>');\r
+            var secondDiv = c.getNode({tag: 'div'})[1];\r
+            var firstDiv = c.getPreviousNode({node: secondDiv});\r
+            assert.equal(firstDiv.klass, 'some-class');\r
+        })\r
+        \r
+        test('pervious node of node without "previous siblings" is its parent', function() {\r
+            var c = new canvas.Canvas('<section><div class="some.class">Div 1</div></section>');\r
+            var div = c.getNode({tag: 'div'})[0];\r
+            var section = c.getPreviousNode({node: div});\r
+            assert.equal(section.tag, 'section');\r
+        })\r
     \r
         test('inserting after', function() {\r
             var c = new canvas.Canvas('<section><header>Header 1</header></section>');\r
     \r
         test('inserting after', function() {\r
             var c = new canvas.Canvas('<section><header>Header 1</header></section>');\r
@@ -93,8 +107,19 @@ define([
             );\r
         });\r
         \r
             );\r
         });\r
         \r
-        test('list', function() {\r
-            var c = new canvas.Canvas('<section><div>Alice</div>has<div>a cat</div></section>');\r
+        test('remove node', function() {\r
+            var c = new canvas.Canvas('<section><header class="some.class">Fancy and nice <span>header</span> 1</header></section>');\r
+            var span = c.getNode({tag: 'span'})[0];\r
+            var siblings = c.removeNode({node:span});\r
+            assert.xmlEqual(c.toXML(), '\\r
+                <section>\\r
+                    <header class="some.class">Fancy and nice  1</header>\\r
+                </section>'\r
+            );\r
+        });\r
+        \r
+        test('create list from existing nodes', function() {\r
+            var c = new canvas.Canvas('<section><div>Alice</div>has<div>a cat</div><div>some text</div></section>');\r
             var div1 = c.getNode({tag:'div'})[0];\r
             var div2 = c.getNode({tag:'div'})[1];\r
             \r
             var div1 = c.getNode({tag:'div'})[0];\r
             var div2 = c.getNode({tag:'div'})[1];\r
             \r
@@ -102,13 +127,36 @@ define([
             \r
             assert.xmlEqual(c.toXML(), '\\r
                 <section>\\r
             \r
             assert.xmlEqual(c.toXML(), '\\r
                 <section>\\r
-                    <div class="list">\\r
-                        <div class="list.item">Alice</div>\\r
-                        <div class="list.item">has</div>\\r
-                        <div class="list.item">a cat</div>\\r
+                    <div class="list.items">\\r
+                        <div class="item">Alice</div>\\r
+                        <div class="item">has</div>\\r
+                        <div class="item">a cat</div>\\r
                     </div>\\r
                     </div>\\r
+                    <div>some text</div>\\r
+                </section>');\r
+\r
+        });\r
+        \r
+        test('remove list', function() {\r
+            var xml = '\\r
+                <section>\\r
+                    <div class="list.items">\\r
+                        <div class="item">Alice</div>\\r
+                        <div class="item">has</div>\\r
+                        <div class="item">a cat</div>\\r
+                    </div>\\r
+                    <div>some text</div>\\r
+                </section>';\r
+           var c = new canvas.Canvas(xml);\r
+           var item = c.getNode({klass: 'item'})[1];\r
+           c.removeList({pointer: item});\r
+           assert.xmlEqual(c.toXML(), '\\r
+                <section>\\r
+                    <div>Alice</div>\\r
+                    <div>has</div>\\r
+                    <div>a cat</div>\\r
+                    <div>some text</div>\\r
                 </section>');\r
                 </section>');\r
-            \r
         });\r
     });\r
 \r
         });\r
     });\r
 \r