import { describe, it, expect, vi } from 'vitest'; import { generateGraphData } from '@/lib/graphUtils.ts'; import { Organization } from '@/types.ts'; vi.mock('../constants.tsx', () => ({ SECTORS: [ { nameKey: 'technology', colorKey: 'blue', icon: null }, { nameKey: 'agriculture', colorKey: 'green', icon: null }, { nameKey: 'finance', colorKey: 'yellow', icon: null }, { nameKey: 'healthcare', colorKey: 'red', icon: null }, { nameKey: 'education', colorKey: 'purple', icon: null }, { nameKey: 'manufacturing', colorKey: 'orange', icon: null }, { nameKey: 'tourism', colorKey: 'teal', icon: null }, ], })); const mockOrganizations: Organization[] = [ { id: 'org-1', name: 'Org One', sector: 'technology', needs: [{ resource: 'Software Engineers', quantity: 5, urgency: 'high' }], offers: [{ resource: 'Web Development', quantity: 10, urgency: 'medium' }], }, { id: 'org-2', name: 'Org Two', sector: 'agriculture', needs: [{ resource: 'Web Development', quantity: 1, urgency: 'low' }], offers: [{ resource: 'Organic Produce', quantity: 100, urgency: 'high' }], }, { id: 'org-3', name: 'Org Three', sector: 'technology', needs: [{ resource: 'Project Managers', quantity: 2, urgency: 'medium' }], offers: [{ resource: 'Mobile App Development', quantity: 5, urgency: 'high' }], }, ]; const mockT = (key: string) => key; describe('generateGraphData', () => { it('should generate nodes and links correctly', () => { const { nodes, links } = generateGraphData(mockOrganizations, mockT); expect(nodes).toHaveLength(7); expect(links).toHaveLength(1); const techNode = nodes.find((n) => n.id === 'technology'); const agricultureNode = nodes.find((n) => n.id === 'agriculture'); expect(techNode?.orgCount).toBe(2); expect(agricultureNode?.orgCount).toBe(1); const link = links[0]; expect(link.source).toBe('agriculture'); expect(link.target).toBe('technology'); expect(link.value).toBe(1); }); });