disable thumbnail test. add test for flat dom

pull/1/head
ansuz 7 years ago
parent 02cd7e5b58
commit df1a700cb2

@ -7,7 +7,8 @@ define([
'/drive/tests.js',
'/common/test.js',
'/common/common-thumbnail.js',
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad, Drive, Test, Thumb) {
'/common/flat-dom.js',
], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad, Drive, Test, Thumb, Flat) {
window.Hyperjson = Hyperjson;
window.TextPatcher = TextPatcher;
window.Sortify = Sortify;
@ -241,6 +242,7 @@ define([
return cb(true);
}, "version 2 hash failed to parse correctly");
/*
assert(function (cb) {
var getBlob = function (url, cb) {
var xhr = new XMLHttpRequest();
@ -266,9 +268,21 @@ define([
});
});
});
*/
Drive.test(assert);
assert(function (cb) {
// extract dom elements into a flattened JSON representation
var flat = Flat.fromDOM(document.body);
// recreate a _mostly_ equivalent DOM
var dom = Flat.toDOM(flat);
// assume we don't care about comments
var bodyText = document.body.outerHTML.replace(/<!\-\-[\s\S]*?\-\->/g, '')
// check for equality
cb(dom.outerHTML === bodyText);
});
var swap = function (str, dict) {
return str.replace(/\{\{(.*?)\}\}/g, function (all, key) {
return typeof dict[key] !== 'undefined'? dict[key] : all;

@ -17,6 +17,7 @@ define([], function () {
return data;
};
var identity = function (x) { return x; };
Flat.fromDOM = function (dom) {
var data = {
map: {},
@ -26,18 +27,20 @@ define([], function () {
var uid = function () { return i++; };
var process = function (el) {
if (!el || el.attributes) { return void console.error(el); }
var id = uid();
var id;
if (!el.tagName && el.nodeType === Node.TEXT_NODE) {
id = uid();
data.map[id] = el.textContent;
return id;
}
if (!el || !el.attributes) { return void console.error(el); }
id = uid();
data.map[id] = [
el.tagName,
getAttrs(el),
slice(el.childNodes).map(function (e) {
return process(e);
})
}).filter(identity)
];
return id;
};
@ -49,6 +52,7 @@ define([], function () {
Flat.toDOM = function (data) {
var visited = {};
var process = function (key) {
if (!key) { return; } // ignore falsey keys
if (visited[key]) {
// TODO handle this more gracefully.
throw new Error('duplicate id or loop detected');

Loading…
Cancel
Save