| ]*>(.*?)<\/th>/g)].map((m) => m[1]);
+ expect(heads.slice(1)).toEqual([
+ "t(dashboard.income)",
+ "t(dashboard.expenses)",
+ "t(reports.uncategorized)",
+ "t(reports.compare.sections.transfers)",
+ "t(dashboard.net)",
+ ]);
+ });
+
+ it("shows the net result in « Net », not income − expenses", () => {
+ expect(cellsOf(html, 1).slice(1)).toEqual(["$500", "$100", "$0", "$0", "$400"]);
+ expect(cellsOf(html, 2).slice(1)).toEqual(["$1,000", "$30", "$40", "-$300", "$710"]);
+ });
+
+ it("totals every column, the net result included", () => {
+ expect(cellsOf(html, 3)).toEqual(["t(common.total)", "$1,500", "$130", "$40", "-$300", "$1,110"]);
+ });
+});
+
+describe("KpiCard", () => {
+ const kpi: CartesKpi = {
+ current: 710,
+ previousMonth: null,
+ previousYear: null,
+ deltaMoMAbs: null,
+ deltaMoMPct: null,
+ deltaYoYAbs: null,
+ deltaYoYPct: null,
+ sparkline: [],
+ };
+ const render = (note?: string) =>
+ renderToStaticMarkup();
+ const divs = (html: string) => html.split(" {
+ const html = render("Dont 40 $ non classés");
+ expect(html).toContain(">Dont 40 $ non classés<");
+ expect(html.indexOf("Dont 40 $ non classés")).toBeGreaterThan(html.indexOf("710"));
+ });
+
+ it("adds no line without a note", () => {
+ expect(divs(render())).toBe(divs(render("Dont 40 $ non classés")) - 1);
+ });
+});
diff --git a/src/pages/DashboardPage.render.test.tsx b/src/pages/DashboardPage.render.test.tsx
index dc88952..216457f 100644
--- a/src/pages/DashboardPage.render.test.tsx
+++ b/src/pages/DashboardPage.render.test.tsx
@@ -3,23 +3,27 @@
// fake `useOnboarding()`, and the dashboard's data hook and widgets are stubbed
// to markers: what is pinned is the page's branching on the path. Since #397
// the page has no list of its own once transactions exist: the banner of
-// AppShell replaced the compact bar (D7).
+// AppShell replaced the compact bar (D7). The fake KpiCard records its props:
+// the page hands « Solde net » the note of the snapshot (#392, D5).
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { MemoryRouter } from "react-router-dom";
import type { OnboardingValue } from "../hooks/useOnboardingChecklist";
+import type { CartesKpi, CartesSnapshot } from "../shared/types";
vi.mock("react-i18next", async () => (await import("../test/i18nMock")).i18nMock());
let onboarding: OnboardingValue;
vi.mock("../contexts/OnboardingContext", () => ({ useOnboarding: () => onboarding }));
+let cartesSnapshot: CartesSnapshot | null = null;
+
vi.mock("../hooks/useDashboard", () => ({
useDashboard: () => ({
state: {
categoryBreakdown: [],
categoryOverTime: { categories: [], data: [] },
- cartesSnapshot: null,
+ cartesSnapshot,
period: "year",
customDateFrom: "2026-01-01",
customDateTo: "2026-10-08",
@@ -39,9 +43,10 @@ vi.mock("../hooks/useDashboard", () => ({
}));
// Hoisted with the mocks below, which run before the imports.
-const { marker, emptyStateProps } = vi.hoisted(() => ({
+const { marker, emptyStateProps, kpiProps } = vi.hoisted(() => ({
marker: (name: string) => ({ default: () => }),
emptyStateProps: { current: null as Record | null },
+ kpiProps: new Map>(),
}));
vi.mock("../components/shared/PageHelp", () => ({ PageHelp: () => null }));
vi.mock("../components/dashboard/CategoriesV1DiscoveryBanner", () => marker("discovery"));
@@ -59,13 +64,20 @@ vi.mock("../components/dashboard/NetWorthTile", () => marker("net-worth"));
vi.mock("../components/reports/CategoryBarChart", () => marker("bar-chart"));
vi.mock("../components/reports/CategoryOverTimeChart", () => marker("over-time"));
vi.mock("../components/reports/FilterPanel", () => marker("filters"));
-vi.mock("../components/reports/cards/KpiCard", () => marker("kpi"));
+vi.mock("../components/reports/cards/KpiCard", () => ({
+ default: (props: Record) => {
+ kpiProps.set(props.id as string, props);
+ return ;
+ },
+}));
vi.mock("../components/reports/cards/IncomeExpenseOverlayChart", () => marker("overlay"));
vi.mock("../components/reports/cards/TopMoversList", () => marker("movers"));
vi.mock("../components/reports/cards/BudgetAdherenceCard", () => marker("adherence"));
vi.mock("../components/shared/TransactionDetailModal", () => marker("detail"));
import DashboardPage from "./DashboardPage";
+import { netNote } from "../components/reports/cards/netNote";
+import { markedT } from "../test/i18nMock";
import { computeChecklist } from "../utils/onboardingChecklist";
import type { OnboardingCounters } from "../shared/types";
@@ -115,6 +127,8 @@ const render = () =>
beforeEach(() => {
onboarding = path();
emptyStateProps.current = null;
+ cartesSnapshot = null;
+ kpiProps.clear();
});
describe("DashboardPage on the shared path (#352, #396, #397)", () => {
@@ -169,3 +183,36 @@ describe("DashboardPage — texts that go through t (#437)", () => {
expect(render()).toContain(">t(dashboard.kpiSectionTitle)<");
});
});
+
+describe("DashboardPage — the note under « Solde net » (#392, D5)", () => {
+ const kpi = (current: number): CartesKpi => ({
+ current,
+ previousMonth: null,
+ previousYear: null,
+ deltaMoMAbs: null,
+ deltaMoMPct: null,
+ deltaYoYAbs: null,
+ deltaYoYPct: null,
+ sparkline: [],
+ });
+
+ it("hands the net card the note of the snapshot's breakdown, and no other card a note", () => {
+ const netBreakdown = { uncategorized: 40, transfers: -300 };
+ cartesSnapshot = {
+ referenceYear: 2026,
+ referenceMonth: 10,
+ kpis: { income: kpi(1000), expenses: kpi(30), net: kpi(710), savingsRate: kpi(97) },
+ netBreakdown,
+ flow12Months: [],
+ topMoversUp: [],
+ topMoversDown: [],
+ budgetAdherence: { categoriesInTarget: 0, categoriesTotal: 0, worstOverruns: [] },
+ seasonality: { referenceAmount: 30, historicalYears: [], historicalAverage: null, deviationPct: null },
+ };
+ render();
+ expect([...kpiProps.keys()]).toEqual(["income", "expenses", "net", "savingsRate"]);
+ expect(kpiProps.get("net")!.note).toContain("t(reports.cartes.netNote.both[");
+ expect(kpiProps.get("net")!.note).toBe(netNote(markedT, "fr", netBreakdown));
+ for (const id of ["income", "expenses", "savingsRate"]) expect(kpiProps.get(id)!.note).toBeUndefined();
+ });
+});
diff --git a/src/pages/ReportsCartesPage.render.test.tsx b/src/pages/ReportsCartesPage.render.test.tsx
new file mode 100644
index 0000000..71aee64
--- /dev/null
+++ b/src/pages/ReportsCartesPage.render.test.tsx
@@ -0,0 +1,96 @@
+// ReportsCartesPage hands « Solde net » the note of its snapshot (#392, D5).
+// No jsdom: react-dom/server renders the page in vitest's node environment.
+// The data hook and the widgets are stubbed, and the fake KpiCard records the
+// props it receives.
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import { renderToStaticMarkup } from "react-dom/server";
+import { MemoryRouter } from "react-router-dom";
+import type { CartesKpi, CartesSnapshot } from "../shared/types";
+
+vi.mock("react-i18next", async () => (await import("../test/i18nMock")).i18nMock());
+
+let snapshot: CartesSnapshot | null = null;
+vi.mock("../hooks/useCartes", () => ({
+ useCartes: () => ({
+ year: 2026,
+ month: 10,
+ mode: "month",
+ snapshot,
+ isLoading: false,
+ error: null,
+ setReferencePeriod: vi.fn(),
+ setMode: vi.fn(),
+ }),
+}));
+
+// Hoisted with the mocks below, which run before the imports.
+const { marker, kpiProps } = vi.hoisted(() => ({
+ marker: (name: string) => ({ default: () => }),
+ kpiProps: new Map>(),
+}));
+vi.mock("../components/reports/CompareReferenceMonthPicker", () => marker("month-picker"));
+vi.mock("../components/reports/cards/CartesPeriodModeToggle", () => marker("mode-toggle"));
+vi.mock("../components/reports/cards/KpiCard", () => ({
+ default: (props: Record) => {
+ kpiProps.set(props.id as string, props);
+ return ;
+ },
+}));
+vi.mock("../components/reports/cards/IncomeExpenseOverlayChart", () => marker("overlay"));
+vi.mock("../components/reports/cards/TopMoversList", () => marker("movers"));
+vi.mock("../components/reports/cards/BudgetAdherenceCard", () => marker("adherence"));
+vi.mock("../components/reports/cards/SeasonalityCard", () => marker("seasonality"));
+
+import ReportsCartesPage from "./ReportsCartesPage";
+import { netNote } from "../components/reports/cards/netNote";
+import { markedT } from "../test/i18nMock";
+
+const kpi = (current: number): CartesKpi => ({
+ current,
+ previousMonth: null,
+ previousYear: null,
+ deltaMoMAbs: null,
+ deltaMoMPct: null,
+ deltaYoYAbs: null,
+ deltaYoYPct: null,
+ sparkline: [],
+});
+
+const render = () =>
+ renderToStaticMarkup(
+
+
+ ,
+ );
+
+beforeEach(() => {
+ snapshot = null;
+ kpiProps.clear();
+});
+
+describe("ReportsCartesPage — the note under « Solde net » (#392, D5)", () => {
+ it("hands the net card the note of the snapshot's breakdown, and no other card a note", () => {
+ const netBreakdown = { uncategorized: 40, transfers: -300 };
+ snapshot = {
+ referenceYear: 2026,
+ referenceMonth: 10,
+ kpis: { income: kpi(1000), expenses: kpi(30), net: kpi(710), savingsRate: kpi(97) },
+ netBreakdown,
+ flow12Months: [],
+ topMoversUp: [],
+ topMoversDown: [],
+ budgetAdherence: { categoriesInTarget: 0, categoriesTotal: 0, worstOverruns: [] },
+ seasonality: { referenceAmount: 30, historicalYears: [], historicalAverage: null, deviationPct: null },
+ };
+ render();
+ expect([...kpiProps.keys()]).toEqual(["income", "expenses", "net", "savingsRate"]);
+ expect(kpiProps.get("net")!.note).toContain("t(reports.cartes.netNote.both[");
+ expect(kpiProps.get("net")!.note).toBe(netNote(markedT, "fr", netBreakdown));
+ for (const id of ["income", "expenses", "savingsRate"]) expect(kpiProps.get(id)!.note).toBeUndefined();
+ });
+
+ it("renders no card without a snapshot", () => {
+ expect(render()).toContain("t(reports.empty.noData)");
+ expect(kpiProps.size).toBe(0);
+ });
+});
diff --git a/src/services/reportService.cartes.test.ts b/src/services/reportService.cartes.test.ts
index 96b3264..badb5b8 100644
--- a/src/services/reportService.cartes.test.ts
+++ b/src/services/reportService.cartes.test.ts
@@ -286,7 +286,7 @@ describe("getCartesSnapshot", () => {
]),
];
routeSelect([
- { match: "strftime('%Y-%m', date)", rows: [{ month: "2026-03", income: 5000, expenses: 400 }] },
+ { match: FLOWS, rows: flowRows([{ month: "2026-03", income: 5000, expenses: 400 }]) },
{ match: "ORDER BY ABS(month_current_total - month_previous_total) DESC", rows: momRows },
{ match: "parent_id FROM categories", rows: [{ id: 99, name: "Salaire", color: null, type: "income", parent_id: null }] },
]);
|