mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 22:26:13 +00:00
fix(admin): read the AI quality summary once on the Coach page
`/admin/coach` mounts the AI quality card and the Coach feedback card, and both read `GET /api/admin/ai-quality` with the same unwrap, under two different query keys, so every open sent the request twice. The feedback card now reads the quality card's cell.
This commit is contained in:
1 parent
a6fdd48058
commit
d310058bc5
2 files changed
+26
-1
No files matched your search
@@ -19,6 +19,7 @@ vi.mock("@tanstack/react-query", () => ({
|
||||
}));
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { AiQualitySection } from "../ai-quality-section";
|
||||
import { CoachFeedbackSection } from "../coach-feedback-section";
|
||||
|
||||
function render() {
|
||||
@@ -138,3 +139,25 @@ describe("CoachFeedbackSection", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the Coach admin page's two quality cards", () => {
|
||||
it("read one cache cell, so the page asks for the summary once", () => {
|
||||
useQueryMock.mockReset().mockReturnValue({
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
data: null,
|
||||
});
|
||||
renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<AiQualitySection />
|
||||
<CoachFeedbackSection />
|
||||
</I18nProvider>,
|
||||
);
|
||||
|
||||
const keys = useQueryMock.mock.calls.map(
|
||||
([options]) => (options as { queryKey: unknown }).queryKey,
|
||||
);
|
||||
expect(keys).toHaveLength(2);
|
||||
expect(keys[1]).toEqual(keys[0]);
|
||||
});
|
||||
});
|
||||
@@ -51,7 +51,9 @@ export function CoachFeedbackSection() {
|
||||
const fmt = useFormatters();
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: queryKeys.adminCoachFeedback(),
|
||||
// The same read as the AI quality section beside it, so one request
|
||||
// serves both cards.
|
||||
queryKey: queryKeys.adminAiQuality(),
|
||||
queryFn: async () => {
|
||||
const data = await apiGet<{ summary: FeedbackSummary | null } | null>(
|
||||
"/api/admin/ai-quality",
|
||||
|
||||
Reference in new issue
Block a user