mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix: harden imports and daily medication state (#577)
This commit is contained in:
1 parent
403eabb888
commit
b20f1b5c66
45 files changed
+2270
-279
No files matched your search
@@ -26,6 +26,8 @@ vi.mock("next/navigation", () => ({
|
||||
usePathname: () => "/settings/export",
|
||||
}));
|
||||
|
||||
import type { Locale } from "@/lib/i18n/config";
|
||||
import { AppleHealthEstimateWarning } from "../import-panel/apple-health-import-card";
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import {
|
||||
ImportPanel,
|
||||
@@ -33,9 +35,10 @@ import {
|
||||
EXAMPLE_CSV,
|
||||
parseImportJson,
|
||||
} from "../import-panel";
|
||||
|
||||
import { parseCsvMeasurements } from "@/lib/import/csv-measurements";
|
||||
|
||||
function render(node: React.ReactElement, locale: "en" | "de" = "en") {
|
||||
function render(node: React.ReactElement, locale: Locale = "en") {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
|
||||
});
|
||||
@@ -98,6 +101,20 @@ describe("<ImportPanel> — SSR smoke", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("<AppleHealthEstimateWarning>", () => {
|
||||
it.each(["en", "de", "es", "fr", "it", "pl"] as const)(
|
||||
"renders localized estimate disclosure for %s",
|
||||
(locale) => {
|
||||
const html = render(<AppleHealthEstimateWarning days={3} />, locale);
|
||||
expect(html).toContain('data-testid="apple-health-estimate-warning"');
|
||||
expect(html).toContain("3");
|
||||
expect(html).not.toContain(
|
||||
"settings.sections.export.import.appleHealth.estimateWarning",
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("EXAMPLE_IMPORT payload", () => {
|
||||
it("round-trips through JSON and stays parseable", () => {
|
||||
const serialised = JSON.stringify(EXAMPLE_IMPORT, null, 2);
|
||||
|
||||
@@ -27,10 +27,31 @@ interface JobStatus {
|
||||
result: {
|
||||
totals?: { recordsRead?: number; rowsUpserted?: number };
|
||||
clinical?: { skipped?: number };
|
||||
cumulativeEstimates?: { days?: number; rows?: number };
|
||||
} | null;
|
||||
failureReason: string | null;
|
||||
}
|
||||
|
||||
export function AppleHealthEstimateWarning({ days }: { days: number }) {
|
||||
const { t } = useTranslations();
|
||||
return (
|
||||
<p
|
||||
data-testid="apple-health-estimate-warning"
|
||||
className="text-foreground flex items-start gap-2 text-xs"
|
||||
>
|
||||
<AlertCircle
|
||||
className="text-warning mt-0.5 size-3.5 shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>
|
||||
{t("settings.sections.export.import.appleHealth.estimateWarning", {
|
||||
count: days,
|
||||
})}
|
||||
</span>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
export function AppleHealthImportCard() {
|
||||
const { t } = useTranslations();
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -233,6 +254,11 @@ export function AppleHealthImportCard() {
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{isDone && (status?.result?.cumulativeEstimates?.days ?? 0) > 0 && (
|
||||
<AppleHealthEstimateWarning
|
||||
days={status?.result?.cumulativeEstimates?.days ?? 0}
|
||||
/>
|
||||
)}
|
||||
{(isFailed || uploadError) && (
|
||||
<p
|
||||
role="alert"
|
||||
|
||||
Reference in new issue
Block a user