3 'modules/documentCanvas/canvas/canvas',
4 'modules/documentCanvas/canvas/documentElement'
5 ], function(chai, canvas, documentElement) {
9 var expect = chai.expect;
11 describe('Canvas', function() {
12 describe('basic properties', function() {
13 it('renders empty document when canvas created from empty XML', function() {
14 var c = canvas.fromXML('');
15 expect(c.doc()).to.equal(null);
18 it('gives access to its document root node', function() {
19 var c = canvas.fromXML('<section></section>');
20 expect(c.doc().wlxmlTag).to.equal('section');
24 describe('document representation api', function() {
25 describe('document root element', function() {
26 var c = canvas.fromXML('<section></section>');
27 it('exists', function() {
28 expect(c.doc()).to.be.instanceOf(documentElement.DocumentElement);
30 it('is of type DocumentNodeElement', function() {
31 expect(c.doc()).to.be.instanceOf(documentElement.DocumentNodeElement);
35 describe('traversing', function() {
36 it('reports element nodes', function() {
37 var c = canvas.fromXML('<section><div></div></section>'),
38 children = c.doc().children();
39 expect(children.length).to.equal(1);
40 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
42 it('reports text nodes', function() {
43 var c = canvas.fromXML('<section>Alice</section>'),
44 children = c.doc().children();
45 expect(children.length).to.equal(1);
46 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
48 describe('free text handling', function() {
49 it('sees free text', function() {
50 var c = canvas.fromXML('<section>Alice <span>has</span> a cat</section>'),
51 children = c.doc().children();
52 expect(children.length).to.equal(3);
53 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
54 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
55 expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
58 describe('white characters handling', function() {
59 it('says empty element node has no children', function() {
60 var c = canvas.fromXML('<section></section>');
61 expect(c.doc().children().length).to.equal(0);
63 it('says element node with one space has one DocumentTextElement', function() {
64 var c = canvas.fromXML('<section> </section>');
65 expect(c.doc().children().length).to.equal(1);
66 expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
68 it('ignores white space surrounding block elements', function() {
69 var c = canvas.fromXML('<section> <div></div> </section>');
70 var children = c.doc().children();
71 expect(children.length).to.equal(1);
72 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
74 it('ignores white space between block elements', function() {
75 var c = canvas.fromXML('<section><div></div> <div></div></section>');
76 var children = c.doc().children();
77 expect(children.length === 2);
78 [0,1].forEach(function(idx) {
79 expect(children[idx]).to.be.instanceOf(documentElement.DocumentNodeElement);
88 /*describe('Canvas', function() {
89 it('can wrap selected document nodes in a list', function() {
90 var c = canvas.fromXML('\
97 var div_alice = c.doc().children({tag: 'div'})[0];
98 var div_cat = c.doc().children({tag: 'div'})[2];
99 c.doc.wrapInList({start: div_alice, end: div_cat});
101 expect(c.doc().children().length === 3)