fixing markup in a template
[fnpeditor.git] / modules / documentCanvas / tests / utils.js
1 define(['libs/jquery-1.9.1.min', 'libs/chai'], function($, chai) {
2     return {
3         cleanUp: function(xml) {
4             var rmws = function(node) {
5                 if(node.nodeType === 3) {
6                     node.data = $.trim(node.data);
7                 }
8                 else {
9                     $(node).contents().each(function() {
10                         rmws(this);
11                     });
12                 }
13             };
14             
15             xml = $($.trim(xml));
16             xml.each(function() {
17                 rmws(this);
18             });
19             
20             /*var toret = xml
21                 .replace(/(<.*>)\s*(<.*>)/gm, '$1$2')
22                 .replace(/(<\/.*>)\s*(<\/.*>)/gm, '$1$2')
23                 .replace(/(<\/.*>)\s*(<.*>)/gm, '$1$2');
24             return $.trim(toret);*/
25             return $('<div>').append(xml).html();
26         },
27         
28         assertDomEqual: function(lhs, rhs) {
29             lhs = lhs.clone();
30             var rhsArr = $.parseHTML(rhs);
31             if(rhsArr.length === 1) {
32                 rhs = $(rhsArr[0]);
33             } else {
34                 rhs = $('<div>');
35                 $.each(rhsArr, function(i, el) {
36                     rhs.append(el);
37                 });            
38             }
39             if(lhs.length > 1) {
40                 lhs = $('<div>').append(lhs);
41             }
42             lhs.attr('id', '');
43             rhs.attr('id', '');
44             lhs.find('*').each(function() {$(this).attr('id', '');});
45             rhs.find('*').each(function() {$(this).attr('id', '');});
46             return chai.assert.ok(lhs[0].isEqualNode(rhs[0]), 'nodes are equal');
47         }
48     };
49 });