2 'libs/jquery-1.9.1.min',
\r
5 'modules/documentCanvas/canvas'
\r
6 ], function($, chai, utils, canvas) {
\r
10 var assert = chai.assert;
\r
12 assert.xmlEqual = function(lhsText, rhsText) {
\r
13 var cleanLhs = utils.cleanUp(lhsText);
\r
14 var cleanRhs = utils.cleanUp(rhsText);
\r
16 var lhs = $(cleanLhs);
\r
17 var rhs = $(cleanRhs);
\r
19 this.equal(lhs.length, 1);
\r
20 this.equal(rhs.length, 1);
\r
25 var test = lhs.isEqualNode(rhs);
\r
27 console.log(cleanLhs);
\r
28 console.log(cleanRhs);
\r
30 return this.ok(test, 'xmls are equal');
\r
33 var retrievingTest = function(title, xml) {
\r
34 test(title, function() {
\r
35 var c = new canvas.Canvas(xml);
\r
36 assert.xmlEqual(c.toXML(), xml);
\r
40 suite('Basic document retrieving', function() {
\r
41 test('empty document', function() {
\r
42 var c = new canvas.Canvas('');
\r
43 assert.equal(c.toXML(), '');
\r
45 retrievingTest('empty tag', '<section></section>');
\r
46 retrievingTest('tag with content', '<section>Some text</section>');
\r
47 retrievingTest('tag with class', '<section class="some.class"></section>');
\r
50 suite('Nodes', function() {
\r
51 test('getting nodes via selector', function() {
\r
52 var c = new canvas.Canvas('<section><header class="some.class">Header 1</header></section>');
\r
53 var header = c.getNode({tag: 'header'})[0];
\r
54 assert.equal(header.tag, 'header');
\r
55 assert.equal(header.klass, 'some-class');
\r
58 test('inserting after', function() {
\r
59 var c = new canvas.Canvas('<section><header>Header 1</header></section>');
\r
60 var header = c.getNode({tag: 'header'})[0];
\r
61 c.insertNode({place: 'after', context: header, tag: 'div', klass: 'some.class'});
\r
62 assert.xmlEqual(c.toXML(), '<section><header>Header 1</header><div class="some.class"></div></section>');
\r
65 test('wrap text in node', function() {
\r
66 var c = new canvas.Canvas('<section><header>Header 1</header></section>');
\r
67 var header = c.getNode({tag: 'header'})[0];
\r
68 c.insertNode({place: 'wrapText', context: header, tag: 'span', klass: 'url', offsetStart: 1, offsetEnd: 6});
\r
69 assert.xmlEqual(c.toXML(), '<section><header>H<span class="url">eader</span> 1</header></section>');
\r
72 test('split node', function() {
\r
73 var c = new canvas.Canvas('<section><header class="some.class">Header 1</header></section>');
\r
74 var header = c.getNode({tag: 'header'})[0];
\r
75 c.splitNode({node: header, offset: 4});
\r
76 assert.xmlEqual(c.toXML(), '\
\r
78 <header class="some.class">Head</header>\
\r
79 <header class="some.class">er 1</header>\
\r
84 test('split node with subnodes', function() {
\r
85 var c = new canvas.Canvas('<section><header class="some.class">Fancy and nice <span>header</span> 1</header></section>');
\r
86 var header = c.getNode({tag: 'header'})[0];
\r
87 c.splitNode({node: header, textNodeIdx: 0, offset: 5});
\r
88 assert.xmlEqual(c.toXML(), '\
\r
90 <header class="some.class">Fancy</header>\
\r
91 <header class="some.class"> and nice <span>header</span> 1</header>\
\r
96 test('remove node', function() {
\r
97 var c = new canvas.Canvas('<section><header class="some.class">Fancy and nice <span>header</span> 1</header></section>');
\r
98 var span = c.getNode({tag: 'span'})[0];
\r
99 var siblings = c.removeNode({node:span});
\r
100 assert.xmlEqual(c.toXML(), '\
\r
102 <header class="some.class">Fancy and nice 1</header>\
\r
107 test('list', function() {
\r
108 var c = new canvas.Canvas('<section><div>Alice</div>has<div>a cat</div></section>');
\r
109 var div1 = c.getNode({tag:'div'})[0];
\r
110 var div2 = c.getNode({tag:'div'})[1];
\r
112 c.createList({start: div1, end: div2});
\r
114 assert.xmlEqual(c.toXML(), '\
\r
116 <div class="list">\
\r
117 <div class="list.item">Alice</div>\
\r
118 <div class="list.item">has</div>\
\r
119 <div class="list.item">a cat</div>\
\r