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('getting previous node', function() {
\r
59 var c = new canvas.Canvas('<section><div class="some.class">Div 1</div><div class="some.other.class">Div 2</div></section>');
\r
60 var secondDiv = c.getNode({tag: 'div'})[1];
\r
61 var firstDiv = c.getPreviousNode({node: secondDiv});
\r
62 assert.equal(firstDiv.klass, 'some-class');
\r
65 test('pervious node of node without "previous siblings" is its parent', function() {
\r
66 var c = new canvas.Canvas('<section><div class="some.class">Div 1</div></section>');
\r
67 var div = c.getNode({tag: 'div'})[0];
\r
68 var section = c.getPreviousNode({node: div});
\r
69 assert.equal(section.tag, 'section');
\r
72 test('inserting after', function() {
\r
73 var c = new canvas.Canvas('<section><header>Header 1</header></section>');
\r
74 var header = c.getNode({tag: 'header'})[0];
\r
75 c.insertNode({place: 'after', context: header, tag: 'div', klass: 'some.class'});
\r
76 assert.xmlEqual(c.toXML(), '<section><header>Header 1</header><div class="some.class"></div></section>');
\r
79 test('wrap text in node', function() {
\r
80 var c = new canvas.Canvas('<section><header>Header 1</header></section>');
\r
81 var header = c.getNode({tag: 'header'})[0];
\r
82 c.insertNode({place: 'wrapText', context: header, tag: 'span', klass: 'url', offsetStart: 1, offsetEnd: 6});
\r
83 assert.xmlEqual(c.toXML(), '<section><header>H<span class="url">eader</span> 1</header></section>');
\r
86 test('split node', function() {
\r
87 var c = new canvas.Canvas('<section><header class="some.class">Header 1</header></section>');
\r
88 var header = c.getNode({tag: 'header'})[0];
\r
89 c.splitNode({node: header, offset: 4});
\r
90 assert.xmlEqual(c.toXML(), '\
\r
92 <header class="some.class">Head</header>\
\r
93 <header class="some.class">er 1</header>\
\r
98 test('split node with subnodes', function() {
\r
99 var c = new canvas.Canvas('<section><header class="some.class">Fancy and nice <span>header</span> 1</header></section>');
\r
100 var header = c.getNode({tag: 'header'})[0];
\r
101 c.splitNode({node: header, textNodeIdx: 0, offset: 5});
\r
102 assert.xmlEqual(c.toXML(), '\
\r
104 <header class="some.class">Fancy</header>\
\r
105 <header class="some.class"> and nice <span>header</span> 1</header>\
\r
110 test('remove node', function() {
\r
111 var c = new canvas.Canvas('<section><header class="some.class">Fancy and nice <span>header</span> 1</header></section>');
\r
112 var span = c.getNode({tag: 'span'})[0];
\r
113 var siblings = c.removeNode({node:span});
\r
114 assert.xmlEqual(c.toXML(), '\
\r
116 <header class="some.class">Fancy and nice 1</header>\
\r
121 test('list', function() {
\r
122 var c = new canvas.Canvas('<section><div>Alice</div>has<div>a cat</div></section>');
\r
123 var div1 = c.getNode({tag:'div'})[0];
\r
124 var div2 = c.getNode({tag:'div'})[1];
\r
126 c.createList({start: div1, end: div2});
\r
128 assert.xmlEqual(c.toXML(), '\
\r
130 <div class="list">\
\r
131 <div class="list.item">Alice</div>\
\r
132 <div class="list.item">has</div>\
\r
133 <div class="list.item">a cat</div>\
\r