1 define(function(require) {
4 /* globals describe, it */
6 var chai = require('libs/chai'),
7 wlxml = require('wlxml/wlxml'),
8 corePlugin = require('./core.js'),
11 var getDocumentFromXML = function(xml, options) {
12 var doc = wlxml.WLXMLDocumentFromXML(xml, options || {});
13 doc.registerExtension(corePlugin.documentExtension);
18 describe('Document extensions', function() {
19 describe('break content', function() {
20 it('break text into two nodes', function() {
21 var doc = getDocumentFromXML('<section><div>Alice</div></section>'),
22 textNode = doc.root.contents()[0].contents()[0];
24 var result = textNode.breakContent({offset:3});
26 var section = doc.root;
27 expect(section.contents().length).to.equal(2);
28 expect(section.contents()[0].contents()[0].getText()).to.equal('Ali');
29 expect(section.contents()[1].contents()[0].getText()).to.equal('ce');
31 expect(result.first.sameNode(section.contents()[0])).to.equal(true);
32 expect(result.second.sameNode(section.contents()[1])).to.equal(true);
33 expect(result.emptyText).to.equal(undefined, 'no new text node created');
35 it('puts empty text node when breaking at the very beginning', function() {
36 var doc = getDocumentFromXML('<section><div>Alice</div></section>'),
37 textNode = doc.root.contents()[0].contents()[0];
39 var result = textNode.breakContent({offset:0}),
40 firstNode = doc.root.contents()[0];
42 expect(result.emptyText.sameNode(firstNode.contents()[0]));
43 expect(result.emptyText.getText()).to.equal('');
45 it('puts empty text node when breaking at the very end', function() {
46 var doc = getDocumentFromXML('<section><div>Alice</div></section>'),
47 textNode = doc.root.contents()[0].contents()[0];
49 var result = textNode.breakContent({offset:5}),
50 secondNode = doc.root.contents()[1];
52 expect(result.emptyText.sameNode(secondNode.contents()[0]));
53 expect(result.emptyText.getText()).to.equal('');