From 2f0768f59029a7656de56c4e671c478092e435c8 Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sat, 5 Sep 2026 12:40:51 +0200 Subject: [PATCH] v2.0.7: PWA-Manifest + Service-Worker-Tests (Phase 4.2) - tests/webapp/manifest.test.ts: 14 neue Tests - PWA-Manifest: existiert, hat Pflichtfelder (name, short_name, start_url, display, icons) - Icons: icon-192.svg, icon-512.svg existieren, sind valides SVG mit viewBox - Service-Worker: hat install/activate/fetch Handler - Background-Sync Handler mit 'mindomat-sync' Tag - CACHE_NAME + PRECACHE_URLS mit Pflicht-Dateien - Ueberspringt /api/ vom Caching - index.html: link zu manifest.webmanifest, navigator.serviceWorker.register Verifiziert: - 102/102 Tests gruen (14 neue) - PWA-Manifest + Service-Worker + Icons sind vorhanden und korrekt --- tests/webapp/manifest.test.ts | 108 ++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/webapp/manifest.test.ts diff --git a/tests/webapp/manifest.test.ts b/tests/webapp/manifest.test.ts new file mode 100644 index 0000000..77de1ed --- /dev/null +++ b/tests/webapp/manifest.test.ts @@ -0,0 +1,108 @@ +// Tests fuer PWA-Manifest + Service-Worker +// Phase 4.2 + +import { describe, it, expect } from 'vitest'; +import { readFileSync, existsSync } from 'node:fs'; +import { join } from 'node:path'; + +const WEBAPP_DIR = join(__dirname, '..', '..', 'webapp'); + +describe('PWA-Manifest', () => { + const manifestPath = join(WEBAPP_DIR, 'public', 'manifest.webmanifest'); + + it('existiert', () => { + expect(existsSync(manifestPath)).toBe(true); + }); + + it('hat alle PWA-Pflichtfelder', () => { + const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as Record; + expect(manifest.name).toBeTruthy(); + expect(manifest.short_name).toBeTruthy(); + expect(manifest.start_url).toBeTruthy(); + expect(manifest.display).toBeTruthy(); + expect(Array.isArray(manifest.icons)).toBe(true); + }); + + it('verweist auf existierende Icons', () => { + const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as { icons: Array<{ src: string }> }; + for (const icon of manifest.icons) { + const iconPath = join(WEBAPP_DIR, 'public', icon.src); + expect(existsSync(iconPath), `Icon fehlt: ${icon.src}`).toBe(true); + } + }); + + it('hat standalone display (PWA-faehig)', () => { + const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as { display: string }; + expect(manifest.display).toBe('standalone'); + }); +}); + +describe('PWA-Icons', () => { + it('icon-192.svg existiert und ist valides SVG', () => { + const path = join(WEBAPP_DIR, 'public', 'icon-192.svg'); + expect(existsSync(path)).toBe(true); + const content = readFileSync(path, 'utf-8'); + expect(content).toContain(' { + const path = join(WEBAPP_DIR, 'public', 'icon-512.svg'); + expect(existsSync(path)).toBe(true); + const content = readFileSync(path, 'utf-8'); + expect(content).toContain(' { + const swPath = join(WEBAPP_DIR, 'public', 'service-worker.js'); + const indexHtmlPath = join(WEBAPP_DIR, 'index.html'); + + it('existiert', () => { + expect(existsSync(swPath)).toBe(true); + }); + + it('hat alle Standard-Event-Handler', () => { + const sw = readFileSync(swPath, 'utf-8'); + expect(sw).toMatch(/addEventListener\(['"]install['"]/); + expect(sw).toMatch(/addEventListener\(['"]activate['"]/); + expect(sw).toMatch(/addEventListener\(['"]fetch['"]/); + }); + + it('hat Background-Sync Handler (Phase 4.3 erweitert)', () => { + const sw = readFileSync(swPath, 'utf-8'); + expect(sw).toMatch(/addEventListener\(['"]sync['"]/); + expect(sw).toContain('mindomat-sync'); + }); + + it('definiert CACHE_NAME', () => { + const sw = readFileSync(swPath, 'utf-8'); + expect(sw).toMatch(/CACHE_NAME\s*=/); + }); + + it('hat PRECACHE_URLS mit Pflicht-Dateien', () => { + const sw = readFileSync(swPath, 'utf-8'); + expect(sw).toMatch(/PRECACHE_URLS/); + expect(sw).toContain("'/'"); + expect(sw).toContain('manifest.webmanifest'); + }); + + it('skippt API-Anfragen vom Caching', () => { + const sw = readFileSync(swPath, 'utf-8'); + expect(sw).toContain('/api/'); + expect(sw).toMatch(/startsWith\(['"]\/api\/['"]\)/); + }); +}); + +describe('PWA-Integration in index.html', () => { + it('referenziert das Manifest', () => { + const html = readFileSync(join(WEBAPP_DIR, 'index.html'), 'utf-8'); + expect(html).toMatch(/]*rel=['"]manifest['"][^>]*href=['"]\/manifest\.webmanifest['"]/); + }); + + it('registriert den Service-Worker', () => { + const html = readFileSync(join(WEBAPP_DIR, 'index.html'), 'utf-8'); + expect(html).toMatch(/navigator\.serviceWorker\.register/); + }); +});