last = item;
});
- var secondList = documentElement.DocumentNodeElement.create({tag: 'div', klass:'list-items'}, this);
+ if(list.children().length === 0)
+ list.detach();
- last.after(secondList);
+ if(succeedingItems.length > 0) {
+ var secondList = documentElement.DocumentNodeElement.create({tag: 'div', klass:'list-items'}, this);
+ last.after(secondList);
- succeedingItems.forEach(function(item) {
- secondList.append(item);
- });
+ succeedingItems.forEach(function(item) {
+ secondList.append(item);
+ });
+ }
}
});
expect(list2.children().length).to.equal(1, 'second list has one child');
expect(list2.children()[0].children()[0].getText()).to.equal('3', 'first item of the second list is a last item of the original list');
});
+
+ it('removes list if all its items are extracted', function() {
+ var c = canvas.fromXML('\
+ <section>\
+ <div class="list.items">\
+ <div class="item">some item</div>\
+ </div>\
+ </section>'),
+ list = c.doc().children()[0],
+ item = list.children()[0];
+
+ c.list.extractItems({element1: item, element2: item});
+
+ var section = c.doc(),
+ list1 = section.children()[0],
+ oldItem1 = section.children()[1],
+ oldItem2 = section.children()[2],
+ list2 = section.children()[3];
+
+ expect(section.children().length).to.equal(1, 'section contains one child');
+ });
});
});