import { describe, expect, it } from 'vitest'; import { JSDOM } from 'jsdom'; import { buildManagementOverviewHtml } from '../../src/reporting/management-overview-report'; import type { ReportProjection } from '../../src/reporting/report-projection'; function projection(overrides: Partial = {}): ReportProjection { return { version: '1.1.0', generatedAt: '2026-09-29T10:00:00Z', project: { id: 'synthetic', name: 'Synthetic GmbH' }, environment: [{ key: 'Domain', value: 'synthetic.example' }, { key: 'Domain Controller', value: '1' }], overallScore: 37, scoreSources: [], domains: [ { domainId: 'identity', domainLabel: 'Identity & Account Hygiene', passed: 204, deviations: 221, assessed: 425, passRate: 204 / 425 }, { domainId: 'gpo', domainLabel: 'GPO & Baseline', passed: 170, deviations: 223, assessed: 393, passRate: 170 / 393 }, { domainId: 'cloud', domainLabel: 'Cloud & Applications', passed: 0, deviations: 0, assessed: 0 } ], priorities: [], coverage: { total: 818, assessed: 818, deviations: 444, passed: 374, notRun: 0, notApplicable: 0, executionErrors: 0, unknown: 0, perSource: [] }, inventory: { bySeverity: {} as never, byOutcome: {} as never, byDomain: {}, bySource: {} }, findings: [], policyEntries: [], workItems: [], sourcePriorities: [], convergence: [], bundles: [], singleSourcePolicyActions: [], diagnostics: [], provenance: [], gpo: { basis: { kind: 'equal-weight', reason: 'Synthetic' }, counts: { Fail: 100, Pass: 20, 'Not configured': 0, 'No baseline rule': 0, 'Not comparable': 0, 'Review required': 0 }, conflicts: 0, duplicates: 0, affectedSettings: 25, affectedBackups: 1, scopeLimited: true }, ...overrides } as ReportProjection; } describe('management export', () => { it('renders a self-contained factual heatmap and pass-rate bars from each projection', () => { const html = buildManagementOverviewHtml(projection()); const document = new JSDOM(html).window.document; expect(document.documentElement.lang).toBe('de'); expect(document.querySelectorAll('.heatmap li')).toHaveLength(3); expect(document.querySelector('.heatmap li')?.textContent).toContain('52 %'); expect(document.querySelectorAll('.comparison-row')).toHaveLength(3); expect(document.querySelector('.comparison-row')?.textContent).toContain('48 %'); expect(document.querySelector('.comparison-row .bar-pass')?.getAttribute('style')).toContain('48'); expect(document.body.textContent).toContain('444'); expect(document.body.textContent).toContain('100 abweichende Vergleiche zu 25 Einstellungen'); expect(html).not.toMatch(/ { const document = new JSDOM(buildManagementOverviewHtml(projection())).window.document; const tile = document.querySelectorAll('.heatmap li')[2]; expect(tile.className).toBe('unknown'); expect(tile.querySelector('.value')?.textContent).toBe('—'); expect(document.querySelectorAll('.comparison-row')[2].textContent).not.toContain('0 %'); }); it('uses other customer values, escapes names and omits GPO evaluation when absent', () => { const html = buildManagementOverviewHtml(projection({ project: { id: 'other', name: '' }, environment: [], gpo: undefined, coverage: { ...projection().coverage, assessed: 10, deviations: 2 }, domains: [{ domainId: 'recovery', domainLabel: 'Monitoring & Recovery', passed: 8, deviations: 2, assessed: 10, passRate: 0.8, evidence: { passed: [], deviations: [] } }] })); expect(html).toContain('<Other Customer>'); expect(html).not.toContain('synthetic.example'); expect(html).not.toContain('gesonderte GPO-Evaluation'); expect(html).toContain('20 %'); expect(html).toContain('80 %'); expect(html).not.toMatch(/|