smartxml: fix
[fnpeditor.git] / src / wlxml / extensions / list / list.test.js
index 1efa795..2d47778 100644 (file)
@@ -2,18 +2,24 @@ define(function(require) {
     
 'use strict';
 
     
 'use strict';
 
+/* jshint multistr:true */
+/* globals describe, it */
+
 var chai = require('libs/chai'),
     wlxml = require('wlxml/wlxml'),
     expect = chai.expect,
     $ = require('libs/jquery'),
 var chai = require('libs/chai'),
     wlxml = require('wlxml/wlxml'),
     expect = chai.expect,
     $ = require('libs/jquery'),
-    lists = require('wlxml/extensions/list/list');
+    listsExtension = require('wlxml/extensions/list/list');
 
 
 var getDocumentFromXML = function(xml, options) {
 
 
 var getDocumentFromXML = function(xml, options) {
-    return wlxml.WLXMLDocumentFromXML(xml, options || {});
+    var doc = wlxml.WLXMLDocumentFromXML(xml, options || {});
+    doc.registerExtension(listsExtension);
+    return doc;
 };
 
 var removeEmptyTextNodes = function(xml) {
 };
 
 var removeEmptyTextNodes = function(xml) {
+    /* globals Node */
     xml = $($.trim(xml));
     xml.find(':not(iframe)')
         .addBack()
     xml = $($.trim(xml));
     xml.find(':not(iframe)')
         .addBack()
@@ -37,7 +43,7 @@ describe('Lists extension', function() {
                 div1 = section.contents()[1],
                 textA = section.contents()[2];
             
                 div1 = section.contents()[1],
                 textA = section.contents()[2];
             
-            doc.transform('createList', {node1: div1, node2: textA});
+            doc.createList({node1: div1, node2: textA});
 
             expect(section.contents().length).to.equal(3, 'section has three child nodes');
 
 
             expect(section.contents().length).to.equal(3, 'section has three child nodes');
 
@@ -54,6 +60,15 @@ describe('Lists extension', function() {
             expect(child3.contents()[0].getText()).to.equal('cat');
         });
 
             expect(child3.contents()[0].getText()).to.equal('cat');
         });
 
+        it('Handles text nodes on the boundries', function() {
+            var doc = getDocumentFromXML('<section>Alice<span>has</span>a cat</section>'),
+                textNode1 = doc.root.contents()[0],
+                textNode2 = doc.root.contents()[2];
+            doc.createList({node1: textNode1, node2: textNode2});
+            expect(doc.root.contents().length).to.equal(1);
+            expect(doc.root.contents()[0].is('list')).to.equal(true);
+        });
+
         it('allows creating nested list from existing sibling list items', function() {
             var doc = getDocumentFromXML('\
                 <section>\
         it('allows creating nested list from existing sibling list items', function() {
             var doc = getDocumentFromXML('\
                 <section>\
@@ -70,7 +85,7 @@ describe('Lists extension', function() {
                 itemC = outerList.contents('.item')[2];
 
             
                 itemC = outerList.contents('.item')[2];
 
             
-            doc.transform('createList', {node1: itemB, node2: itemC});
+            doc.createList({node1: itemB, node2: itemC});
 
             var outerListItems = outerList.contents('.item'),
                 innerList = outerListItems[1].contents()[0];
 
             var outerListItems = outerList.contents('.item'),
                 innerList = outerListItems[1].contents()[0];
@@ -106,7 +121,7 @@ describe('Lists extension', function() {
                 item1 = list.contents()[1],
                 item2 = list.contents()[2];
 
                 item1 = list.contents()[1],
                 item2 = list.contents()[2];
 
-            doc.transform('extractItems', {item1: item1, item2: item2});
+            doc.extractItems({item1: item1, item2: item2});
 
             var section = doc.root,
                 list1 = section.contents()[0],
 
             var section = doc.root,
                 list1 = section.contents()[0],
@@ -142,10 +157,9 @@ describe('Lists extension', function() {
                 </section>')),
                 list = doc.root.contents()[0],
                 item1 = list.contents()[0],
                 </section>')),
                 list = doc.root.contents()[0],
                 item1 = list.contents()[0],
-                item2 = list.contents()[1],
-                item3 = list.contents()[2];
+                item2 = list.contents()[1];
 
 
-            doc.transform('extractItems', {item1: item1, item2: item2});
+            doc.extractItems({item1: item1, item2: item2});
 
             var section = doc.root,
                 oldItem1 = section.contents()[0],
 
             var section = doc.root,
                 oldItem1 = section.contents()[0],
@@ -169,11 +183,10 @@ describe('Lists extension', function() {
                     </div>\
                 </section>')),
                 list = doc.root.contents()[0],
                     </div>\
                 </section>')),
                 list = doc.root.contents()[0],
-                item1 = list.contents()[0],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2];
 
                 item2 = list.contents()[1],
                 item3 = list.contents()[2];
 
-            doc.transform('extractItems', {item1: item2, item2: item3});
+            doc.extractItems({item1: item2, item2: item3});
 
             var section = doc.root,
                 oldItem1 = section.contents()[1],
 
             var section = doc.root,
                 oldItem1 = section.contents()[1],
@@ -199,7 +212,7 @@ describe('Lists extension', function() {
                 item1 = list.contents()[0],
                 item2 = list.contents()[1];
 
                 item1 = list.contents()[0],
                 item2 = list.contents()[1];
 
-            doc.transform('extractItems', {item1: item1, item2: item2});
+            doc.extractItems({item1: item1, item2: item2});
 
             var section = doc.root,
                 oldItem1 = section.contents()[0],
 
             var section = doc.root,
                 oldItem1 = section.contents()[0],
@@ -229,11 +242,10 @@ describe('Lists extension', function() {
                 nestedList = list.contents()[1].contents()[0],
                 nestedListItem = nestedList.contents()[1];
 
                 nestedList = list.contents()[1].contents()[0],
                 nestedListItem = nestedList.contents()[1];
 
-            doc.transform('extractItems', {item1: nestedListItem, item2: nestedListItem});
+            doc.extractItems({item1: nestedListItem, item2: nestedListItem}); //@@ name!
 
 
-            var section = doc.root,
-                list = section.contents()[0],
-                item1 = list.contents()[0],
+            list = doc.root.contents()[0];
+            var item1 = list.contents()[0],
                 item2 = list.contents()[1], //
                 item3 = list.contents()[2],
                 item4 = list.contents()[3], //
                 item2 = list.contents()[1], //
                 item3 = list.contents()[2],
                 item4 = list.contents()[3], //
@@ -278,11 +290,9 @@ describe('Lists extension', function() {
                 nestedListItem1 = nestedList.contents()[1],
                 nestedListItem2 = nestedList.contents()[2];
 
                 nestedListItem1 = nestedList.contents()[1],
                 nestedListItem2 = nestedList.contents()[2];
 
-            doc.transform('extractItems', {item1: nestedListItem1, item2: nestedListItem2});
-
-            var section = doc.root,
-                list = section.contents()[0],
-                item1 = list.contents()[0],
+            doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
+            list = doc.root.contents()[0];
+            var item1 = list.contents()[0],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3],
@@ -319,11 +329,10 @@ describe('Lists extension', function() {
                 nestedListItem1 = nestedList.contents()[0],
                 nestedListItem2 = nestedList.contents()[1];
 
                 nestedListItem1 = nestedList.contents()[0],
                 nestedListItem2 = nestedList.contents()[1];
 
-            doc.transform('extractItems', {item1: nestedListItem1, item2: nestedListItem2});
+            doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
 
 
-            var section = doc.root,
-                list = section.contents()[0],
-                item1 = list.contents()[0],
+            list = doc.root.contents()[0];
+            var item1 = list.contents()[0],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3],
@@ -360,11 +369,10 @@ describe('Lists extension', function() {
                 nestedListItem1 = nestedList.contents()[0],
                 nestedListItem2 = nestedList.contents()[1];
 
                 nestedListItem1 = nestedList.contents()[0],
                 nestedListItem2 = nestedList.contents()[1];
 
-            doc.transform('extractItems', {item1: nestedListItem1, item2: nestedListItem2});
+            doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
 
 
-            var section = doc.root,
-                list = section.contents()[0],
-                item1 = list.contents()[0],
+            list = doc.root.contents()[0];
+            var item1 = list.contents()[0],
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3];
                 item2 = list.contents()[1],
                 item3 = list.contents()[2],
                 item4 = list.contents()[3];
@@ -395,9 +403,9 @@ describe('Lists extension', function() {
                 nestedList = list.contents()[1].contents()[0],
                 nestedListItem = nestedList.contents()[0];
 
                 nestedList = list.contents()[1].contents()[0],
                 nestedListItem = nestedList.contents()[0];
 
-            var test = doc.transform('extractItems', {item1: nestedListItem, item2: nestedListItem, merge: false});
+            var test = doc.extractItems({item1: nestedListItem, item2: nestedListItem, merge: false});
 
 
-            expect(test).to.equal(true, 'extraction status ok');
+            expect(test.sameNode(nestedListItem)).to.equal(true, 'first item returned');
 
             var sectionContents = section.contents(),
                 extractedItem = sectionContents[1];
 
             var sectionContents = section.contents(),
                 extractedItem = sectionContents[1];