worldmap-viewer

git clone https://git.godosa.eu/worldmap-viewer

master

raw ยท 1267 bytes

// Minimal DOM stand-in for node tests of the panels: just what ui.el() and the panels touch.
export class FakeEl {
  constructor(tag) { Object.assign(this, { tag, kids: [], attrs: {}, on: {}, style: {}, value: '', hidden: false }); }
  setAttribute(k, v) { this.attrs[k] = v; }
  get className() { return this.attrs.class ?? ''; }
  addEventListener(t, f) { (this.on[t] ??= []).push(f); }
  fire(t, e = {}) { for (const f of this.on[t] ?? []) f({ preventDefault() {}, stopPropagation() {}, target: this, ...e }); }
  append(...k) { this.kids.push(...k); }
  replaceChildren(...k) { this.kids = k; }
  focus() {}
  blur() {}
  getBoundingClientRect() { return { left: 0, top: 0, width: 320, height: 130 }; }
  get textContent() { return this.kids.map(k => (typeof k === 'string' ? k : k.textContent)).join(''); }
  set textContent(v) { this.kids = [String(v)]; }
  find(pred) {
    for (const k of this.kids) {
      if (typeof k === 'string') continue;
      if (pred(k)) return k;
      const r = k.find(pred);
      if (r) return r;
    }
    return null;
  }
}

export function installFakeDom() {
  globalThis.document = { createElement: t => new FakeEl(t), createElementNS: (_, t) => new FakeEl(t),
    querySelector: () => null, querySelectorAll: () => [] };
}