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