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