Files
paseo/packages/app/src/components/file-pane-enabled.test.ts
T
daf7042cd2 Refresh open file tabs when revisited (#445) (#1699)
File previews read once and then froze: visited tabs stay mounted-but-hidden
(LRU in useMountedTabSet), so refetchOnMount never re-fired and the only way
to see fresh content was to close and reopen the tab.

Gate the file query's `enabled` on tab + app visibility so React Query
refetches on the disabled->enabled transition — and only when the cached read
is stale (keeping the existing 5s staleTime), so a quick flip away and back
doesn't re-read. Covers switching between tabs and backgrounding/reopening the
whole app to the same tab.

Adds a wiring test covering the stale-revisit refetch, the fresh-revisit
debounce, the app-foreground refetch, and the read-error path.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 20:16:52 +08:00

29 lines
925 B
TypeScript

import { describe, expect, it } from "vitest";
import { isFileQueryEnabled } from "./file-pane-enabled";
describe("isFileQueryEnabled", () => {
it("reads when there is a target, the tab is active, and the app is visible", () => {
expect(isFileQueryEnabled({ hasReadTarget: true, isTabActive: true, isAppVisible: true })).toBe(
true,
);
});
it("does not read while the tab is hidden", () => {
expect(
isFileQueryEnabled({ hasReadTarget: true, isTabActive: false, isAppVisible: true }),
).toBe(false);
});
it("does not read while the app is backgrounded", () => {
expect(
isFileQueryEnabled({ hasReadTarget: true, isTabActive: true, isAppVisible: false }),
).toBe(false);
});
it("does not read without a resolved file target", () => {
expect(
isFileQueryEnabled({ hasReadTarget: false, isTabActive: true, isAppVisible: true }),
).toBe(false);
});
});