smartxml: Fixing Document.containsNode
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / utils.test.js
1 define([
2 'libs/chai',
3 'modules/documentCanvas/canvas/utils'
4
5 ], function(chai, utils) {
6
7 'use strict';
8
9 var expect = chai.expect;
10
11
12 describe('utils.nearestInDocumentOrder', function() {
13
14
15     var tests = [
16         ['return null if no match found',
17             '<span>\
18                 <span></span>\
19                 <div id="b">\
20                 <span></span>\
21             </span>'
22         ],
23         ['returns nearest sibling if applicable',
24             '<div n1>\
25                 <div n2></div>\
26                 <div n3>\
27                     <div id="a"></div>\
28                     <div id="b"></div>\
29                     <div id="c"></div>\
30                 </div>\
31                 <div n4></div>\
32             </div>'
33         ],
34         ['looks inside siblings children',
35             '<div>\
36                 <div></div>\
37                 <div>\
38                     <div></div>\
39                     <span>\
40                         <div id="a"></div>\
41                     </span>\
42                     <div id="b"></div>\
43                     <span>\
44                         <div id="c"></div>\
45                     </span>\
46                     <div></div>\
47                 </div>\
48                 <div></div>\
49             </div>'
50         ]
51
52
53     ];
54
55     tests.forEach(function(test) {
56         var description = test[0],
57             html = test[1];
58         it(description, function() {
59             var dom = $(html),
60                 a = dom.find('#a').length ? dom.find('#a')[0] : null,
61                 b = dom.find('#b')[0],
62                 c = dom.find('#c').length ? dom.find('#c')[0] : null;
63             expect(utils.nearestInDocumentOrder('div', 'above', b)).to.equal(a, 'above');
64             expect(utils.nearestInDocumentOrder('div', 'below', b)).to.equal(c, 'below');
65         });
66     });
67
68 });
69
70 });