Fixing list creation
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 10:38:21 +0000 (12:38 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 10:38:21 +0000 (12:38 +0200)
- Array.forEach has no elegant way of breaking from it, so we
use Array.some instead
- checking if iterating over params.element2 was failing on
text elements

modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/canvas.test3.js

index ee0a174..462c305 100644 (file)
@@ -135,7 +135,8 @@ $.extend(Canvas.prototype.list, {
         
         var place = 'before';
         var canvas = this;
         
         var place = 'before';
         var canvas = this;
-        parent.children().forEach(function(element) {
+        parent.children().some(function(element) {
+            var _e = element;
             if(element.sameNode(params.element1))
                 place = 'inside';
             if(place === 'inside') {
             if(element.sameNode(params.element1))
                 place = 'inside';
             if(place === 'inside') {
@@ -147,8 +148,8 @@ $.extend(Canvas.prototype.list, {
                 element.setWlxmlClass('item');
                 elementsToWrap.push(element);
             }
                 element.setWlxmlClass('item');
                 elementsToWrap.push(element);
             }
-            if(element.sameNode(params.element2))
-                return false;
+            if(_e.sameNode(params.element2))
+                return true;
         });
         
         var listElement = documentElement.DocumentNodeElement.create({tag: 'div', klass: 'list-items' + (params.type === 'enum' ? '-enum' : '')});
         });
         
         var listElement = documentElement.DocumentNodeElement.create({tag: 'div', klass: 'list-items' + (params.type === 'enum' ? '-enum' : '')});
index ba14af7..609a36b 100644 (file)
@@ -451,19 +451,24 @@ describe('Canvas', function() {
                         <div>cat</div>\
                     </section>'),
                     section = c.doc(),
                         <div>cat</div>\
                     </section>'),
                     section = c.doc(),
-                    textAlice = section.children()[0],
-                    divCat = section.children()[3]
+                    textHas = section.children()[1],
+                    divA = section.children()[2]
                 
                 
-                c.list.create({element1: textAlice, element2: divCat});
+                c.list.create({element1: textHas, element2: divA});
 
 
-                expect(section.children().length).to.equal(1, 'section has one child element');
+                expect(section.children().length).to.equal(3, 'section has three child elements');
 
 
-                var list = section.children()[0];
-                expect(list.is('list')).to.equal(true, 'section\'s only child is a list');
-                expect(list.children().length).to.equal(4, 'list contains four elements');
+                var child1 = section.children()[0],
+                    list = section.children()[1],
+                    child3 = section.children()[2];
+
+                expect(child1.getText()).to.equal('Alice');
+                expect(list.is('list')).to.equal(true, 'second child is a list');
+                expect(list.children().length).to.equal(2, 'list contains two elements');
                 list.children().forEach(function(child) {
                     expect(child.getWlxmlClass()).to.equal('item', 'list childs have wlxml class of item');
                 });
                 list.children().forEach(function(child) {
                     expect(child.getWlxmlClass()).to.equal('item', 'list childs have wlxml class of item');
                 });
+                expect(child3.children()[0].getText()).to.equal('cat');
             });
 
             describe('extracting list items', function() {
             });
 
             describe('extracting list items', function() {