import { describe, expect, it } from 'vitest' import type { Source } from '../api/engine' import { buildGraph, HEIGHT, WIDTH } from './graph' import type { Material } from './results' const doc = (docId: number, title: string, status = 'completed') => ({ docId, title, originalName: `${title}.pdf`, status }) as Source const material = (id: number, status: Material['status'], sources: string[]) => ({ id, agentId: 7, kind: 'summary', status, planTitle: `Lesson ${id}`, sources }) as Material describe('buildGraph', () => { const data = { docs: [doc(1, 'Onboarding'), doc(2, 'Safety'), doc(3, 'Broken', 'failed')], materials: [ material(10, 'accepted', ['Onboarding.pdf', 'Safety']), material(11, 'generating', []), material(12, 'failed', ['Safety']), material(13, 'ready', ['Safety']), ], } const graph = buildGraph(data, c => c) it('holds only the knowledge base and the content made from it', () => { expect(graph.nodes.filter(n => !n.hub).map(n => `${n.cluster}:${n.id}`).sort()) .toEqual(['made:mat-7-10', 'made:mat-7-13', 'sources:doc-1', 'sources:doc-2']) }) it('links content to its sources', () => { const cross = graph.links.filter(l => !l.hub).map(l => `${l.source}>${l.target}`) expect(cross.sort()).toEqual(['mat-7-10>doc-1', 'mat-7-10>doc-2', 'mat-7-13>doc-2']) }) it('lays out the same data the same way, inside the canvas', () => { expect(buildGraph(data, c => c).nodes).toEqual(graph.nodes) for (const n of graph.nodes) { expect(n.x).toBeGreaterThanOrEqual(0); expect(n.x).toBeLessThanOrEqual(WIDTH) expect(n.y).toBeGreaterThanOrEqual(0); expect(n.y).toBeLessThanOrEqual(HEIGHT) } }) })