Files
fusion/packages/dashboard/app/hooks/__tests__/useUpdateCheck.test.ts
Fusion acbd6580b3 feat(FN-2663): add cached update-check setting, APIs, and banner
- Add global updateCheckEnabled setting to core schema/types and wire dashboard command to cache update checks in the CLI
- Implement dashboard server update-check cache module plus REST routes for status and refresh behavior
- Add dashboard client hook, legacy API helpers, and UpdateAvailableBanner UI to show cached CLI update notices
- Cover update-check server routes, hook behavior, banner rendering, and route registration with focused tests
- Document update-check configuration and API behavior in architecture and settings reference docs
2026-04-27 01:40:07 -07:00

68 lines
2.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderHook, waitFor, act } from "@testing-library/react";
import { useUpdateCheck } from "../useUpdateCheck";
import * as api from "../../api";
vi.mock("../../api", () => ({
checkForUpdate: vi.fn(),
}));
const mockCheckForUpdate = vi.mocked(api.checkForUpdate);
describe("useUpdateCheck", () => {
beforeEach(() => {
vi.clearAllMocks();
sessionStorage.clear();
});
it("fetches update status on mount", async () => {
mockCheckForUpdate.mockResolvedValueOnce({
currentVersion: "0.6.0",
latestVersion: "0.7.0",
updateAvailable: true,
lastChecked: Date.now(),
});
const { result } = renderHook(() => useUpdateCheck());
await waitFor(() => expect(result.current.loading).toBe(false));
expect(mockCheckForUpdate).toHaveBeenCalledOnce();
expect(result.current.updateAvailable).toBe(true);
expect(result.current.latestVersion).toBe("0.7.0");
expect(result.current.currentVersion).toBe("0.6.0");
});
it("dismiss stores session flag", async () => {
mockCheckForUpdate.mockResolvedValueOnce({
currentVersion: "0.6.0",
latestVersion: "0.7.0",
updateAvailable: true,
});
const { result } = renderHook(() => useUpdateCheck());
await waitFor(() => expect(result.current.loading).toBe(false));
act(() => {
result.current.dismiss();
});
expect(result.current.dismissed).toBe(true);
expect(sessionStorage.getItem("kb-update-banner-dismissed")).toBe("true");
});
it("starts dismissed when sessionStorage already has dismissal key", async () => {
sessionStorage.setItem("kb-update-banner-dismissed", "true");
mockCheckForUpdate.mockResolvedValueOnce({
currentVersion: "0.6.0",
latestVersion: "0.7.0",
updateAvailable: true,
});
const { result } = renderHook(() => useUpdateCheck());
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.dismissed).toBe(true);
});
});