diff --git a/test/knAnsichtOrakel.test.js b/test/knAnsichtOrakel.test.js new file mode 100644 index 0000000..db3be66 --- /dev/null +++ b/test/knAnsichtOrakel.test.js @@ -0,0 +1,22 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { sichtbarerText, ohneKopf, ladeAlteApp } from './support/knWortlautOrakel.js' +import { aboAntwort, abo, VORSCHAU, LIMITS } from './support/knDaten.js' + +test('sichtbarerText: Tags, Skripte und jeder Leerraum fallen weg, Entitäten werden Text', () => { + assert.equal(sichtbarerText('

Hallo Welt & Co

'), 'HalloWelt&Co') + assert.equal(sichtbarerText('50,00 € '), '50,00€') +}) +test('ohneKopf streicht nur den Kopf, nicht die Absätze danach', () => { + assert.equal(sichtbarerText(ohneKopf('

A

B

C

')), 'C') + assert.equal(sichtbarerText(ohneKopf('

A

C

')), 'C') + assert.equal(sichtbarerText(ohneKopf('

C

')), 'C') +}) +test('altes app.js rendert in der VM: Bestellen, Wechsel, Speicher, Gutschrift', async () => { + const alt = ladeAlteApp() + assert.match(sichtbarerText(alt.bestellen(aboAntwort(), 'wartung')), /Zahlungspflichtigbestellen/) + const hosting = aboAntwort({ subscription: abo({ produkt: 'hosting', canSwitch: true }) }) + assert.match(sichtbarerText(await alt.wechsel(hosting, VORSCHAU)), /Zahlungspflichtigbestellen/) + assert.match(sichtbarerText(await alt.speicher(aboAntwort({ subscription: abo() }))), /E-Mail-Speicher/) + assert.match(sichtbarerText(await alt.gutschrift(aboAntwort({ subscription: abo() }), { requests: [], limits: LIMITS })), /Antragabsenden/) +}) diff --git a/test/support/knWortlautOrakel.js b/test/support/knWortlautOrakel.js new file mode 100644 index 0000000..131076e --- /dev/null +++ b/test/support/knWortlautOrakel.js @@ -0,0 +1,125 @@ +// Wortlaut-Orakel (P2): lädt das alte public/app.js in eine VM, rendert die vier Wortlaut-Seiten (Bestellen, Wechsel, E-Mail-Speicher, +// Gutschrift) mit Attrappen und liefert deren HTML. Die neuen Seiten müssen denselben sichtbaren Text haben (C14, Fassung 5). +// Nur lesend: app.js bleibt unverändert. P10 friert dieses Hilfsmittel vor dem Löschen von app.js ein (N40, N51). +import vm from 'node:vm' +import { readFileSync } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import { setImmediate as takt } from 'node:timers/promises' + +const APP_JS = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'public', 'app.js') + +const ENTITAETEN = { '&': '&', '<': '<', '>': '>', '"': '"', ''': "'", ' ': ' ' } + +/** Sichtbarer Text eines HTML-Strings oder Elements: ohne Tags, Kommentare,