import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; const dataHubSource = readFileSync(new URL('../../src/features/project-import/DataHub.tsx', import.meta.url), 'utf8'); const gpoRowSource = readFileSync(new URL('../../src/features/project-import/GpoStatusRow.tsx', import.meta.url), 'utf8'); const historyOverviewSource = readFileSync(new URL('../../src/features/project-import/DatahubHistoryOverview.tsx', import.meta.url), 'utf8'); const gpoImportSource = readFileSync(new URL('../../src/features/project-import/GpoFolderImport.tsx', import.meta.url), 'utf8'); describe('Datahub assessment timeslot composition', () => { it('keeps GPO as a source in the timeslot without pretending it is a scanner run', () => { expect(dataHubSource).toContain('listProjectGpoBackupStatus'); expect(dataHubSource).toContain('projectGpoData'); expect(dataHubSource).not.toContain('tenant-file-gpo'); expect(dataHubSource).toContain('reports.length + group.gpoBackups.length'); expect(dataHubSource).toContain('group.gpoBackups.map(record =>'); expect(gpoRowSource).toContain('GPO Backup'); expect(gpoRowSource).toContain("succeeded: 'Ready'"); expect(gpoRowSource).not.toContain("succeeded: 'Imported'"); expect(gpoRowSource).toContain('className="tenant-gpo-source-marker"'); expect(dataHubSource).toContain('onEvaluate={() => void reevaluateGpoBackup(record)}'); expect(dataHubSource).not.toContain('>Evaluate'); expect(dataHubSource).toContain('onDelete={() => setGpoDeleteTarget(record)}'); expect(gpoRowSource).toContain('onClick={onDelete}>Delete'); expect(dataHubSource).toContain('Delete GPO backup from the database?'); expect(dataHubSource).toContain('The timeslot and all other scan and GPO entries remain intact.'); expect(dataHubSource).toContain(''); expect(dataHubSource).toContain("globalThis.addEventListener('assessor:gpo-changed', refresh)"); expect(historyOverviewSource).not.toContain('listProjectGpoBackupStatus'); expect(historyOverviewSource).not.toContain('tenant-file-gpo'); expect(historyOverviewSource).toContain('groupProjectImportFiles('); expect(historyOverviewSource).toContain('projectGpoData[project.id] ?? []'); expect(historyOverviewSource).toContain('aria-pressed={selected}'); expect(historyOverviewSource).toContain('onClick={() => onSelectProject(project.id)}'); expect(dataHubSource).toContain('const latest = groupsForProject(projectId).find(group => group.scanRunIds.length)'); expect(dataHubSource).toContain('runIds: latest.scanRunIds'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Results All"'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Deviation"'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Passed"'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Not Applicable"'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Not Run"'); expect(historyOverviewSource).toContain('DonutMetricCard className="datahub-reference-knob" label="Error"'); }); it('keeps detailed status management and supports folder as well as ZIP selection', () => { expect(gpoImportSource).toContain('aria-label="GPO processing status"'); expect(gpoImportSource).toContain('GPO Processing'); expect(gpoImportSource).toContain('1 tenant GPO backup'); expect(gpoImportSource).toContain('GPO{record.gpoCount === 1'); expect(gpoImportSource).toContain("input.setAttribute('webkitdirectory', '')"); expect(gpoImportSource).toContain('accept=".zip,application/zip"'); expect(gpoImportSource).toContain('submitFolder(selectedFiles).finally'); expect(gpoImportSource).toContain('submitArchive(selectedArchive).finally'); expect(gpoImportSource).toContain("input.value = '';"); expect(gpoImportSource).toContain('const captured = file.arrayBuffer()'); expect(gpoImportSource).toContain('captureReadableGpoSelectedFiles(files.map'); expect(gpoImportSource).toContain('showDirectoryPicker'); expect(gpoImportSource).toContain('collectGpoDirectoryFiles(directory)'); expect(gpoImportSource).toContain('captureReadableGpoSelectedFiles'); expect(gpoImportSource).toContain('unreadable skipped'); expect(gpoImportSource).toContain('onClick={() => void chooseFolder()}'); expect(gpoImportSource).toContain('konnte nicht lokal gelesen werden'); expect(dataHubSource).toContain('label="Import GPO Folder" archiveLabel="Import GPO ZIP"'); expect(dataHubSource).toContain("record.state === 'dead-letter'"); }); });