disable thumbnail test. add test for flat dom
This commit is contained in:
parent
02cd7e5b58
commit
df1a700cb2
@ -7,7 +7,8 @@ define([
|
|||||||
'/drive/tests.js',
|
'/drive/tests.js',
|
||||||
'/common/test.js',
|
'/common/test.js',
|
||||||
'/common/common-thumbnail.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.Hyperjson = Hyperjson;
|
||||||
window.TextPatcher = TextPatcher;
|
window.TextPatcher = TextPatcher;
|
||||||
window.Sortify = Sortify;
|
window.Sortify = Sortify;
|
||||||
@ -241,6 +242,7 @@ define([
|
|||||||
return cb(true);
|
return cb(true);
|
||||||
}, "version 2 hash failed to parse correctly");
|
}, "version 2 hash failed to parse correctly");
|
||||||
|
|
||||||
|
/*
|
||||||
assert(function (cb) {
|
assert(function (cb) {
|
||||||
var getBlob = function (url, cb) {
|
var getBlob = function (url, cb) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
@ -266,9 +268,21 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
Drive.test(assert);
|
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) {
|
var swap = function (str, dict) {
|
||||||
return str.replace(/\{\{(.*?)\}\}/g, function (all, key) {
|
return str.replace(/\{\{(.*?)\}\}/g, function (all, key) {
|
||||||
return typeof dict[key] !== 'undefined'? dict[key] : all;
|
return typeof dict[key] !== 'undefined'? dict[key] : all;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ define([], function () {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var identity = function (x) { return x; };
|
||||||
Flat.fromDOM = function (dom) {
|
Flat.fromDOM = function (dom) {
|
||||||
var data = {
|
var data = {
|
||||||
map: {},
|
map: {},
|
||||||
@ -26,18 +27,20 @@ define([], function () {
|
|||||||
var uid = function () { return i++; };
|
var uid = function () { return i++; };
|
||||||
|
|
||||||
var process = function (el) {
|
var process = function (el) {
|
||||||
if (!el || el.attributes) { return void console.error(el); }
|
var id;
|
||||||
var id = uid();
|
|
||||||
if (!el.tagName && el.nodeType === Node.TEXT_NODE) {
|
if (!el.tagName && el.nodeType === Node.TEXT_NODE) {
|
||||||
|
id = uid();
|
||||||
data.map[id] = el.textContent;
|
data.map[id] = el.textContent;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
if (!el || !el.attributes) { return void console.error(el); }
|
||||||
|
id = uid();
|
||||||
data.map[id] = [
|
data.map[id] = [
|
||||||
el.tagName,
|
el.tagName,
|
||||||
getAttrs(el),
|
getAttrs(el),
|
||||||
slice(el.childNodes).map(function (e) {
|
slice(el.childNodes).map(function (e) {
|
||||||
return process(e);
|
return process(e);
|
||||||
})
|
}).filter(identity)
|
||||||
];
|
];
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
@ -49,6 +52,7 @@ define([], function () {
|
|||||||
Flat.toDOM = function (data) {
|
Flat.toDOM = function (data) {
|
||||||
var visited = {};
|
var visited = {};
|
||||||
var process = function (key) {
|
var process = function (key) {
|
||||||
|
if (!key) { return; } // ignore falsey keys
|
||||||
if (visited[key]) {
|
if (visited[key]) {
|
||||||
// TODO handle this more gracefully.
|
// TODO handle this more gracefully.
|
||||||
throw new Error('duplicate id or loop detected');
|
throw new Error('duplicate id or loop detected');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user