2 'libs/jquery-1.9.1.min',
\r
5 'modules/documentCanvas/canvas',
\r
6 'modules/documentCanvas/canvasNode'
\r
7 ], function($, chai, utils, canvas, canvasNode) {
\r
11 var assert = chai.assert;
\r
12 var assertDomEqual = utils.assertDomEqual;
\r
15 suite('Quering nodes', function() {
\r
16 test('getting preceding node', function() {
\r
17 var c = canvas.create('<div wlxml-tag="section"><div wlxml-tag="p">a</div><div wlxml-tag="p">b</div></div>');
\r
18 var secondP = c.findNodes({tag: 'p'})[1];
\r
19 var firstP = c.getPrecedingNode({node: secondP});
\r
20 assert.equal(firstP.getContent(), 'a');
\r
23 test('pervious node of node without "previous siblings" is its parent', function() {
\r
24 var c = canvas.create('<div wlxml-tag="section"><div wlxml-tag="p">a</div></div>');
\r
25 var paragraph = c.findNodes({tag: 'p'})[0];
\r
26 assert.equal(c.getPrecedingNode({node: paragraph}).getTag(), 'section');
\r
32 suite('Inserting nodes', function() {
\r
33 test('append node to root', function() {
\r
34 var c = canvas.create();
\r
35 var node = canvasNode.create({tag: 'header', klass: 'some-class'});
\r
36 c.nodeAppend({node: node, to: 'root'});
\r
37 assertDomEqual(c.getContent(), '<div wlxml-tag="header" wlxml-class="some-class">');
\r
40 test('append node to another node', function() {
\r
41 var c = canvas.create('<div wlxml-tag="section"></div>');
\r
42 var node = canvasNode.create({tag: 'header', klass: 'some-class'});
\r
43 var to = c.findNodes('div')[0];
\r
44 c.nodeAppend({node: node, to: to});
\r
45 assertDomEqual(c.getContent(), '<div wlxml-tag="section"><div wlxml-tag="header" wlxml-class="some-class"></div></div>');
\r
48 test('insert node after another node', function() {
\r
49 var c = canvas.create('<div wlxml-tag="section"></div>');
\r
50 var node = canvasNode.create({tag: 'header', klass: 'some-class'});
\r
51 var after = c.findNodes('div')[0];
\r
52 c.nodeInsertAfter({node: node, after: after});
\r
53 assertDomEqual(c.getContent(), '<div wlxml-tag="section"></div><div wlxml-tag="header" wlxml-class="some-class"></div>');
\r
56 test('wrap text in node', function() {
\r
57 var c = canvas.create('<div wlxml-tag="section"><div wlxml-tag="header">Header 1</div></div>');
\r
58 var header = c.findNodes({tag: 'header'})[0];
\r
59 var wrapper = canvasNode.create({tag: 'aside'});
\r
60 c.nodeWrap({inside: header, _with: wrapper, offsetStart: 1, offsetEnd: 6})
\r
61 assertDomEqual(c.getContent(), '<div wlxml-tag="section"><div wlxml-tag="header">H<span wlxml-tag="aside">eader</span> 1</div></div>');
\r
64 test('split node', function() {
\r
65 var c = canvas.create('<div wlxml-tag="section"><div wlxml-tag="header">Header 1</div></div>');
\r
66 var header = c.findNodes({tag: 'header'})[0];
\r
67 var newNode = c.nodeSplit({node: header, offset: 4});
\r
68 assertDomEqual(c.getContent(), utils.cleanUp('\
\r
69 <div wlxml-tag="section">\
\r
70 <div wlxml-tag="header">Head</div>\
\r
71 <div wlxml-tag="header">er 1</div>\
\r
73 assert.ok(newNode.isSame(c.findNodes({tag: 'header'})[1]));
\r
76 test('split root node', function() {
\r
77 var c = canvas.create('<div wlxml-tag="header">cat</div>');
\r
78 var header = c.findNodes({tag: 'header'})[0];
\r
79 var newNode = c.nodeSplit({node: header, offset: 1});
\r
80 assertDomEqual(c.getContent(), utils.cleanUp('\
\r
81 <div wlxml-tag="header">c</div>\
\r
82 <div wlxml-tag="header">at</div>'));
\r
83 assert.ok(newNode.isSame(c.findNodes({tag: 'header'})[1]));
\r
86 test('split node with subnodes', function() {
\r
87 var c = canvas.create(utils.cleanUp('\
\r
88 <div wlxml-tag="section">\
\r
89 <div wlxml-tag="header">Fancy and nice<span wlxml-tag="aside">header</span> 1</div>\
\r
91 var header = c.findNodes({tag: 'header'})[0];
\r
92 var newNode = c.nodeSplit({node: header, offset: 5});
\r
93 assertDomEqual(c.getContent(), utils.cleanUp('\
\r
94 <div wlxml-tag="section">\
\r
95 <div wlxml-tag="header">Fancy</div>\
\r
96 <div wlxml-tag="header">and nice<span wlxml-tag="aside">header</span> 1</div>\
\r
100 test('remove node', function() {
\r
101 var c = canvas.create('<div wlxml-tag="section"><span wlxml-tag="span">some text</span></div>');
\r
102 var span = c.findNodes({tag: 'span'})[0];
\r
103 c.nodeRemove({node: span});
\r
104 assertDomEqual(c.getContent(), '<div wlxml-tag="section"></div>');
\r
109 suite('Lists', function() {
\r
110 test('create from existing nodes', function() {
\r
111 var c = canvas.create(utils.cleanUp('\
\r
112 <div wlxml-tag="section">\
\r
113 <div wlxml-tag="div">alice</div>\
\r
115 <div wlxml-tag="div">a</div>\
\r
116 <div wlxml-tag="div">cat</div>\
\r
117 <div wlxml-tag="div">or not</div>\
\r
121 var div_alice = c.findNodes({tag: 'div'})[0];
\r
122 var div_cat = c.findNodes({tag:'div'})[2];
\r
124 c.listCreate({start: div_alice, end: div_cat});
\r
126 assertDomEqual(c.getContent(), utils.cleanUp('\
\r
127 <div wlxml-tag="section">\
\r
128 <div wlxml-tag="div" wlxml-class="list-items">\
\r
129 <div wlxml-tag="div" wlxml-class="item">alice</div>\
\r
130 <div wlxml-tag="div" wlxml-class="item">has</div>\
\r
131 <div wlxml-tag="div" wlxml-class="item">a</div>\
\r
132 <div wlxml-tag="div" wlxml-class="item">cat</div>\
\r
134 <div wlxml-tag="div">or not</div>\
\r
138 test('create from existing nodes - start/end order doesn\'t matter', function() {
\r
139 var html = utils.cleanUp('\
\r
140 <div wlxml-tag="div">alice</div>\
\r
141 <div wlxml-tag="div">cat</div>');
\r
142 var expected = utils.cleanUp('\
\r
143 <div wlxml-tag="div" wlxml-class="list-items">\
\r
144 <div wlxml-tag="div" wlxml-class="item">alice</div>\
\r
145 <div wlxml-tag="div" wlxml-class="item">cat</div>\
\r
148 var c = canvas.create(html);
\r
149 var div_alice = c.findNodes({tag: 'div'})[0];
\r
150 var div_cat = c.findNodes({tag:'div'})[1];
\r
151 c.listCreate({start: div_cat, end: div_alice});
\r
152 assertDomEqual(c.getContent(), expected);
\r
154 c = canvas.create(html);
\r
155 div_alice = c.findNodes({tag: 'div'})[0];
\r
156 div_cat = c.findNodes({tag:'div'})[1];
\r
157 c.listCreate({start: div_alice, end: div_cat});
\r
158 assertDomEqual(c.getContent(), expected);
\r
161 test('remove', function() {
\r
162 var c = canvas.create(utils.cleanUp('\
\r
163 <div wlxml-tag="section">\
\r
164 <div wlxml-tag="div" wlxml-class="list-items">\
\r
165 <div wlxml-tag="div" wlxml-class="item">alice</div>\
\r
166 <div wlxml-tag="div" wlxml-class="item">cat</div>\
\r
169 var item = c.findNodes({klass: 'item'})[1];
\r
170 c.listRemove({pointer: item});
\r
171 assertDomEqual(c.getContent(), utils.cleanUp('\
\r
172 <div wlxml-tag="section">\
\r
173 <div wlxml-tag="div">alice</div>\
\r
174 <div wlxml-tag="div">cat</div>\
\r