Analyse: Dev-Hinweis in der richtigen Kachel + Render-Test
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4bf3726c00
commit
d416a7aa09
2 files changed
+49
-1
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
// public/funktionen.js wirklich laden (der absolute Import /analyse-view.js wird auf die Datei umgeleitet)
|
||||
const dir = mkdtempSync(join(tmpdir(), 'fn-tiles-'))
|
||||
const viewUrl = pathToFileURL(new URL('../public/analyse-view.js', import.meta.url).pathname).href
|
||||
const src = readFileSync(new URL('../public/funktionen.js', import.meta.url), 'utf8').replace("'/analyse-view.js'", `'${viewUrl}'`)
|
||||
const file = join(dir, 'funktionen.mjs')
|
||||
writeFileSync(file, src)
|
||||
const { initFunktionen } = await import(pathToFileURL(file).href)
|
||||
|
||||
const news = { state: 'off' }
|
||||
const project = (id, analyse) => ({ projectId: id, projectName: `P ${id}`, liveUrl: '', features: { news }, analyse })
|
||||
async function render(projects) {
|
||||
globalThis.fetch = async () => ({ ok: true, status: 200, json: async () => ({ projects }) })
|
||||
const root = { innerHTML: '', querySelector: () => null }
|
||||
await initFunktionen(root)
|
||||
return root.innerHTML
|
||||
}
|
||||
const tile = (html, key) => html.slice(html.indexOf(`data-fn-tile="${key}"`), html.indexOf('</article>', html.indexOf(`data-fn-tile="${key}"`)))
|
||||
|
||||
test('Kacheln rendern ohne Fehler: News, Analyse comingSoon/aus/aktiv/gesperrt', async () => {
|
||||
const soon = await render([project('a', { comingSoon: true })])
|
||||
assert.match(tile(soon, 'news'), /News-Pinnwand/)
|
||||
assert.match(soon, /Kommt bald/)
|
||||
assert.doesNotMatch(soon, /data-fn-tile="analyse"/)
|
||||
|
||||
const off = await render([project('a', { state: 'off', eligible: true, devMode: false })])
|
||||
assert.match(tile(off, 'analyse'), /Einrichten/)
|
||||
assert.doesNotMatch(off, /Dev-Modus/)
|
||||
|
||||
const dev = await render([project('a', { state: 'active', eligible: true, devMode: true })])
|
||||
assert.match(tile(dev, 'analyse'), /Auswertung ansehen/)
|
||||
assert.match(tile(dev, 'analyse'), /Im Dev-Modus wird nicht gemessen/)
|
||||
assert.doesNotMatch(tile(dev, 'news'), /Dev-Modus/)
|
||||
|
||||
const live = await render([project('a', { state: 'active', eligible: true, devMode: false })])
|
||||
assert.match(tile(live, 'analyse'), /Auswertung ansehen/)
|
||||
assert.doesNotMatch(live, /Dev-Modus/)
|
||||
|
||||
const disabled = await render([project('a', { state: 'disabled' })])
|
||||
assert.match(tile(disabled, 'analyse'), /Bitte melde dich bei uns/)
|
||||
assert.doesNotMatch(disabled, /Dev-Modus/)
|
||||
})
|
||||
Reference in new issue
Block a user