Files
CustomBranding/tests/BrandingDomRenderer.test.js
Torsten Brendgen 490e9adbd8 feat: Add custom branding functionality with CSS and JSON configuration
- Introduced custom branding CSS styles in `custom-branding.css`.
- Created example JSON configuration for custom branding in `custom-branding.example.json`.
- Implemented branding configuration logic in `BrandingConfig.ts` to normalize and validate branding settings.
- Developed CSS loader to manage loading and unloading of custom stylesheets in `BrandingCssLoader.ts`.
- Added DOM rendering capabilities for branding elements in `BrandingDomRenderer.ts`.
- Defined types and interfaces for branding elements and configurations in `BrandingTypes.ts`.
- Included localization support for German in `de-de.js`.
- Added unit tests for branding configuration, CSS loader, and DOM renderer.
- Validated project structure and static assets with new validation scripts.
2026-07-20 22:55:47 +02:00

60 lines
2.0 KiB
JavaScript

'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.');