From f607fcc0aded88a83313bfe4a6cae9d6f942b32e Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 20 Jun 2016 18:38:56 +0200 Subject: [PATCH] test using newest hyperjson. forget hyperscript --- www/assert/main.js | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/www/assert/main.js b/www/assert/main.js index 244e731e4..dc3c2087e 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -1,14 +1,12 @@ require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } }); define([ '/bower_components/jquery/dist/jquery.min.js', - '/bower_components/hyperjson/hyperjson.amd.js', // serializing classes as an attribute - '/common/hyperscript.js', // using setAttribute + '/bower_components/hyperjson/hyperjson.js', '/bower_components/textpatcher/TextPatcher.amd.js', 'json.sortify', -], function (jQuery, Hyperjson, Hyperscript, TextPatcher, Sortify) { +], function (jQuery, Hyperjson, TextPatcher, Sortify) { var $ = window.jQuery; window.Hyperjson = Hyperjson; - window.Hyperscript = Hyperscript; window.TextPatcher = TextPatcher; window.Sortify = Sortify; @@ -44,11 +42,11 @@ define([ var $body = $('body'); var HJSON_list = [ - '["DIV#target",{},[["P#bang",{"class":" alice bob charlie has.dot"},["pewpewpew"]]]]', + '["DIV",{"id":"target"},[["P",{"class":" alice bob charlie has.dot","id":"bang"},["pewpewpew"]]]]', - '["DIV#quot",{},[["P",{},["\\"pewpewpew\\""]]]]', + '["DIV",{"id":"quot"},[["P",{},["\\"pewpewpew\\""]]]]', - '["DIV#widget",{},[["DIV",{"class":"cke_widget_wrapper cke_widget_block","contenteditable":"false","data-cke-display-name":"macro:velocity","data-cke-filter":"off","data-cke-widget-id":"0","data-cke-widget-wrapper":"1","tabindex":"-1"},[["DIV",{"class":"macro cke_widget_element","data-cke-widget-data":"%7B%22classes%22%3A%7B%22macro%22%3A1%7D%7D","data-cke-widget-keep-attr":"0","data-cke-widget-upcasted":"1","data-macro":"startmacro:velocity|-||-|Here is a macro","data-widget":"xwiki-macro"},[["P",{},["Here is a macro"]]]],["SPAN",{"class":"cke_reset cke_widget_drag_handler_container","style":"background: rgba(220, 220, 220, 0.5) url(\\"/customize/cryptofist_small.png\\") repeat scroll 0% 0%; top: -15px; left: 0px; display: block;"},[["IMG",{"class":"cke_reset cke_widget_drag_handler","data-cke-widget-drag-handler":"1","height":"15","src":"data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==","title":"Click and drag to move","width":"15"},[]]]]]]]]', + '["DIV",{"id":"widget"},[["DIV",{"class":"cke_widget_wrapper cke_widget_block","contenteditable":"false","data-cke-display-name":"macro:velocity","data-cke-filter":"off","data-cke-widget-id":"0","data-cke-widget-wrapper":"1","tabindex":"-1"},[["DIV",{"class":"macro cke_widget_element","data-cke-widget-data":"%7B%22classes%22%3A%7B%22macro%22%3A1%7D%7D","data-cke-widget-keep-attr":"0","data-cke-widget-upcasted":"1","data-macro":"startmacro:velocity|-||-|Here is a macro","data-widget":"xwiki-macro"},[["P",{},["Here is a macro"]]]],["SPAN",{"class":"cke_reset cke_widget_drag_handler_container","style":"background: rgba(220, 220, 220, 0.5) url(\\"/customize/cryptofist_small.png\\") repeat scroll 0% 0%; top: -15px; left: 0px; display: block;"},[["IMG",{"class":"cke_reset cke_widget_drag_handler","data-cke-widget-drag-handler":"1","height":"15","src":"data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==","title":"Click and drag to move","width":"15"},[]]]]]]]]', ]; @@ -75,7 +73,7 @@ define([ } // turn it into a DOM - var DOM = Hyperjson.callOn(hjson, Hyperscript); + var DOM = Hyperjson.toDOM(hjson); // turn it back into stringified Hyperjson, but apply filters var shjson2 = Sortify(Hyperjson.fromDOM(DOM, elementFilter, attributeFilter)); @@ -83,7 +81,6 @@ define([ var success = shjson === shjson2; var op = TextPatcher.diff(shjson, shjson2); - //console.log(TextPatcher.format(shjson, op)); var diff = TextPatcher.format(shjson, op); @@ -98,18 +95,11 @@ define([ HJSON_list.map(HJSON_equal); - /* FIXME - This test is not correct. It passes in Firefox, but fails in Chrome, - even though for our purposes the produced code is valid. Passing - `

` through the function yields - `

`. This is the same element, but string - equality is not a correct metric. */ var roundTrip = function (sel) { var target = $(sel)[0]; assert(function () { var hjson = Hyperjson.fromDOM(target); - var cloned = Hyperjson.callOn(hjson, Hyperscript); - + var cloned = Hyperjson.toDOM(hjson); var success = cloned.outerHTML === target.outerHTML; if (!success) { @@ -120,7 +110,6 @@ define([ B: cloned.outerHTML, diff: op }; - //console.log(JSON.stringify(window.DEBUG, null, 2)); console.log("DIFF:"); TextPatcher.log(target.outerHTML, op); } @@ -131,7 +120,7 @@ define([ var HTML_list = [ '#target', - '#widget', // fails in Firefox 19? + '#widget', '#quot', ]; @@ -151,16 +140,6 @@ define([ strungJSON(orig); }); - //assert(function () { }, "this is expected to fail"); - - /* TODO Test how browsers handle weird elements - like "_moz-resizing":"true" - - and anything else you can think of. - - Start with Hyperjson, turn it into a DOM and come back - */ - var swap = function (str, dict) { return str.replace(/\{\{(.*?)\}\}/g, function (all, key) { return typeof dict[key] !== 'undefined'? dict[key] : all;