Adding jshint grunt task
[fnpeditor.git] / modules / documentCanvas / tests / utils.js
index e23808c..cf1f7c2 100644 (file)
@@ -1,7 +1,6 @@
-define(['libs/jquery-1.9.1.min'], function($) {\r
+define(['libs/jquery-1.9.1.min', 'libs/chai'], function($, chai) {\r
     return {\r
         cleanUp: function(xml) {\r
-            \r
             var rmws = function(node) {\r
                 if(node.nodeType === 3) {\r
                     node.data = $.trim(node.data);\r
@@ -24,6 +23,27 @@ define(['libs/jquery-1.9.1.min'], function($) {
                 .replace(/(<\/.*>)\s*(<.*>)/gm, '$1$2');\r
             return $.trim(toret);*/\r
             return $('<div>').append(xml).html();\r
+        },\r
+        \r
+        assertDomEqual: function(lhs, rhs) {\r
+            lhs = lhs.clone();\r
+            var rhsArr = $.parseHTML(rhs);\r
+            if(rhsArr.length === 1) {\r
+                rhs = $(rhsArr[0]);\r
+            } else {\r
+                rhs = $('<div>');\r
+                $.each(rhsArr, function(i, el) {\r
+                    rhs.append(el);\r
+                });            \r
+            }\r
+            if(lhs.length > 1) {\r
+                lhs = $('<div>').append(lhs);\r
+            }\r
+            lhs.attr('id', '');\r
+            rhs.attr('id', '');\r
+            lhs.find('*').each(function() {$(this).attr('id', '');});\r
+            rhs.find('*').each(function() {$(this).attr('id', '');});\r
+            return chai.assert.ok(lhs[0].isEqualNode(rhs[0]), 'nodes are equal');\r
         }\r
     }\r
 });
\ No newline at end of file