Update tests.

This commit is contained in:
Lars Jung 2016-07-02 02:40:34 +02:00
parent babb952485
commit 5bbc88b8e2
4 changed files with 44 additions and 33 deletions

View file

@ -4,6 +4,8 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>h5ai test suite</title> <title>h5ai test suite</title>
<link rel="stylesheet" href="h5ai-styles.css"> <link rel="stylesheet" href="h5ai-styles.css">
<script src="tests.js"></script>
</head> </head>
<body>
<script src="tests.js"></script>
</body>
</html> </html>

View file

@ -8,14 +8,3 @@ test('window is global object', () => {
test('document is global object', () => { test('document is global object', () => {
assert.equal(typeof global.document, 'object'); assert.equal(typeof global.document, 'object');
}); });
test('jQuery and $ are global functions', () => {
assert.equal(typeof global.jQuery, 'function');
assert.equal(global.jQuery.fn.jquery, '2.2.4');
assert.equal(global.jQuery, global.$);
});
test('_ is global function', () => {
assert.equal(typeof global._, 'function');
assert.equal(global._.VERSION, '4.13.1');
});

View file

@ -6,17 +6,13 @@ test('event is object', () => {
}); });
test('event has the right props', () => { test('event has the right props', () => {
assert.deepEqual(Object.keys(event), ['sub', 'unsub', 'pub']); assert.deepEqual(Object.keys(event), ['sub', 'pub']);
}); });
test('event.sub is function', () => { test('event.sub is function', () => {
assert.equal(typeof event.sub, 'function'); assert.equal(typeof event.sub, 'function');
}); });
test('event.unsub is function', () => {
assert.equal(typeof event.unsub, 'function');
});
test('event.pub is function', () => { test('event.pub is function', () => {
assert.equal(typeof event.pub, 'function'); assert.equal(typeof event.pub, 'function');
}); });

View file

@ -1,6 +1,6 @@
const win = global.window; const win = global.window;
const doc = win.document; const doc = win.document;
const jq = win.jQuery;
let title; let title;
let htmlId; let htmlId;
let htmlClasses; let htmlClasses;
@ -8,24 +8,48 @@ let bodyId;
let bodyClasses; let bodyClasses;
let $pinnedElements; let $pinnedElements;
function pinHtml() { const attr = (el, name, value) => {
title = doc.title; if (typeof el === 'string') {
htmlId = jq('html').attr('id'); el = doc.querySelector(el);
htmlClasses = jq('html').attr('class'); }
bodyId = jq('body').attr('id'); if (value === undefined) {
bodyClasses = jq('body').attr('class'); return el.getAttribute(name);
$pinnedElements = jq('head,body').children(); }
} if (value === null) {
return el.removeAttribute(name);
}
return el.setAttribute(name, value);
};
function restoreHtml() { const rootChildren = () => {
return [
...doc.querySelector('head').childNodes,
...doc.querySelector('body').childNodes
];
};
const pinHtml = () => {
title = doc.title;
htmlId = attr('html', 'id');
htmlClasses = attr('html', 'class');
bodyId = attr('body', 'id');
bodyClasses = attr('body', 'class');
$pinnedElements = rootChildren();
};
const restoreHtml = () => {
doc.title = title; doc.title = title;
jq('html').attr('id', htmlId); attr('html', 'id', htmlId);
jq('html').attr('class', htmlClasses); attr('html', 'class', htmlClasses);
jq('body').attr('id', bodyId); attr('body', 'id', bodyId);
jq('body').attr('class', bodyClasses); attr('body', 'class', bodyClasses);
jq('head,body').children().not($pinnedElements).remove(); rootChildren().forEach(el => {
if ($pinnedElements.indexOf(el) <= 0) {
el.remove();
}
});
win.localStorage.clear(); win.localStorage.clear();
} };
module.exports = { module.exports = {
pinHtml, pinHtml,