3 'modules/documentCanvas/canvas/canvas',
4 'modules/documentCanvas/canvas/documentElement'
5 ], function(chai, canvas, documentElement) {
9 var expect = chai.expect;
12 describe('Canvas', function() {
14 describe('Internal HTML representation of a sample document', function() {
15 it('works', function() {
16 var c = canvas.fromXML('\
18 This is some text without its own wrapping tag.\
19 <div class="p.subclass">\
23 This is text in a div <span>with some inline text</span>.\
25 This is some text without its own wrapping tag.\
28 var expected = '<div wlxml-tag="section">'
29 + 'This is some text without its own wrapping tag.'
30 + '<div wlxml-tag="div" wlxml-class="p-subclass">This is a paragraph.</div>'
31 + '<div wlxml-tag="div">This is text in a div <div wlxml-tag="span">with some inline text</div>.</div>'
32 + 'This is some text without its own wrapping tag.'
34 expect(c.doc().dom()[0].isEqualNode($(expected)[0])).to.be.true;
38 describe('Internal HTML representation of a DocumentNodeElement', function() {
39 it('is always a div tag', function() {
40 ['section', 'header', 'span', 'aside', 'figure'].forEach(function(tagName) {
41 var dom = canvas.fromXML('<' + tagName + '></' + tagName + '>').doc().dom();
42 expect(dom.prop('tagName')).to.equal('DIV', tagName + ' is represented as div');
45 it('has wlxml tag put into wlxml-tag attribute', function() {
46 var dom = canvas.fromXML('<section></section>').doc().dom();
47 expect(dom.attr('wlxml-tag')).to.equal('section');
49 it('has wlxml class put into wlxml-class, dots replaced with dashes', function() {
50 var dom = canvas.fromXML('<section class="some.class"></section>').doc().dom();
51 expect(dom.attr('wlxml-class')).to.equal('some-class');
55 describe('Internal HTML representation of a DocumentTextElement', function() {
56 it('is just a TextNode', function() {
57 var dom = canvas.fromXML('<section>Alice</section>').doc().children()[0].dom();
58 expect(dom[0].nodeType === Node.TEXT_NODE);
62 describe('basic properties', function() {
63 it('renders empty document when canvas created from empty XML', function() {
64 var c = canvas.fromXML('');
65 expect(c.doc()).to.equal(null);
68 it('gives access to its document root node', function() {
69 var c = canvas.fromXML('<section></section>');
70 expect(c.doc().wlxmlTag).to.equal('section');
73 describe('DocumentTextElement', function() {
74 it('can have its content set', function() {
75 var c = canvas.fromXML('<section>Alice</section>'),
77 text = root.children()[0];
79 text.setText('a cat');
80 expect(root.children()[0].getText()).to.equal('a cat');
84 describe('DocumentNodeElement', function() {
85 it('knows index of its child', function() {
86 var c = canvas.fromXML('<section><div></div><header></header><span></span></section>'),
88 child = root.children()[1];
89 expect(root.childIndex(child)).to.equal(1);
92 it('knows WLXML tag it renders', function(){
93 var c = canvas.fromXML('<section></section>'),
95 expect(section.getWlxmlTag()).to.equal('section', 'initial tag is section');
96 section.setWlxmlTag('header');
97 expect(section.getWlxmlTag()).to.equal('header', 'tag is changed to header');
100 it('knows WLXML class of a WLXML tag it renders', function(){
101 var c = canvas.fromXML('<section class="some.class"></section>'),
103 expect(section.getWlxmlClass()).to.equal('some.class');
104 section.setWlxmlClass('some.other.class');
105 expect(section.getWlxmlClass()).to.equal('some.other.class');
106 section.setWlxmlClass(null);
107 expect(section.getWlxmlClass()).to.be.undefined;
114 describe('document representation api', function() {
115 describe('document root element', function() {
116 var c = canvas.fromXML('<section></section>');
117 it('exists', function() {
118 expect(c.doc()).to.be.instanceOf(documentElement.DocumentElement);
120 it('is of type DocumentNodeElement', function() {
121 expect(c.doc()).to.be.instanceOf(documentElement.DocumentNodeElement);
125 describe('DocumentElements comparison', function() {
126 it('reports dwo DocumentElements to be the same when they represent the same wlxml document element', function() {
127 var c = canvas.fromXML('<section><div></div><div></div></section>'),
128 first_div1 = c.doc().children()[0],
129 first_div2 = c.doc().children()[0],
130 second_div = c.doc().children()[1];
131 expect(first_div1.sameNode(first_div1)).to.be.true;
132 expect(first_div1.sameNode(first_div2)).to.be.true;
133 expect(first_div1.sameNode(second_div)).to.be.false;
137 describe('traversing', function() {
138 it('reports element nodes', function() {
139 var c = canvas.fromXML('<section><div></div></section>'),
140 children = c.doc().children();
141 expect(children.length).to.equal(1);
142 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
144 c = canvas.fromXML('<section><div></div><div></div></section>'),
145 children = c.doc().children();
146 expect(children.length).to.equal(2);
147 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
148 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
151 it('reports text nodes', function() {
152 var c = canvas.fromXML('<section>Alice</section>'),
153 children = c.doc().children();
154 expect(children.length).to.equal(1);
155 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
158 describe('accessing parents', function() {
159 it('returns DocumentNodeElement representing parent in wlxml document as DocumentNodeElement parent', function() {
160 var c = canvas.fromXML('<section><div></div></section>'),
161 div = c.doc().children()[0];
162 expect(div.parent().sameNode(c.doc())).to.be.true;
164 it('returns DocumentNodeElement representing parent in wlxml document as DocumentTextElement parent', function() {
165 var c = canvas.fromXML('<section>Alice</section>'),
166 text = c.doc().children()[0];
167 expect(text.parent().sameNode(c.doc())).to.be.true;
171 describe('free text handling', function() {
172 it('sees free text', function() {
173 var c = canvas.fromXML('<section>Alice <span>has</span> a cat</section>'),
174 children = c.doc().children();
175 expect(children.length).to.equal(3);
176 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
177 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
178 expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
182 describe('white characters handling', function() {
183 it('says empty element node has no children', function() {
184 var c = canvas.fromXML('<section></section>');
185 expect(c.doc().children().length).to.equal(0);
187 it('says element node with one space has one DocumentTextElement', function() {
188 var c = canvas.fromXML('<section> </section>');
189 expect(c.doc().children().length).to.equal(1);
190 expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
191 expect(c.doc().children()[0].getText()).to.equal(' ');
193 it('ignores white space surrounding block elements', function() {
194 var c = canvas.fromXML('<section> <div></div> </section>');
195 var children = c.doc().children();
196 expect(children.length).to.equal(1);
197 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
199 it('ignores white space between block elements', function() {
200 var c = canvas.fromXML('<section><div></div> <div></div></section>');
201 var children = c.doc().children();
202 expect(children.length === 2);
203 [0,1].forEach(function(idx) {
204 expect(children[idx]).to.be.instanceOf(documentElement.DocumentNodeElement);
208 it('trims white space from the beginning and the end of the block elements', function() {
209 var c = canvas.fromXML('<section> Alice <span>has</span> a cat </section>');
210 expect(c.doc().children()[0].getText()).to.equal('Alice ');
211 expect(c.doc().children()[2].getText()).to.equal(' a cat');
214 it('normalizes string of white characters to one space at the inline element boundries', function() {
215 var c = canvas.fromXML('<span> Alice has a cat </span>');
216 expect(c.doc().children()[0].getText()).to.equal(' Alice has a cat ');
219 it('normalizes string of white characters to one space before inline element', function() {
220 var c = canvas.fromXML('<div>Alice has <span>a cat</span></div>');
221 expect(c.doc().children()[0].getText()).to.equal('Alice has ');
224 it('normalizes string of white characters to one space after inline element', function() {
225 var c = canvas.fromXML('<div>Alice has <span>a</span> cat</div>');
226 expect(c.doc().children()[2].getText()).to.equal(' cat');
231 describe('manipulation api', function() {
233 describe('Basic Element inserting', function() {
234 it('can put new NodeElement at the end', function() {
235 var c = canvas.fromXML('<section></section>'),
236 appended = c.doc().append({tag: 'header', klass: 'some.class'}),
237 children = c.doc().children();
239 expect(children.length).to.equal(1);
240 expect(children[0].sameNode(appended));
243 it('can put new TextElement at the end', function() {
244 var c = canvas.fromXML('<section></section>'),
245 appended = c.doc().append({text: 'Alice'}),
246 children = c.doc().children();
248 expect(children.length).to.equal(1);
249 expect(children[0].sameNode(appended));
250 expect(children[0].getText()).to.equal('Alice');
253 it('can put new NodeElement after another NodeElement', function() {
254 var c = canvas.fromXML('<section><div></div></section>'),
255 div = c.doc().children()[0],
256 added = div.after({tag: 'header', klass: 'some.class'}),
257 children = c.doc().children();
258 expect(children.length).to.equal(2);
259 expect(children[1].sameNode(added));
262 it('can put new Nodeelement before another element', function() {
263 var c = canvas.fromXML('<section><div></div></section>'),
264 div = c.doc().children()[0],
265 added = div.before({tag: 'header', klass: 'some.class'}),
266 children = c.doc().children();
267 expect(children.length).to.equal(2);
268 expect(children[0].sameNode(added));
271 it('can put new DocumentNodeElement after DocumentTextElement', function() {
272 var c = canvas.fromXML('<section>Alice</section>'),
273 text = c.doc().children()[0],
274 added = text.after({tag: 'p'}),
275 children = c.doc().children();
277 expect(children.length).to.equal(2);
278 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
279 expect(children[0].getText()).to.equal('Alice');
280 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
281 expect(children[1].sameNode(added)).to.be.true;
283 it('can put new DocumentNodeElement before DocumentTextElement', function() {
284 var c = canvas.fromXML('<section>Alice</section>'),
285 text = c.doc().children()[0],
286 added = text.before({tag: 'p'}),
287 children = c.doc().children();
289 expect(children.length).to.equal(2);
290 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
291 expect(children[0].sameNode(added)).to.be.true;
292 expect(children[1]).to.be.instanceOf(documentElement.DocumentTextElement);
293 expect(children[1].getText()).to.equal('Alice');
297 describe('Splitting text', function() {
299 it('splits DocumentTextElement\'s parent into two DocumentNodeElements of the same type', function() {
300 var c = canvas.fromXML('<section><header>Some header</header></section>'),
302 text = section.children()[0].children()[0];
304 text.split({offset: 5});
305 expect(section.children().length).to.equal(2, 'section has two children');
307 var header1 = section.children()[0];
308 var header2 = section.children()[1];
310 expect(header1.wlxmlTag).to.equal('header', 'first section child represents wlxml header');
311 expect(header1.children().length).to.equal(1, 'first header has one text child');
312 expect(header1.children()[0].getText()).to.equal('Some ', 'first header has correct content');
313 expect(header2.wlxmlTag).to.equal('header', 'second section child represents wlxml header');
314 expect(header2.children().length).to.equal(1, 'second header has one text child');
315 expect(header2.children()[0].getText()).to.equal('header', 'second header has correct content');
318 it('keeps DocumentTextElement\'s parent\'s children elements intact', function() {
319 var c = canvas.fromXML('\
322 A <span>fancy</span> and <span>nice</span> header\
326 header = section.children()[0],
327 textAnd = header.children()[2];
329 textAnd.split({offset: 2});
331 var sectionChildren = section.children();
332 expect(sectionChildren.length).to.equal(2, 'Section has two children');
333 expect(sectionChildren[0].wlxmlTag).to.equal('header', 'First section element is a wlxml header');
334 expect(sectionChildren[1].wlxmlTag).to.equal('header', 'Second section element is a wlxml header');
336 var firstHeaderChildren = sectionChildren[0].children();
337 expect(firstHeaderChildren.length).to.equal(3, 'First header has three children');
338 expect(firstHeaderChildren[0].getText()).to.equal('A ', 'First header starts with a text');
339 expect(firstHeaderChildren[1].wlxmlTag).to.equal('span', 'First header has span in the middle');
340 expect(firstHeaderChildren[2].getText()).to.equal(' a', 'First header ends with text');
342 var secondHeaderChildren = sectionChildren[1].children();
343 expect(secondHeaderChildren.length).to.equal(3, 'Second header has three children');
344 expect(secondHeaderChildren[0].getText()).to.equal('nd ', 'Second header starts with text');
345 expect(secondHeaderChildren[1].wlxmlTag).to.equal('span', 'Second header has span in the middle');
346 expect(secondHeaderChildren[2].getText()).to.equal(' header', 'Second header ends with text');
350 describe('wrapping', function() {
351 it('wraps DocumentNodeElement', function() {
352 var c = canvas.fromXML('<section><div></div></section>'),
353 div = c.doc().children()[0];
355 var returned = div.wrapWithNodeElement({tag: 'header', klass: 'some.class'}),
356 parent = div.parent(),
357 parent2 = c.doc().children()[0];
359 expect(returned.sameNode(parent)).to.be.true;
360 expect(returned.sameNode(parent2)).to.be.true;
361 expect(returned.getWlxmlTag()).to.equal('header');
362 expect(returned.getWlxmlClass()).to.equal('some.class');
364 it('wraps DocumentTextElement', function() {
365 var c = canvas.fromXML('<section>Alice</section>'),
366 text = c.doc().children()[0];
368 var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class'}),
369 parent = text.parent(),
370 parent2 = c.doc().children()[0];
372 expect(returned.sameNode(parent)).to.be.true;
373 expect(returned.sameNode(parent2)).to.be.true;
374 expect(returned.getWlxmlTag()).to.equal('header');
375 expect(returned.getWlxmlClass()).to.equal('some.class');
378 it('wraps part of DocumentTextElement', function() {
379 var c = canvas.fromXML('<section>Alice has a cat</section>'),
380 text = c.doc().children()[0];
382 var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class', start: 5, end: 12}),
383 children = c.doc().children();
385 expect(children.length).to.equal(3);
387 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
388 expect(children[0].getText()).to.equal('Alice');
390 expect(children[1].sameNode(returned)).to.be.true;
391 expect(returned.getWlxmlTag()).to.equal('header');
392 expect(returned.getWlxmlClass()).to.equal('some.class');
393 expect(children[1].children().length).to.equal(1);
394 expect(children[1].children()[0].getText()).to.equal(' has a ');
396 expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
397 expect(children[2].getText()).to.equal('cat');
400 it('wraps text spanning multiple sibling DocumentTextNodes', function() {
401 var c = canvas.fromXML('<section>Alice has a <span>small</span> cat</section>'),
403 wrapper = c.wrapText({
405 _with: {tag: 'span', klass: 'some.class'},
411 expect(section.children().length).to.equal(2);
412 expect(section.children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
413 expect(section.children()[0].getText()).to.equal('Alice ');
415 var wrapper2 = section.children()[1];
416 expect(wrapper2.sameNode(wrapper)).to.be.true;
418 var wrapperChildren = wrapper.children();
419 expect(wrapperChildren.length).to.equal(3);
420 expect(wrapperChildren[0].getText()).to.equal('has a ');
422 expect(wrapperChildren[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
423 expect(wrapperChildren[1].children().length).to.equal(1);
424 expect(wrapperChildren[1].children()[0].getText()).to.equal('small');
426 expect(wrapperChildren[2].getText()).to.equal(' cat');
430 describe('unwrapping', function() {
431 it('unwraps DocumentTextElement from its parent DocumentNodeElement if it\'s its only child', function() {
432 var c = canvas.fromXML('<section><div>Alice has a cat</div></section>'),
434 text = section.children()[0].children()[0];
438 expect(section.children().length).to.equal(1);
439 expect(section.children()[0].getText()).to.equal('Alice has a cat');
444 describe('Lists api', function() {
445 describe('creating lists', function() {
446 it('allows creation of a list from existing sibling DocumentElements', function() {
447 var c = canvas.fromXML('\
455 textHas = section.children()[1],
456 divA = section.children()[2]
458 c.list.create({element1: textHas, element2: divA});
460 expect(section.children().length).to.equal(3, 'section has three child elements');
462 var child1 = section.children()[0],
463 list = section.children()[1],
464 child3 = section.children()[2];
466 expect(child1.getText()).to.equal('Alice');
467 expect(list.is('list')).to.equal(true, 'second child is a list');
468 expect(list.children().length).to.equal(2, 'list contains two elements');
469 list.children().forEach(function(child) {
470 expect(child.getWlxmlClass()).to.equal('item', 'list childs have wlxml class of item');
472 expect(child3.children()[0].getText()).to.equal('cat');
475 it('allows creating nested list from existing sibling list items', function() {
476 var c = canvas.fromXML('\
478 <div class="list-items">\
479 <div class="item">A</div>\
480 <div class="item">B</div>\
481 <div class="item">C</div>\
482 <div class="item">D</div>\
485 outerList = c.doc().children()[0],
486 itemB = outerList.children()[1],
487 itemC = outerList.children()[2];
490 c.list.create({element1: itemB, element2: itemC});
492 var outerListItems = outerList.children(),
493 innerList = outerListItems[1].children()[0],
494 innerListItems = innerList.children();
496 expect(outerListItems.length).to.equal(3, 'outer list has three items');
497 expect(outerListItems[0].children()[0].getText()).to.equal('A', 'first outer item ok');
498 expect(outerListItems[1].getWlxmlClass()).to.equal('item', 'inner list is wrapped by item element');
500 expect(innerList.is('list')).to.equal(true, 'inner list created');
501 expect(innerListItems.length).to.equal(2, 'inner list has two items');
502 expect(innerListItems[0].children()[0].getText()).to.equal('B', 'first inner item ok');
503 expect(innerListItems[1].children()[0].getText()).to.equal('C', 'second inner item ok');
505 expect(outerListItems[2].children()[0].getText()).to.equal('D', 'last outer item ok');
511 describe('extracting list items', function() {
512 it('creates two lists with extracted items in the middle if extracting from the middle of the list', function() {
513 var c = canvas.fromXML('\
515 <div class="list.items">\
516 <div class="item">0</div>\
517 <div class="item">1</div>\
518 <div class="item">2</div>\
519 <div class="item">3</div>\
522 list = c.doc().children()[0],
523 item1 = list.children()[1],
524 item2 = list.children()[2];
526 c.list.extractItems({element1: item1, element2: item2});
528 var section = c.doc(),
529 list1 = section.children()[0],
530 oldItem1 = section.children()[1],
531 oldItem2 = section.children()[2],
532 list2 = section.children()[3];
534 expect(section.children().length).to.equal(4, 'section contains four children');
536 expect(list1.is('list')).to.equal(true, 'first section child is a list');
537 expect(list1.children().length).to.equal(1, 'first list has one child');
538 expect(list1.children()[0].children()[0].getText()).to.equal('0', 'first item of the first list is a first item of the original list');
540 expect(oldItem1.children()[0].getText()).to.equal('1', 'first item got extracted');
541 expect(oldItem1.getWlxmlClass() === undefined).to.equal(true, 'first extracted element has no wlxml class');
543 expect(oldItem2.children()[0].getText()).to.equal('2', 'second item got extracted');
544 expect(oldItem2.getWlxmlClass() === undefined).to.equal(true, 'second extracted element has no wlxml class');
546 expect(list2.is('list')).to.equal(true, 'last section child is a list');
547 expect(list2.children().length).to.equal(1, 'second list has one child');
548 expect(list2.children()[0].children()[0].getText()).to.equal('3', 'first item of the second list is a last item of the original list');
551 it('puts extracted items above the list if starting item is the first one', function() {
552 var c = canvas.fromXML('\
554 <div class="list.items">\
555 <div class="item">0</div>\
556 <div class="item">1</div>\
557 <div class="item">2</div>\
560 list = c.doc().children()[0],
561 item1 = list.children()[0],
562 item2 = list.children()[1],
563 item3 = list.children()[2];
565 c.list.extractItems({element1: item1, element2: item2});
567 var section = c.doc(),
568 oldItem1 = section.children()[0],
569 oldItem2 = section.children()[1],
570 newList = section.children()[2];
572 expect(section.children().length).to.equal(3, 'section has three children');
573 expect(oldItem1.children()[0].getText()).to.equal('0', 'first item extracted');
574 expect(oldItem2.children()[0].getText()).to.equal('1', 'second item extracted');
575 expect(newList.is('list')).to.equal(true, 'list lies below extracted item');
576 expect(newList.children().length).to.equal(1, 'list has now one child');
579 it('puts extracted items below the list if ending item is the last one', function() {
580 var c = canvas.fromXML('\
582 <div class="list.items">\
583 <div class="item">0</div>\
584 <div class="item">1</div>\
585 <div class="item">2</div>\
588 list = c.doc().children()[0],
589 item1 = list.children()[0],
590 item2 = list.children()[1],
591 item3 = list.children()[2];
593 c.list.extractItems({element1: item2, element2: item3});
595 var section = c.doc(),
596 oldItem1 = section.children()[1],
597 oldItem2 = section.children()[2],
598 newList = section.children()[0];
600 expect(section.children().length).to.equal(3, 'section has three children');
601 expect(oldItem1.children()[0].getText()).to.equal('1', 'first item extracted');
602 expect(oldItem2.children()[0].getText()).to.equal('2', 'second item extracted');
603 expect(newList.is('list')).to.equal(true, 'list lies above extracted item');
604 expect(newList.children().length).to.equal(1, 'list has now one child');
607 it('removes list if all its items are extracted', function() {
608 var c = canvas.fromXML('\
610 <div class="list.items">\
611 <div class="item">some item</div>\
612 <div class="item">some item 2</div>\
615 list = c.doc().children()[0],
616 item1 = list.children()[0],
617 item2 = list.children()[1];
619 c.list.extractItems({element1: item1, element2: item2});
621 var section = c.doc(),
622 list1 = section.children()[0],
623 oldItem1 = section.children()[0],
624 oldItem2 = section.children()[1];
626 expect(section.children().length).to.equal(2, 'section contains two children');
627 expect(oldItem1.children()[0].getText()).to.equal('some item');
628 expect(oldItem2.children()[0].getText()).to.equal('some item 2');
631 it('creates two lists with extracted items in the middle if extracting from the middle of the list - nested case' , function() {
632 var c = canvas.fromXML('\
634 <div class="list.items">\
635 <div class="item">0</div>\
637 <div class="list.items">\
638 <div class="item">1.1</div>\
639 <div class="item">1.2</div>\
640 <div class="item">1.3</div>\
643 <div class="item">2</div>\
646 list = c.doc().children()[0],
647 nestedList = list.children()[1].children()[0],
648 nestedListItem = nestedList.children()[1];
650 c.list.extractItems({element1: nestedListItem, element2: nestedListItem});
652 var section = c.doc(),
653 list = section.children()[0],
654 item1 = list.children()[0],
655 item2 = list.children()[1], //
656 item3 = list.children()[2],
657 item4 = list.children()[3], //
658 item5 = list.children()[4],
659 nestedList1 = item2.children()[0],
660 nestedList2 = item4.children()[0];
662 expect(list.children().length).to.equal(5, 'top list has five items');
664 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
666 expect(item2.getWlxmlClass()).to.equal('item', 'first nested list is still wrapped in item element');
667 expect(nestedList1.children().length).to.equal(1, 'first nested list is left with one child');
668 expect(nestedList1.children()[0].children()[0].getText()).to.equal('1.1', 'first nested list item left alone');
670 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
672 expect(item4.getWlxmlClass()).to.equal('item', 'second nested list is still wrapped in item element');
673 expect(nestedList2.children().length).to.equal(1, 'second nested list is left with one child');
674 expect(nestedList2.children()[0].children()[0].getText()).to.equal('1.3', 'second nested list item left alone');
676 expect(item5.children()[0].getText()).to.equal('2', 'last item ok');
679 it('puts extracted items below the list if ending item is the last one - nested case' , function() {
680 var c = canvas.fromXML('\
682 <div class="list.items">\
683 <div class="item">0</div>\
685 <div class="list.items">\
686 <div class="item">1.1</div>\
687 <div class="item">1.2</div>\
688 <div class="item">1.3</div>\
691 <div class="item">2</div>\
694 list = c.doc().children()[0],
695 nestedList = list.children()[1].children()[0],
696 nestedListItem1 = nestedList.children()[1],
697 nestedListItem2 = nestedList.children()[2];
699 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
701 var section = c.doc(),
702 list = section.children()[0],
703 item1 = list.children()[0],
704 item2 = list.children()[1],
705 item3 = list.children()[2],
706 item4 = list.children()[3],
707 item5 = list.children()[4];
708 nestedList = item2.children()[0];
710 expect(list.children().length).to.equal(5, 'top list has five items');
711 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
712 expect(item2.getWlxmlClass()).to.equal('item', 'nested list is still wrapped in item element');
713 expect(nestedList.children().length).to.equal(1, 'nested list is left with one child');
714 expect(nestedList.children()[0].children()[0].getText()).to.equal('1.1', 'nested list item left alone');
715 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
716 expect(item4.children()[0].getText()).to.equal('1.3', 'fourth item ok');
717 expect(item5.children()[0].getText()).to.equal('2', 'fifth item ok');
720 it('puts extracted items above the list if starting item is the first one - nested case' , function() {
721 var c = canvas.fromXML('\
723 <div class="list.items">\
724 <div class="item">0</div>\
726 <div class="list.items">\
727 <div class="item">1.1</div>\
728 <div class="item">1.2</div>\
729 <div class="item">1.3</div>\
732 <div class="item">2</div>\
735 list = c.doc().children()[0],
736 nestedList = list.children()[1].children()[0],
737 nestedListItem1 = nestedList.children()[0],
738 nestedListItem2 = nestedList.children()[1];
740 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
742 var section = c.doc(),
743 list = section.children()[0],
744 item1 = list.children()[0],
745 item2 = list.children()[1],
746 item3 = list.children()[2],
747 item4 = list.children()[3],
748 item5 = list.children()[4];
749 nestedList = item4.children()[0];
751 expect(list.children().length).to.equal(5, 'top list has five items');
752 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
753 expect(item2.children()[0].getText()).to.equal('1.1', 'second item ok');
754 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
756 expect(item4.getWlxmlClass()).to.equal('item', 'nested list is still wrapped in item element');
757 expect(nestedList.children().length).to.equal(1, 'nested list is left with one child');
758 expect(nestedList.children()[0].children()[0].getText()).to.equal('1.3', 'nested list item left alone');
759 expect(item5.children()[0].getText()).to.equal('2', 'fifth item ok');
762 it('removes list if all its items are extracted - nested case', function() {
763 var c = canvas.fromXML('\
765 <div class="list.items">\
766 <div class="item">0</div>\
768 <div class="list.items">\
769 <div class="item">1.1</div>\
770 <div class="item">1.2</div>\
773 <div class="item">2</div>\
776 list = c.doc().children()[0],
777 nestedList = list.children()[1].children()[0],
778 nestedListItem1 = nestedList.children()[0],
779 nestedListItem2 = nestedList.children()[1];
781 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
783 var section = c.doc(),
784 list = section.children()[0],
785 item1 = list.children()[0],
786 item2 = list.children()[1],
787 item3 = list.children()[2],
788 item4 = list.children()[3];
790 expect(list.children().length).to.equal(4, 'top list has four items');
791 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
792 expect(item2.children()[0].getText()).to.equal('1.1', 'second item ok');
793 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
794 expect(item4.children()[0].getText()).to.equal('2', 'fourth item ok');