8f779d30c485fedc2124b65d890854dfd310f411
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.test3.js
1 define([
2 'libs/chai',
3 'modules/documentCanvas/canvas/canvas',
4 'modules/documentCanvas/canvas/documentElement'
5 ], function(chai, canvas, documentElement) {
6     
7 'use strict';
8
9 var expect = chai.expect;
10
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);
16         });
17
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');
21         });
22     });
23
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);
29             });
30             it('is of type DocumentNodeElement', function() {
31                 expect(c.doc()).to.be.instanceOf(documentElement.DocumentNodeElement);
32             });
33         });
34
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);
41
42                 c = canvas.fromXML('<section><div></div><div></div></section>'),
43                     children = c.doc().children();
44                 expect(children.length).to.equal(2);
45                 expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
46                 expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
47             });
48             it('reports text nodes', function() {
49                 var c = canvas.fromXML('<section>Alice</section>'),
50                     children = c.doc().children();
51                 expect(children.length).to.equal(1);
52                 expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
53             });
54             describe('free text handling', function() {
55                     it('sees free text', function() {
56                         var c = canvas.fromXML('<section>Alice <span>has</span> a cat</section>'),
57                             children = c.doc().children();
58                         expect(children.length).to.equal(3);
59                         expect(children[0]).to.be.instanceOf(documentElement.DocumentTextElement);
60                         expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
61                         expect(children[2]).to.be.instanceOf(documentElement.DocumentTextElement);
62                     });
63             });
64             describe('white characters handling', function() {
65                 it('says empty element node has no children', function() {
66                     var c = canvas.fromXML('<section></section>');
67                     expect(c.doc().children().length).to.equal(0);
68                 });
69                 it('says element node with one space has one DocumentTextElement', function() {
70                     var c = canvas.fromXML('<section> </section>');
71                     expect(c.doc().children().length).to.equal(1);
72                     expect(c.doc().children()[0]).to.be.instanceOf(documentElement.DocumentTextElement);
73                 });
74                 it('ignores white space surrounding block elements', function() {
75                     var c = canvas.fromXML('<section> <div></div> </section>');
76                         var children = c.doc().children();
77                         expect(children.length).to.equal(1);
78                         expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
79                 });
80                 it('ignores white space between block elements', function() {
81                     var c = canvas.fromXML('<section><div></div> <div></div></section>');
82                         var children = c.doc().children();
83                         expect(children.length === 2);
84                         [0,1].forEach(function(idx) {
85                             expect(children[idx]).to.be.instanceOf(documentElement.DocumentNodeElement);
86                         });
87                 });
88             });
89         })
90
91     });
92 });
93
94 /*describe('Canvas', function() {
95     it('can wrap selected document nodes in a list', function() {
96         var c = canvas.fromXML('\
97             <section>\
98                 <div>Alice</div>\
99                 <div>has</div>\
100                 <div>a cat</div>\
101             </section>
102         ');
103         var div_alice   = c.doc().children({tag: 'div'})[0];
104         var div_cat     = c.doc().children({tag: 'div'})[2];
105         c.doc.wrapInList({start: div_alice, end: div_cat});
106
107         expect(c.doc().children().length === 3)
108
109
110     })
111 });*/
112
113
114
115
116 });