test(day): read a chart and its same-named folder as one

The HealthChart split moved its layers, tooltip and day footer into
health-chart/, so the guard read the composer as a date-axis chart with
no doors. A component and the folder of its name are now one entry, a
tooltip action handed whole to the tooltip counts as wired, and the mount
floor counts the dashboard's one builder mount for its seven charts.
Drop two return-type exports nothing imports.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 14:01:17 +02:00
1 parent 5eafed8dd5
commit ad9e0d8732
3 files changed
+54 -9

No files matched your search

@@ -131,10 +131,32 @@ export function stripComments(text: string): string {
.replace(/(^|[^:"'`])\/\/.*$/gm, "$1");
}
const source = new Map(
const read = new Map(
files.map((f) => [rel(f), stripComments(readFileSync(f, "utf8"))]),
);
/**
* A component and the folder of the same name beside it are one chart: the
* HealthChart composer in `health-chart.tsx` draws the axes, and its layers,
* tooltip and day footer live in `health-chart/`. Read apart, the composer
* would look like a date-axis chart with no doors and the folder like no
* chart at all, so each folder is folded into its component's entry.
*/
export function foldComponentFolders(
sources: Map<string, string>,
): Map<string, string> {
const folded = new Map<string, string>();
const owners = [...sources.keys()].filter((f) => f.endsWith(".tsx"));
for (const [file, text] of sources) {
const owner = owners.find((o) => file.startsWith(`${o.slice(0, -4)}/`));
const key = owner ?? file;
folded.set(key, `${folded.get(key) ?? ""}\n${text}`);
}
return folded;
}
const source = foldComponentFolders(read);
/**
* The text of every JSX opening tag named `name` in `text`: from `<Name` to
* the `>` that closes it at brace depth zero, so an arrow function or a
@@ -223,7 +245,10 @@ function findMissingDoors(): {
/\bChartDayFooter\b/.test(text) &&
/\bOPEN_DAY_LINE\b/.test(text) &&
/\.tooltipProps\b/.test(text) &&
/\.tooltipAction\(/.test(text);
// Called in place, or handed whole to a tooltip that calls it.
/\.tooltipAction\(|\btooltipAction:\s*\w+\.tooltipAction\b/.test(
text,
);
if (wired) {
doors.charts += 1;
doors.chartFiles.push(file);
@@ -263,9 +288,10 @@ describe("every chart drawn in days opens its days, or says why not", () => {
it("still finds the doors it is meant to find (an empty match set fails)", () => {
// HealthChart on the metric pages (two mounts in the HealthKit page),
// blood pressure, weight, pulse, BMI, recovery, sleep, the mood line,
// water and caffeine; on the dashboard its seven charts, the mood line
// and the adherence chart.
expect(doors.mounts).toBeGreaterThanOrEqual(20);
// water and caffeine; on the dashboard the one mount its chart builder
// draws all seven metric charts through, the mood line and the
// adherence chart.
expect(doors.mounts).toBeGreaterThanOrEqual(14);
// HealthChart, the mood line and the nutrient bars themselves, sleep
// stages, mood dimensions, lab marker, custom metric, questionnaire,
// basal temperature, dose strength, efficacy, the adherence chart:
@@ -303,6 +329,29 @@ describe("every chart drawn in days opens its days, or says why not", () => {
}
});
it("folds a component's same-named folder into it, and nothing else", () => {
const folded = foldComponentFolders(
new Map([
["src/components/charts/health-chart.tsx", "<XAxis />"],
[
"src/components/charts/health-chart/chart-layers.tsx",
"ChartDayFooter",
],
["src/components/charts/health-chart-dynamic.tsx", "dynamic"],
]),
);
expect([...folded.keys()].sort()).toEqual([
"src/components/charts/health-chart-dynamic.tsx",
"src/components/charts/health-chart.tsx",
]);
expect(folded.get("src/components/charts/health-chart.tsx")).toContain(
"ChartDayFooter",
);
expect(source.get("src/components/charts/health-chart.tsx")).toMatch(
/\buseChartDayLinks\(/,
);
});
it("reads a JSX tag to its real end, past arrow functions in its props", () => {
const [tag] = jsxTags(
`<HealthChart onVisibleStats={(s) => s > 1} dayLinks />`,
@@ -201,5 +201,3 @@ export function useVaultLibrary({
years,
};
}
export type VaultLibrary = ReturnType<typeof useVaultLibrary>;
@@ -130,5 +130,3 @@ export function useVaultSelection(documents: InboundDocumentDto[]) {
openBulkShare,
};
}
export type VaultSelection = ReturnType<typeof useVaultSelection>;