import { describe, expect, it } from "vitest"; import { calculateCategoryTrends } from "./opexTrends"; describe("calculateCategoryTrends", () => { it("compare les montants de l'exercice affiché à ceux de sa vraie année N-1", () => { const trends = calculateCategoryTrends( [ { categorie: "App global", montant: 504_980 }, { categorie: "App HEP", montant: 98_000 }, ], [ { categorie: "App global", montant: 505_730 }, { categorie: "App HEP", montant: 98_000 }, ], ); // Régression : 2027 ne doit jamais réutiliser le +26 % (comparaison 2026/2025). expect(trends["App global"]).toEqual({ montantN1: 505_730, variationPct: -0.1, tendance: "stable", }); expect(trends["App HEP"]).toEqual({ montantN1: 98_000, variationPct: 0, tendance: "stable", }); }); it("identifie une nouvelle catégorie et une variation significative", () => { const trends = calculateCategoryTrends( [ { categorie: "App global", montant: 1_050 }, { categorie: "Sécurité", montant: 20 }, ], [{ categorie: "App global", montant: 1_000 }], ); expect(trends["App global"]).toEqual({ montantN1: 1_000, variationPct: 5, tendance: "hausse", }); expect(trends["Sécurité"]).toEqual({ montantN1: null, variationPct: null, tendance: "new", }); }); });