4 'modules/documentCanvas/canvas/canvas',
5 'modules/documentCanvas/canvas/documentElement',
6 'modules/documentCanvas/canvas/utils'
7 ], function(chai, sinon, canvas, documentElement, utils) {
11 var expect = chai.expect;
14 describe('Canvas', function() {
16 describe('Internal HTML representation of a DocumentNodeElement', function() {
17 it('is always a div tag', function() {
18 ['section', 'header', 'span', 'aside', 'figure'].forEach(function(tagName) {
19 var dom = canvas.fromXML('<' + tagName + '></' + tagName + '>').doc().dom();
20 expect(dom.prop('tagName')).to.equal('DIV', tagName + ' is represented as div');
23 it('has wlxml tag put into wlxml-tag attribute of its internal container', function() {
24 var dom = canvas.fromXML('<section></section>').doc().dom();
25 expect(dom.children('[document-element-content]').attr('wlxml-tag')).to.equal('section');
27 it('has wlxml class put into wlxml-class attribute of its internal containr, dots replaced with dashes', function() {
28 var dom = canvas.fromXML('<section class="some.class"></section>').doc().dom();
29 expect(dom.children('[document-element-content]').attr('wlxml-class')).to.equal('some-class');
33 describe('Internal HTML representation of a DocumentTextElement', function() {
34 it('is text node wrapped in a div with document-text-element attribute set', function() {
35 var dom = canvas.fromXML('<section>Alice</section>').doc().children()[0].dom();
36 expect(dom.prop('tagName')).to.equal('DIV');
37 expect(dom.attr('document-text-element')).to.equal('');
38 expect(dom.contents().length).to.equal(1);
39 expect(dom.contents()[0].nodeType).to.equal(Node.TEXT_NODE);
40 expect($(dom.contents()[0]).text()).to.equal('Alice');
44 describe('basic properties', function() {
45 it('renders empty document when canvas created from empty XML', function() {
46 var c = canvas.fromXML('');
47 expect(c.doc()).to.equal(null);
50 it('gives access to its document root node', function() {
51 var c = canvas.fromXML('<section></section>');
52 expect(c.doc().getWlxmlTag()).to.equal('section');
55 describe('root element', function() {
56 it('has no parent', function() {
57 var c = canvas.fromXML('<section></section>');
58 expect(c.doc().parent()).to.be.null;
62 describe('DocumentTextElement', function() {
63 it('can have its content set', function() {
64 var c = canvas.fromXML('<section>Alice</section>'),
66 text = root.children()[0];
68 text.setText('a cat');
69 expect(root.children()[0].getText()).to.equal('a cat');
73 describe('DocumentNodeElement', function() {
74 it('knows index of its child', function() {
75 var c = canvas.fromXML('<section><div></div><header></header><span></span></section>'),
77 child = root.children()[1];
78 expect(root.childIndex(child)).to.equal(1);
81 it('knows WLXML tag it renders', function(){
82 var c = canvas.fromXML('<section></section>'),
84 expect(section.getWlxmlTag()).to.equal('section', 'initial tag is section');
85 section.setWlxmlTag('header');
86 expect(section.getWlxmlTag()).to.equal('header', 'tag is changed to header');
89 it('knows WLXML class of a WLXML tag it renders', function(){
90 var c = canvas.fromXML('<section class="some.class.A"></section>'),
92 expect(section.getWlxmlClass()).to.equal('some.class.A');
93 section.setWlxmlClass('some.class.B');
94 expect(section.getWlxmlClass()).to.equal('some.class.B');
95 section.setWlxmlClass(null);
96 expect(section.getWlxmlClass()).to.be.undefined;
101 describe('element has meta attributes', function() {
102 it('can change its meta attributes', function() {
103 var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
104 span = c.doc().children()[0];
106 expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
107 span.setWlxmlMetaAttr('uri', 'otheruri');
108 expect(span.getWlxmlMetaAttr('uri')).to.equal('otheruri');
111 it('changes its meta attributes with class change', function() {
112 var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
113 span = c.doc().children()[0];
115 expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
116 span.setWlxmlClass('author');
117 expect(span.getWlxmlMetaAttr('uri')).to.be.undefined;
120 it('keeps meta attribute value on class change if a new class has this attribute', function() {
121 var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
122 span = c.doc().children()[0];
123 span.setWlxmlClass('uri.some.subclass');
124 expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
129 it('returns DocumentNodeElement instance from HTMLElement', function() {
130 var c = canvas.fromXML('<section></section>'),
131 htmlElement = c.doc().dom().get(0),
132 element = c.getDocumentElement(htmlElement);
133 expect(element).to.be.instanceOf(documentElement.DocumentNodeElement);
134 expect(element.sameNode(c.doc()));
137 it('returns DocumentTextElement instance from Text Node', function() {
138 var c = canvas.fromXML('<section>Alice</section>'),
139 aliceElement = c.doc().children()[0],
140 textNode = aliceElement.dom().contents()[0],
141 element = c.getDocumentElement(textNode);
143 expect(textNode.nodeType).to.equal(Node.TEXT_NODE, 'text node selected');
144 expect($(textNode).text()).to.equal('Alice');
146 expect(element).to.be.instanceOf(documentElement.DocumentTextElement);
147 expect(element.sameNode(c.doc().children()[0]));
153 describe('document representation api', function() {
154 describe('document root element', function() {
155 var c = canvas.fromXML('<section></section>');
156 it('exists', function() {
157 expect(c.doc()).to.be.instanceOf(documentElement.DocumentElement);
159 it('is of type DocumentNodeElement', function() {
160 expect(c.doc()).to.be.instanceOf(documentElement.DocumentNodeElement);
164 describe('DocumentElements comparison', function() {
165 it('reports dwo DocumentElements to be the same when they represent the same wlxml document element', function() {
166 var c = canvas.fromXML('<section><div></div><div></div></section>'),
167 first_div1 = c.doc().children()[0],
168 first_div2 = c.doc().children()[0],
169 second_div = c.doc().children()[1];
170 expect(first_div1.sameNode(first_div1)).to.be.true;
171 expect(first_div1.sameNode(first_div2)).to.be.true;
172 expect(first_div1.sameNode(second_div)).to.be.false;
176 describe('traversing', function() {
177 it('reports element nodes', function() {
178 var c = canvas.fromXML('<section><div></div></section>'),
179 children = c.doc().children();
180 expect(children.length).to.equal(1);
181 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
183 c = canvas.fromXML('<section><div></div><div></div></section>'),
184 children = c.doc().children();
185 expect(children.length).to.equal(2);
186 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
187 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
190 it('reports text nodes', function() {
191 var c = canvas.fromXML('<section>Alice</section>'),
192 children = c.doc().children();
193 expect(children.length).to.equal(1);
194 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
197 describe('accessing parents', function() {
198 it('returns DocumentNodeElement representing parent in wlxml document as DocumentNodeElement parent', function() {
199 var c = canvas.fromXML('<section><div></div></section>'),
200 div = c.doc().children()[0];
201 expect(div.parent().sameNode(c.doc())).to.be.true;
203 it('returns DocumentNodeElement representing parent in wlxml document as DocumentTextElement parent', function() {
204 var c = canvas.fromXML('<section>Alice</section>'),
205 text = c.doc().children()[0];
206 expect(text.parent().sameNode(c.doc())).to.be.true;
210 describe('accessing sibling parents of two elements', function() {
211 it('returns elements themself if they have direct common parent', function() {
212 var c = canvas.fromXML('<section>\
219 wrappingDiv = c.doc().children()[0],
220 divA = wrappingDiv.children()[0],
221 divB = wrappingDiv.children()[1];
223 var siblingParents = c.getSiblingParents({element1: divA, element2: divB});
225 expect(siblingParents.element1.sameNode(divA)).to.equal(true, 'divA');
226 expect(siblingParents.element2.sameNode(divB)).to.equal(true, 'divB');
229 it('returns sibling parents - example 1', function() {
230 var c = canvas.fromXML('<section>Alice <span>has a cat</span></section>'),
232 aliceText = section.children()[0],
233 span = section.children()[1],
234 spanText = span.children()[0];
236 var siblingParents = c.getSiblingParents({element1: aliceText, element2: spanText});
238 expect(siblingParents.element1.sameNode(aliceText)).to.equal(true, 'aliceText');
239 expect(siblingParents.element2.sameNode(span)).to.equal(true, 'span');
243 describe('free text handling', function() {
244 it('sees free text', function() {
245 var c = canvas.fromXML('<section>Alice <span>has</span> a cat</section>'),
246 children = c.doc().children();
247 expect(children.length).to.equal(3);
248 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
249 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
250 expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
254 describe('white characters handling', function() {
255 it('says empty element node has no children', function() {
256 var c = canvas.fromXML('<section></section>');
257 expect(c.doc().children().length).to.equal(0);
259 it('says element node with one space has one DocumentTextElement', function() {
260 var c = canvas.fromXML('<section> </section>');
261 expect(c.doc().children().length).to.equal(1);
262 expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
263 expect(c.doc().children()[0].getText()).to.equal(' ');
265 it('ignores white space surrounding block elements', function() {
266 var c = canvas.fromXML('<section> <div></div> </section>');
267 var children = c.doc().children();
268 expect(children.length).to.equal(1);
269 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
271 it('ignores white space between block elements', function() {
272 var c = canvas.fromXML('<section><div></div> <div></div></section>');
273 var children = c.doc().children();
274 expect(children.length === 2);
275 [0,1].forEach(function(idx) {
276 expect(children[idx]).to.be.instanceOf(documentElement.DocumentNodeElement);
280 it('trims white space from the beginning and the end of the block elements', function() {
281 var c = canvas.fromXML('<section> Alice <span>has</span> a cat </section>');
282 expect(c.doc().children()[0].getText()).to.equal('Alice ');
283 expect(c.doc().children()[2].getText()).to.equal(' a cat');
286 it('normalizes string of white characters to one space at the inline element boundries', function() {
287 var c = canvas.fromXML('<span> Alice has a cat </span>');
288 expect(c.doc().children()[0].getText()).to.equal(' Alice has a cat ');
291 it('normalizes string of white characters to one space before inline element', function() {
292 var c = canvas.fromXML('<div>Alice has <span>a cat</span></div>');
293 expect(c.doc().children()[0].getText()).to.equal('Alice has ');
296 it('normalizes string of white characters to one space after inline element', function() {
297 var c = canvas.fromXML('<div>Alice has <span>a</span> cat</div>');
298 expect(c.doc().children()[2].getText()).to.equal(' cat');
302 describe('getting vertically first text element', function() {
303 it('returns the first child if it\'s text element, ignores metadata', function() {
304 var c = canvas.fromXML('<section><metadata><dc:author>author</dc:author></metadata>Alice<div>has</div>a cat</section>'),
305 first = c.doc().getVerticallyFirstTextElement();
307 expect(first.sameNode(c.doc().children()[1])).to.be.true;
310 it('looks recursively inside node elements if they precede text element', function() {
311 var c = canvas.fromXML('\
320 textAlice = c.doc().children()[0].children()[0].children()[0],
321 first = c.doc().getVerticallyFirstTextElement();
323 expect(textAlice).to.be.instanceOf(documentElement.DocumentTextElement);
324 expect(first.sameNode(textAlice)).to.be.true;
329 describe('manipulation api', function() {
331 describe('Basic Element inserting', function() {
332 it('can put new NodeElement at the end', function() {
333 var c = canvas.fromXML('<section></section>'),
334 appended = c.doc().append({tag: 'header', klass: 'some.class'}),
335 children = c.doc().children();
337 expect(children.length).to.equal(1);
338 expect(children[0].sameNode(appended)).to.be.true;
341 it('can put new TextElement at the end', function() {
342 var c = canvas.fromXML('<section></section>'),
343 appended = c.doc().append({text: 'Alice'}),
344 children = c.doc().children();
346 expect(children.length).to.equal(1);
347 expect(children[0].sameNode(appended)).to.be.true;
348 expect(children[0].getText()).to.equal('Alice');
351 it('can put new NodeElement at the beginning', function() {
352 var c = canvas.fromXML('<section><div></div></section>'),
353 prepended = c.doc().prepend({tag: 'header', klass: 'some.class'}),
354 children = c.doc().children();
356 expect(children).to.have.length(2);
357 expect(children[0].sameNode(prepended)).to.be.true;
360 it('can put new TextElement at the beginning', function() {
361 var c = canvas.fromXML('<section><div></div></section>'),
362 prepended = c.doc().prepend({text: 'Alice'}),
363 children = c.doc().children();
365 expect(children).to.have.length(2)
366 expect(children[0].sameNode(prepended)).to.be.true;
367 expect(children[0].getText()).to.equal('Alice');
370 it('can put new NodeElement after another NodeElement', function() {
371 var c = canvas.fromXML('<section><div></div></section>'),
372 div = c.doc().children()[0],
373 added = div.after({tag: 'header', klass: 'some.class'}),
374 children = c.doc().children();
375 expect(children.length).to.equal(2);
376 expect(children[1].sameNode(added)).to.be.true;
379 it('can put new Nodeelement before another element', function() {
380 var c = canvas.fromXML('<section><div></div></section>'),
381 div = c.doc().children()[0],
382 added = div.before({tag: 'header', klass: 'some.class'}),
383 children = c.doc().children();
384 expect(children.length).to.equal(2);
385 expect(children[0].sameNode(added)).to.be.true;
388 it('can put new DocumentNodeElement after DocumentTextElement', function() {
389 var c = canvas.fromXML('<section>Alice</section>'),
390 text = c.doc().children()[0],
391 added = text.after({tag: 'p'}),
392 children = c.doc().children();
394 expect(children.length).to.equal(2);
395 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
396 expect(children[0].getText()).to.equal('Alice');
397 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
398 expect(children[1].sameNode(added)).to.be.true;
400 it('can put new DocumentNodeElement before DocumentTextElement', function() {
401 var c = canvas.fromXML('<section>Alice</section>'),
402 text = c.doc().children()[0],
403 added = text.before({tag: 'p'}),
404 children = c.doc().children();
406 expect(children.length).to.equal(2);
407 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
408 expect(children[0].sameNode(added)).to.be.true;
409 expect(children[1]).to.be.instanceOf(documentElement.DocumentTextElement);
410 expect(children[1].getText()).to.equal('Alice');
413 it('can divide DocumentTextElement with a new DocumentNodeElement', function() {
414 var c = canvas.fromXML('<section>Alice has a cat</section>'),
416 text = section.children()[0];
418 var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 5}),
419 sectionChildren = section.children(),
420 lhsText = sectionChildren[0],
421 rhsText = sectionChildren[2];
423 expect(lhsText.getText()).to.equal('Alice');
424 expect(returned.sameNode(sectionChildren[1]));
425 expect(rhsText.getText()).to.equal(' has a cat');
428 it('treats dividing DocumentTextElement at the very end as appending after it', function() {
429 var c = canvas.fromXML('<section>Alice has a cat</section>'),
431 text = section.children()[0];
433 var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 15}),
434 sectionChildren = section.children(),
435 textElement = sectionChildren[0],
436 nodeElement = sectionChildren[1];
438 expect(sectionChildren.length).to.equal(2);
439 expect(textElement.getText()).to.equal('Alice has a cat');
440 expect(returned.sameNode(nodeElement)).to.be.true;
441 expect(nodeElement.getWlxmlTag()).to.equal('aside');
444 it('treats dividing DocumentTextElement at the very beginning as appending before it', function() {
445 var c = canvas.fromXML('<section>Alice has a cat</section>'),
447 text = section.children()[0];
449 var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 0}),
450 sectionChildren = section.children(),
451 nodeElement = sectionChildren[0],
452 textElement = sectionChildren[1];
454 expect(sectionChildren.length).to.equal(2);
455 expect(textElement.getText()).to.equal('Alice has a cat');
456 expect(returned.sameNode(nodeElement)).to.be.true;
457 expect(nodeElement.getWlxmlTag()).to.equal('aside');
461 describe('Splitting text', function() {
463 it('splits DocumentTextElement\'s parent into two DocumentNodeElements of the same type', function() {
464 var c = canvas.fromXML('<section><header>Some header</header></section>'),
466 text = section.children()[0].children()[0];
468 var returnedValue = text.split({offset: 5});
469 expect(section.children().length).to.equal(2, 'section has two children');
471 var header1 = section.children()[0];
472 var header2 = section.children()[1];
474 expect(header1.getWlxmlTag()).to.equal('header', 'first section child represents wlxml header');
475 expect(header1.children().length).to.equal(1, 'first header has one text child');
476 expect(header1.children()[0].getText()).to.equal('Some ', 'first header has correct content');
477 expect(header2.getWlxmlTag()).to.equal('header', 'second section child represents wlxml header');
478 expect(header2.children().length).to.equal(1, 'second header has one text child');
479 expect(header2.children()[0].getText()).to.equal('header', 'second header has correct content');
481 expect(returnedValue.first.sameNode(header1)).to.equal(true, 'first node returnde');
482 expect(returnedValue.second.sameNode(header2)).to.equal(true, 'second node returned');
485 it('leaves empty copy of DocumentNodeElement if splitting at the very beginning', function() {
486 var c = canvas.fromXML('<section><header>Some header</header></section>'),
488 text = section.children()[0].children()[0];
490 text.split({offset: 0});
492 var header1 = section.children()[0];
493 var header2 = section.children()[1];
495 expect(header1.children().length).to.equal(0);
496 expect(header2.children()[0].getText()).to.equal('Some header');
499 it('leaves empty copy of DocumentNodeElement if splitting at the very end', function() {
500 var c = canvas.fromXML('<section><header>Some header</header></section>'),
502 text = section.children()[0].children()[0];
504 text.split({offset: 11});
506 var header1 = section.children()[0];
507 var header2 = section.children()[1];
509 expect(header1.children()[0].getText()).to.equal('Some header');
510 expect(header2.children().length).to.equal(0);
513 it('keeps DocumentTextElement\'s parent\'s children elements intact', function() {
514 var c = canvas.fromXML('\
517 A <span>fancy</span> and <span>nice</span> header\
521 header = section.children()[0],
522 textAnd = header.children()[2];
524 textAnd.split({offset: 2});
526 var sectionChildren = section.children();
527 expect(sectionChildren.length).to.equal(2, 'Section has two children');
528 expect(sectionChildren[0].getWlxmlTag()).to.equal('header', 'First section element is a wlxml header');
529 expect(sectionChildren[1].getWlxmlTag()).to.equal('header', 'Second section element is a wlxml header');
531 var firstHeaderChildren = sectionChildren[0].children();
532 expect(firstHeaderChildren.length).to.equal(3, 'First header has three children');
533 expect(firstHeaderChildren[0].getText()).to.equal('A ', 'First header starts with a text');
534 expect(firstHeaderChildren[1].getWlxmlTag()).to.equal('span', 'First header has span in the middle');
535 expect(firstHeaderChildren[2].getText()).to.equal(' a', 'First header ends with text');
537 var secondHeaderChildren = sectionChildren[1].children();
538 expect(secondHeaderChildren.length).to.equal(3, 'Second header has three children');
539 expect(secondHeaderChildren[0].getText()).to.equal('nd ', 'Second header starts with text');
540 expect(secondHeaderChildren[1].getWlxmlTag()).to.equal('span', 'Second header has span in the middle');
541 expect(secondHeaderChildren[2].getText()).to.equal(' header', 'Second header ends with text');
545 describe('wrapping', function() {
546 it('wraps DocumentNodeElement', function() {
547 var c = canvas.fromXML('<section><div></div></section>'),
548 div = c.doc().children()[0];
550 var returned = div.wrapWithNodeElement({tag: 'header', klass: 'some.class'}),
551 parent = div.parent(),
552 parent2 = c.doc().children()[0];
554 expect(returned.sameNode(parent)).to.be.true;
555 expect(returned.sameNode(parent2)).to.be.true;
556 expect(returned.getWlxmlTag()).to.equal('header');
557 expect(returned.getWlxmlClass()).to.equal('some.class');
559 it('wraps DocumentTextElement', function() {
560 var c = canvas.fromXML('<section>Alice</section>'),
561 text = c.doc().children()[0];
563 var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class'}),
564 parent = text.parent(),
565 parent2 = c.doc().children()[0];
567 expect(returned.sameNode(parent)).to.be.true;
568 expect(returned.sameNode(parent2)).to.be.true;
569 expect(returned.getWlxmlTag()).to.equal('header');
570 expect(returned.getWlxmlClass()).to.equal('some.class');
573 describe('wrapping part of DocumentTextElement', function() {
574 [{start: 5, end: 12}, {start: 12, end: 5}].forEach(function(offsets) {
575 it('wraps in the middle ' + offsets.start + '/' + offsets.end, function() {
576 var c = canvas.fromXML('<section>Alice has a cat</section>'),
577 text = c.doc().children()[0];
579 var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class', start: offsets.start, end: offsets.end}),
580 children = c.doc().children();
582 expect(children.length).to.equal(3);
584 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
585 expect(children[0].getText()).to.equal('Alice');
587 expect(children[1].sameNode(returned)).to.be.true;
588 expect(returned.getWlxmlTag()).to.equal('header');
589 expect(returned.getWlxmlClass()).to.equal('some.class');
590 expect(children[1].children().length).to.equal(1);
591 expect(children[1].children()[0].getText()).to.equal(' has a ');
593 expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
594 expect(children[2].getText()).to.equal('cat');
598 it('wraps whole text inside DocumentTextElement if offsets span entire content', function() {
599 var c = canvas.fromXML('<section>Alice has a cat</section>'),
600 text = c.doc().children()[0];
602 var returned = text.wrapWithNodeElement({tag: 'header', klass: 'some.class', start: 0, end: 15}),
603 children = c.doc().children();
605 expect(children.length).to.equal(1);
606 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
607 expect(children[0].children()[0].getText()).to.equal('Alice has a cat');
611 it('wraps text spanning multiple sibling DocumentTextNodes', function() {
612 var c = canvas.fromXML('<section>Alice has a <span>small</span> cat</section>'),
614 wrapper = c.wrapText({
616 _with: {tag: 'span', klass: 'some.class'},
622 expect(section.children().length).to.equal(2);
623 expect(section.children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
624 expect(section.children()[0].getText()).to.equal('Alice ');
626 var wrapper2 = section.children()[1];
627 expect(wrapper2.sameNode(wrapper)).to.be.true;
629 var wrapperChildren = wrapper.children();
630 expect(wrapperChildren.length).to.equal(3);
631 expect(wrapperChildren[0].getText()).to.equal('has a ');
633 expect(wrapperChildren[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
634 expect(wrapperChildren[1].children().length).to.equal(1);
635 expect(wrapperChildren[1].children()[0].getText()).to.equal('small');
637 expect(wrapperChildren[2].getText()).to.equal(' cat');
641 describe('unwrapping', function() {
642 it('unwraps DocumentTextElement from its parent DocumentNodeElement if it\'s its only child', function() {
643 var c = canvas.fromXML('<section>Alice <span>has a</span> cat</section>'),
645 text = section.children()[1].children()[0];
647 var newTextContainer = text.unwrap();
649 expect(section.children().length).to.equal(1, 'section has one child');
650 expect(section.children()[0].getText()).to.equal('Alice has a cat');
651 expect(newTextContainer.sameNode(c.doc())).to.equal(true, 'unwrap returns new text parent DocumentNodeElement');
656 describe('Lists api', function() {
657 describe('creating lists', function() {
658 it('allows creation of a list from existing sibling DocumentElements', function() {
659 var c = canvas.fromXML('\
667 textHas = section.children()[1],
668 divA = section.children()[2]
670 c.list.create({element1: textHas, element2: divA});
672 expect(section.children().length).to.equal(3, 'section has three child elements');
674 var child1 = section.children()[0],
675 list = section.children()[1],
676 child3 = section.children()[2];
678 expect(child1.getText()).to.equal('Alice');
679 expect(list.is('list')).to.equal(true, 'second child is a list');
680 expect(list.children().length).to.equal(2, 'list contains two elements');
681 list.children().forEach(function(child) {
682 expect(child.getWlxmlClass()).to.equal('item', 'list childs have wlxml class of item');
684 expect(child3.children()[0].getText()).to.equal('cat');
687 it('allows creating nested list from existing sibling list items', function() {
688 var c = canvas.fromXML('\
690 <div class="list-items">\
691 <div class="item">A</div>\
692 <div class="item">B</div>\
693 <div class="item">C</div>\
694 <div class="item">D</div>\
697 outerList = c.doc().children()[0],
698 itemB = outerList.children()[1],
699 itemC = outerList.children()[2];
702 c.list.create({element1: itemB, element2: itemC});
704 var outerListItems = outerList.children(),
705 innerList = outerListItems[1].children()[0],
706 innerListItems = innerList.children();
708 expect(outerListItems.length).to.equal(3, 'outer list has three items');
709 expect(outerListItems[0].children()[0].getText()).to.equal('A', 'first outer item ok');
710 expect(outerListItems[1].getWlxmlClass()).to.equal('item', 'inner list is wrapped by item element');
712 expect(innerList.is('list')).to.equal(true, 'inner list created');
713 expect(innerListItems.length).to.equal(2, 'inner list has two items');
714 expect(innerListItems[0].children()[0].getText()).to.equal('B', 'first inner item ok');
715 expect(innerListItems[1].children()[0].getText()).to.equal('C', 'second inner item ok');
717 expect(outerListItems[2].children()[0].getText()).to.equal('D', 'last outer item ok');
723 describe('extracting list items', function() {
724 it('creates two lists with extracted items in the middle if extracting from the middle of the list', function() {
725 var c = canvas.fromXML('\
727 <div class="list.items">\
728 <div class="item">0</div>\
729 <div class="item">1</div>\
730 <div class="item">2</div>\
731 <div class="item">3</div>\
734 list = c.doc().children()[0],
735 item1 = list.children()[1],
736 item2 = list.children()[2];
738 c.list.extractItems({element1: item1, element2: item2});
740 var section = c.doc(),
741 list1 = section.children()[0],
742 oldItem1 = section.children()[1],
743 oldItem2 = section.children()[2],
744 list2 = section.children()[3];
746 expect(section.children().length).to.equal(4, 'section contains four children');
748 expect(list1.is('list')).to.equal(true, 'first section child is a list');
749 expect(list1.children().length).to.equal(1, 'first list has one child');
750 expect(list1.children()[0].children()[0].getText()).to.equal('0', 'first item of the first list is a first item of the original list');
752 expect(oldItem1.children()[0].getText()).to.equal('1', 'first item got extracted');
753 expect(oldItem1.getWlxmlClass() === undefined).to.equal(true, 'first extracted element has no wlxml class');
755 expect(oldItem2.children()[0].getText()).to.equal('2', 'second item got extracted');
756 expect(oldItem2.getWlxmlClass() === undefined).to.equal(true, 'second extracted element has no wlxml class');
758 expect(list2.is('list')).to.equal(true, 'last section child is a list');
759 expect(list2.children().length).to.equal(1, 'second list has one child');
760 expect(list2.children()[0].children()[0].getText()).to.equal('3', 'first item of the second list is a last item of the original list');
763 it('puts extracted items above the list if starting item is the first one', function() {
764 var c = canvas.fromXML('\
766 <div class="list.items">\
767 <div class="item">0</div>\
768 <div class="item">1</div>\
769 <div class="item">2</div>\
772 list = c.doc().children()[0],
773 item1 = list.children()[0],
774 item2 = list.children()[1],
775 item3 = list.children()[2];
777 c.list.extractItems({element1: item1, element2: item2});
779 var section = c.doc(),
780 oldItem1 = section.children()[0],
781 oldItem2 = section.children()[1],
782 newList = section.children()[2];
784 expect(section.children().length).to.equal(3, 'section has three children');
785 expect(oldItem1.children()[0].getText()).to.equal('0', 'first item extracted');
786 expect(oldItem2.children()[0].getText()).to.equal('1', 'second item extracted');
787 expect(newList.is('list')).to.equal(true, 'list lies below extracted item');
788 expect(newList.children().length).to.equal(1, 'list has now one child');
791 it('puts extracted items below the list if ending item is the last one', function() {
792 var c = canvas.fromXML('\
794 <div class="list.items">\
795 <div class="item">0</div>\
796 <div class="item">1</div>\
797 <div class="item">2</div>\
800 list = c.doc().children()[0],
801 item1 = list.children()[0],
802 item2 = list.children()[1],
803 item3 = list.children()[2];
805 c.list.extractItems({element1: item2, element2: item3});
807 var section = c.doc(),
808 oldItem1 = section.children()[1],
809 oldItem2 = section.children()[2],
810 newList = section.children()[0];
812 expect(section.children().length).to.equal(3, 'section has three children');
813 expect(oldItem1.children()[0].getText()).to.equal('1', 'first item extracted');
814 expect(oldItem2.children()[0].getText()).to.equal('2', 'second item extracted');
815 expect(newList.is('list')).to.equal(true, 'list lies above extracted item');
816 expect(newList.children().length).to.equal(1, 'list has now one child');
819 it('removes list if all its items are extracted', function() {
820 var c = canvas.fromXML('\
822 <div class="list.items">\
823 <div class="item">some item</div>\
824 <div class="item">some item 2</div>\
827 list = c.doc().children()[0],
828 item1 = list.children()[0],
829 item2 = list.children()[1];
831 c.list.extractItems({element1: item1, element2: item2});
833 var section = c.doc(),
834 list1 = section.children()[0],
835 oldItem1 = section.children()[0],
836 oldItem2 = section.children()[1];
838 expect(section.children().length).to.equal(2, 'section contains two children');
839 expect(oldItem1.children()[0].getText()).to.equal('some item');
840 expect(oldItem2.children()[0].getText()).to.equal('some item 2');
843 it('creates two lists with extracted items in the middle if extracting from the middle of the list - nested case' , function() {
844 var c = canvas.fromXML('\
846 <div class="list.items">\
847 <div class="item">0</div>\
849 <div class="list.items">\
850 <div class="item">1.1</div>\
851 <div class="item">1.2</div>\
852 <div class="item">1.3</div>\
855 <div class="item">2</div>\
858 list = c.doc().children()[0],
859 nestedList = list.children()[1].children()[0],
860 nestedListItem = nestedList.children()[1];
862 c.list.extractItems({element1: nestedListItem, element2: nestedListItem});
864 var section = c.doc(),
865 list = section.children()[0],
866 item1 = list.children()[0],
867 item2 = list.children()[1], //
868 item3 = list.children()[2],
869 item4 = list.children()[3], //
870 item5 = list.children()[4],
871 nestedList1 = item2.children()[0],
872 nestedList2 = item4.children()[0];
874 expect(list.children().length).to.equal(5, 'top list has five items');
876 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
878 expect(item2.getWlxmlClass()).to.equal('item', 'first nested list is still wrapped in item element');
879 expect(nestedList1.children().length).to.equal(1, 'first nested list is left with one child');
880 expect(nestedList1.children()[0].children()[0].getText()).to.equal('1.1', 'first nested list item left alone');
882 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
884 expect(item4.getWlxmlClass()).to.equal('item', 'second nested list is still wrapped in item element');
885 expect(nestedList2.children().length).to.equal(1, 'second nested list is left with one child');
886 expect(nestedList2.children()[0].children()[0].getText()).to.equal('1.3', 'second nested list item left alone');
888 expect(item5.children()[0].getText()).to.equal('2', 'last item ok');
891 it('puts extracted items below the list if ending item is the last one - nested case' , function() {
892 var c = canvas.fromXML('\
894 <div class="list.items">\
895 <div class="item">0</div>\
897 <div class="list.items">\
898 <div class="item">1.1</div>\
899 <div class="item">1.2</div>\
900 <div class="item">1.3</div>\
903 <div class="item">2</div>\
906 list = c.doc().children()[0],
907 nestedList = list.children()[1].children()[0],
908 nestedListItem1 = nestedList.children()[1],
909 nestedListItem2 = nestedList.children()[2];
911 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
913 var section = c.doc(),
914 list = section.children()[0],
915 item1 = list.children()[0],
916 item2 = list.children()[1],
917 item3 = list.children()[2],
918 item4 = list.children()[3],
919 item5 = list.children()[4];
920 nestedList = item2.children()[0];
922 expect(list.children().length).to.equal(5, 'top list has five items');
923 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
924 expect(item2.getWlxmlClass()).to.equal('item', 'nested list is still wrapped in item element');
925 expect(nestedList.children().length).to.equal(1, 'nested list is left with one child');
926 expect(nestedList.children()[0].children()[0].getText()).to.equal('1.1', 'nested list item left alone');
927 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
928 expect(item4.children()[0].getText()).to.equal('1.3', 'fourth item ok');
929 expect(item5.children()[0].getText()).to.equal('2', 'fifth item ok');
932 it('puts extracted items above the list if starting item is the first one - nested case' , function() {
933 var c = canvas.fromXML('\
935 <div class="list.items">\
936 <div class="item">0</div>\
938 <div class="list.items">\
939 <div class="item">1.1</div>\
940 <div class="item">1.2</div>\
941 <div class="item">1.3</div>\
944 <div class="item">2</div>\
947 list = c.doc().children()[0],
948 nestedList = list.children()[1].children()[0],
949 nestedListItem1 = nestedList.children()[0],
950 nestedListItem2 = nestedList.children()[1];
952 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
954 var section = c.doc(),
955 list = section.children()[0],
956 item1 = list.children()[0],
957 item2 = list.children()[1],
958 item3 = list.children()[2],
959 item4 = list.children()[3],
960 item5 = list.children()[4];
961 nestedList = item4.children()[0];
963 expect(list.children().length).to.equal(5, 'top list has five items');
964 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
965 expect(item2.children()[0].getText()).to.equal('1.1', 'second item ok');
966 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
968 expect(item4.getWlxmlClass()).to.equal('item', 'nested list is still wrapped in item element');
969 expect(nestedList.children().length).to.equal(1, 'nested list is left with one child');
970 expect(nestedList.children()[0].children()[0].getText()).to.equal('1.3', 'nested list item left alone');
971 expect(item5.children()[0].getText()).to.equal('2', 'fifth item ok');
974 it('removes list if all its items are extracted - nested case', function() {
975 var c = canvas.fromXML('\
977 <div class="list.items">\
978 <div class="item">0</div>\
980 <div class="list.items">\
981 <div class="item">1.1</div>\
982 <div class="item">1.2</div>\
985 <div class="item">2</div>\
988 list = c.doc().children()[0],
989 nestedList = list.children()[1].children()[0],
990 nestedListItem1 = nestedList.children()[0],
991 nestedListItem2 = nestedList.children()[1];
993 c.list.extractItems({element1: nestedListItem1, element2: nestedListItem2});
995 var section = c.doc(),
996 list = section.children()[0],
997 item1 = list.children()[0],
998 item2 = list.children()[1],
999 item3 = list.children()[2],
1000 item4 = list.children()[3];
1002 expect(list.children().length).to.equal(4, 'top list has four items');
1003 expect(item1.children()[0].getText()).to.equal('0', 'first item ok');
1004 expect(item2.children()[0].getText()).to.equal('1.1', 'second item ok');
1005 expect(item3.children()[0].getText()).to.equal('1.2', 'third item ok');
1006 expect(item4.children()[0].getText()).to.equal('2', 'fourth item ok');
1009 it('extracts items out of outer most list when merge flag is set to false', function() {
1010 var c = canvas.fromXML('\
1012 <div class="list.items">\
1013 <div class="item">0</div>\
1015 <div class="list.items">\
1016 <div class="item">1.1</div>\
1017 <div class="item">1.2</div>\
1020 <div class="item">2</div>\
1024 list = section.children()[0],
1025 nestedList = list.children()[1].children()[0],
1026 nestedListItem = nestedList.children()[0];
1028 var test = c.list.extractItems({element1: nestedListItem, element2: nestedListItem, merge: false});
1030 expect(test).to.equal(true, 'extraction status ok');
1032 var sectionChildren = section.children(),
1033 extractedItem = sectionChildren[1];
1035 expect(sectionChildren.length).to.equal(3, 'section has three children');
1036 expect(sectionChildren[0].is('list')).to.equal(true, 'first child is a list');
1038 expect(extractedItem.getWlxmlTag()).to.equal('div', 'extracted item is a wlxml div');
1039 expect(extractedItem.getWlxmlClass()).to.equal(undefined, 'extracted item has no wlxml class');
1040 expect(extractedItem.children()[0].getText()).to.equal('1.1', 'extracted item ok');
1041 expect(sectionChildren[2].is('list')).to.equal(true, 'second child is a list');
1048 describe('Cursor', function() {
1052 var findTextNode = function(inside, text) {
1053 var nodes = inside.find(':not(iframe)').addBack().contents().filter(function() {
1054 return this.nodeType === Node.TEXT_NODE && this.data === text;
1061 beforeEach(function() {
1062 getSelection = sinon.stub(window, 'getSelection');
1065 afterEach(function() {
1066 getSelection.restore();
1069 it('returns position when browser selection collapsed', function() {
1070 var c = canvas.fromXML('<section>Alice has a cat</section>'),
1071 dom = c.doc().dom(),
1072 text = findTextNode(dom, 'Alice has a cat');
1074 expect(text.nodeType).to.equal(Node.TEXT_NODE, 'correct node selected');
1075 expect($(text).text()).to.equal('Alice has a cat');
1077 getSelection.returns({
1084 var cursor = c.getCursor(),
1085 position = cursor.getPosition();
1087 expect(cursor.isSelecting()).to.equal(false, 'cursor is not selecting anything');
1088 expect(position.element.getText()).to.equal('Alice has a cat');
1089 expect(position.offset).to.equal(5);
1090 expect(position.offsetAtEnd).to.equal(false, 'offset is not at end');
1092 getSelection.returns({
1100 expect(cursor.getPosition().offsetAtEnd).to.equal(true, 'offset at end');
1103 it('returns boundries of selection when browser selection not collapsed', function() {
1104 var c = canvas.fromXML('<section>Alice <span>has</span> a <span>big</span> cat</section>'),
1105 dom = c.doc().dom(),
1107 alice: findTextNode(dom, 'Alice '),
1108 has: findTextNode(dom, 'has'),
1109 cat: findTextNode(dom, ' cat')
1111 cursor = c.getCursor(),
1112 aliceElement = c.getDocumentElement(text.alice),
1113 catElement = c.getDocumentElement(text.cat);
1117 {focus: text.alice, focusOffset: 1, anchor: text.cat, anchorOffset: 2, selectionAnchor: catElement},
1118 {focus: text.cat, focusOffset: 2, anchor: text.alice, anchorOffset: 1, selectionAnchor: aliceElement}
1119 ].forEach(function(s, idx) {
1120 getSelection.returns({isColapsed: false, anchorNode: s.anchor, anchorOffset: s.anchorOffset, focusNode: s.focus, focusOffset: s.focusOffset});
1122 var selectionStart = cursor.getSelectionStart(),
1123 selectionEnd = cursor.getSelectionEnd(),
1124 selectionAnchor = cursor.getSelectionAnchor();
1126 expect(cursor.isSelecting()).to.equal(true, 'cursor is selecting');
1127 expect(selectionStart.element.sameNode(aliceElement)).to.equal(true, '"Alice" is the start of the selection ' + idx);
1128 expect(selectionStart.offset).to.equal(1, '"Alice" offset ok' + idx);
1129 expect(selectionEnd.element.sameNode(catElement)).to.equal(true, '"Cat" is the start of the selection ' + idx);
1130 expect(selectionEnd.offset).to.equal(2, '"Cat" offset ok' + idx);
1131 expect(selectionAnchor.element.sameNode(s.selectionAnchor)).to.equal(true, 'anchor ok');
1132 expect(selectionAnchor.offset).to.equal(s.anchorOffset, 'anchor offset ok');
1136 it('recognizes when browser selection boundries lies in sibling DocumentTextElements', function() {
1137 var c = canvas.fromXML('<section>Alice <span>has</span> a <span>big</span> cat</section>'),
1138 dom = c.doc().dom(),
1140 alice: findTextNode(dom, 'Alice '),
1141 has: findTextNode(dom, 'has'),
1142 a: findTextNode(dom, ' a '),
1143 big: findTextNode(dom, 'big'),
1144 cat: findTextNode(dom, ' cat'),
1146 cursor = c.getCursor();
1148 expect($(text.alice).text()).to.equal('Alice ');
1149 expect($(text.has).text()).to.equal('has');
1150 expect($(text.a).text()).to.equal(' a ');
1151 expect($(text.big).text()).to.equal('big');
1152 expect($(text.cat).text()).to.equal(' cat');
1154 getSelection.returns({anchorNode: text.alice, focusNode: text.a});
1155 expect(cursor.isSelectingSiblings()).to.equal(true, '"Alice" and "a" are children');
1157 getSelection.returns({anchorNode: text.alice, focusNode: text.cat});
1158 expect(cursor.isSelectingSiblings()).to.equal(true, '"Alice" and "cat" are children');
1160 getSelection.returns({anchorNode: text.alice, focusNode: text.has});
1161 expect(cursor.isSelectingSiblings()).to.equal(false, '"Alice" and "has" are not children');
1163 getSelection.returns({anchorNode: text.has, focusNode: text.big});
1164 expect(cursor.isSelectingSiblings()).to.equal(false, '"has" and "big" are not children');
1168 describe('zero width space handling', function() {
1169 it('position range includes ZWS at the boundries of text in case when native selection api doesn\'t', function() {
1170 var c = canvas.fromXML("<section>Alice</section>"),
1171 dom = c.doc().dom(),
1172 textNode = findTextNode(dom, 'Alice'),
1173 cursor = c.getCursor();
1175 textNode.data = utils.unicode.ZWS + 'Alice';
1176 getSelection.returns({anchorNode: textNode, anchorOffset: 1, focusNode: textNode, focusOffset: 1});
1177 expect(cursor.getPosition().offset).to.equal(0);
1178 expect(cursor.getPosition().offsetAtBeginning).to.equal(true, 'offset at beginning');
1180 textNode.data = 'Alice' + utils.unicode.ZWS;
1181 getSelection.returns({anchorNode: textNode, anchorOffset: 5, focusNode: textNode, focusOffset: 5});
1182 expect(cursor.getPosition().offset).to.equal(6);
1183 expect(cursor.getPosition().offsetAtEnd).to.equal(true, 'offset at end');
1188 describe('Serializing document to WLXML', function() {
1189 it('keeps document intact when no changes have been made', function() {
1190 var xmlIn = '<section>Alice<div>has</div>a <span class="uri" meta-uri="http://cat.com">cat</span>!</section>',
1191 c = canvas.fromXML(xmlIn),
1194 var parser = new DOMParser(),
1195 input = parser.parseFromString(xmlIn, "application/xml").childNodes[0],
1196 output = parser.parseFromString(xmlOut, "application/xml").childNodes[0];
1198 expect(input.isEqualNode(output)).to.be.true;
1201 it('keeps arbitrary node attributes intact', function() {
1202 var xmlIn = '<section a="1" xmlns:dcterms="http://purl.org/dc/terms/"></section>',
1203 $xmlOut = $(canvas.fromXML(xmlIn).toXML());
1205 expect($xmlOut.attr('a')).to.equal('1');
1206 expect($xmlOut.attr('xmlns:dcterms')).to.equal('http://purl.org/dc/terms/');
1209 it('doesn\' serialize meta attribute if its empty', function() {
1212 c = canvas.fromXML('<section class="uri" meta-uri="some.uri"></section>');
1213 c.doc().setWlxmlMetaAttr('uri', '');
1214 expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'overriding attribute with zero length string');
1216 c = canvas.fromXML('<section class="uri"></section>');
1217 c.doc().setWlxmlMetaAttr('uri', '');
1218 expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'setting attribute to zero length string');
1221 describe('output xml', function() {
1222 it('keeps entities intact', function() {
1223 var xmlIn = '<section>< ></section>',
1224 c = canvas.fromXML(xmlIn),
1226 expect(xmlOut).to.equal(xmlIn);
1228 it('keeps entities intact when they form html/xml', function() {
1229 var xmlIn = '<section><abc></section>',
1230 c = canvas.fromXML(xmlIn),
1232 expect(xmlOut).to.equal(xmlIn);
1236 describe('formatting output xml', function() {
1237 /*it('keeps white spaces at the edges of input xml', function() {
1238 var xmlIn = ' <section></section> ',
1239 c = canvas.fromXML(xmlIn),
1242 expect(xmlOut.substr(4)).to.equal(' <', 'start');
1243 expect(xmlOut.substr(-2)).to.equal('> ', 'end');
1245 it('keeps white space between XML nodes', function() {
1246 var xmlIn = '<section>\n\n\n<div></div>\n\n\n<div></div>\n\n\n</section>',
1247 c = canvas.fromXML(xmlIn),
1250 var partsIn = xmlIn.split('\n\n\n'),
1251 partsOut = xmlOut.split('\n\n\n');
1253 expect(partsIn).to.deep.equal(partsOut);
1256 it('keeps white space between XML nodes - inline case', function() {
1257 var xmlIn = '<section>\n\n\n<span></span>\n\n\n<span></span>\n\n\n</section>',
1258 c = canvas.fromXML(xmlIn),
1261 var partsIn = xmlIn.split('\n\n\n'),
1262 partsOut = xmlOut.split('\n\n\n');
1264 expect(partsIn).to.deep.equal(partsOut);
1267 it('keeps white space at the beginning of text', function() {
1268 var xmlIn = '<section> abc<div>some div</div> abc</section>',
1269 c = canvas.fromXML(xmlIn),
1272 expect(xmlOut).to.equal(xmlIn);
1275 it('nests new children block elements', function() {
1276 var c = canvas.fromXML('<section></section>');
1278 c.doc().append({tag: 'header'});
1280 var xmlOut = c.toXML();
1281 expect(xmlOut.split('\n ')[0]).to.equal('<section>', 'nesting start ok');
1282 expect(xmlOut.split('\n').slice(-1)[0]).to.equal('</section>', 'nesting end ok');
1286 it('doesn\'t nest new children inline elements', function() {
1287 var c = canvas.fromXML('<section></section>');
1289 c.doc().append({tag: 'span'});
1291 var xmlOut = c.toXML();
1292 expect(xmlOut).to.equal('<section><span></span></section>');
1295 it('keeps original white space at the end of text', function() {
1297 var xmlIn = '<header> Some text ended with white space \
1299 <span class="uri">Some text</span> some text\
1302 c = canvas.fromXML(xmlIn);
1304 var xmlOut = c.toXML();
1305 console.log(xmlOut);
1306 expect(xmlOut).to.equal(xmlIn);
1309 it('keeps white space around text node', function() {
1310 var xmlIn = '<section>\
1311 <header>header1</header>\
1312 Some text surrounded by white space\
1313 <header>header2</header>\
1315 c = canvas.fromXML(xmlIn);
1317 var xmlOut = c.toXML();
1318 expect(xmlOut).to.equal(xmlIn);
1321 it('keeps white space around text node - last node case', function() {
1322 var xmlIn = '<section>\
1323 <header>header</header>\
1325 Some text surrounded by white space\
1328 c = canvas.fromXML(xmlIn);
1330 var xmlOut = c.toXML();
1331 expect(xmlOut).to.equal(xmlIn);
1334 it('keeps white space after detaching text element', function() {
1335 var xmlIn = '<section><header>header</header>\n\
1340 expectedXmlOut = '<section><header>header</header>\n\
1345 c = canvas.fromXML(xmlIn),
1346 children = c.doc().children(),
1347 text = children[children.length-1];
1349 expect(text.getText()).to.equal('text1');
1353 var xmlOut = c.toXML();
1354 expect(xmlOut).to.equal(expectedXmlOut);