'use strict'; var BrandingDomRenderer = require('../temp/tests/BrandingDomRenderer').BrandingDomRenderer; var passed = 0; function assert(condition, message) { if (!condition) { throw new Error(message); } passed++; } function FakeNode(name, text) { this.nodeName = name; this.text = text || ''; this.children = []; this.attributes = {}; this.parentNode = null; this.style = { values: {}, setProperty: function (key, value) { this.values[key] = value; } }; } Object.defineProperty(FakeNode.prototype, 'firstChild', { get: function () { return this.children.length ? this.children[0] : null; } }); FakeNode.prototype.appendChild = function (child) { child.parentNode = this; this.children.push(child); return child; }; FakeNode.prototype.removeChild = function (child) { this.children.splice(this.children.indexOf(child), 1); child.parentNode = null; }; FakeNode.prototype.setAttribute = function (name, value) { this.attributes[name] = value; }; global.document = { createElement: function (name) { return new FakeNode(name); }, createTextNode: function (text) { return new FakeNode('#text', text); } }; var host = new FakeNode('host'); host.appendChild(new FakeNode('old')); new BrandingDomRenderer().render(host, [{ type: 'section', attributes: { class: 'portal-header' }, styles: { color: '#123456' }, children: [{ type: 'strong', content: 'Inhalt' }] }]); assert(host.children.length === 1, 'Vorhandener eigener Inhalt muss ersetzt werden.'); assert(host.children[0].nodeName === 'section', 'Der DOM-Tag wurde nicht erzeugt.'); assert(host.children[0].attributes.class === 'portal-header', 'Attribute fehlen.'); assert(host.children[0].style.values.color === '#123456', 'Styles fehlen.'); assert(host.children[0].children[0].children[0].text === 'Inhalt', 'Textknoten fehlt.'); new BrandingDomRenderer().clear(host); assert(host.children.length === 0, 'clear muss alle eigenen Knoten entfernen.'); console.log('BrandingDomRenderer: ' + passed + ' Pruefungen erfolgreich.');