import { describe, expect, it } from 'vitest'; import { construireArbre } from './lieux'; import type { LocationDto } from '@siop/shared'; const loc = (over: Partial): LocationDto => ({ id: crypto.randomUUID(), name: 'X', parentId: null, address: null, city: null, guardianName: null, guardianPhone: null, latitude: null, longitude: null, assetCount: 0, ...over, }); describe('construireArbre (liste plate → site → zones)', () => { it('rattache les zones à leur site et trie par nombre d’appareils', () => { const atlas = loc({ name: 'Tour Atlas', assetCount: 4 }); const manar = loc({ name: 'Al Manar', assetCount: 1 }); const hall = loc({ name: 'Hall', parentId: atlas.id, assetCount: 2 }); const arbre = construireArbre([manar, atlas, hall]); expect(arbre.map((s) => s.name)).toEqual(['Tour Atlas', 'Al Manar']); expect(arbre[0]!.zones.map((z) => z.name)).toEqual(['Hall']); expect(arbre[1]!.zones).toHaveLength(0); }); });