mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
- Wait for a validated account scope before warming record reads - Abort scoped preloads and discard handoffs across record transitions - Cover malformed scope reloads and fresh own-record recovery
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { isRecordPreloadReady } from "@/components/providers";
|
|
import {
|
|
__resetRecordScopeForTests,
|
|
setRecordScope,
|
|
setRefusedRecordScope,
|
|
} from "@/lib/query-keys/record-scope";
|
|
|
|
describe("isRecordPreloadReady", () => {
|
|
it("waits for the account response before warming record reads", () => {
|
|
__resetRecordScopeForTests();
|
|
|
|
expect(
|
|
isRecordPreloadReady({ isLoading: true, accountAccessStatus: "valid" }),
|
|
).toBe(false);
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: undefined,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("accepts only a resolved own-record response with an own-record scope", () => {
|
|
__resetRecordScopeForTests();
|
|
setRecordScope(null);
|
|
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: "valid",
|
|
activeAccountId: null,
|
|
}),
|
|
).toBe(true);
|
|
|
|
setRecordScope("shared-record");
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: "valid",
|
|
activeAccountId: null,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("accepts a shared-record response only after its exact scope is mirrored", () => {
|
|
__resetRecordScopeForTests();
|
|
setRecordScope("shared-record");
|
|
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: "valid",
|
|
activeAccountId: "shared-record",
|
|
}),
|
|
).toBe(true);
|
|
|
|
setRecordScope(null);
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: "valid",
|
|
activeAccountId: "shared-record",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("never opens a preload window for an explicitly refused record", () => {
|
|
__resetRecordScopeForTests();
|
|
setRefusedRecordScope();
|
|
|
|
expect(
|
|
isRecordPreloadReady({
|
|
isLoading: false,
|
|
accountAccessStatus: "invalid",
|
|
activeAccountId: null,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|