// @vitest-environment jsdom // // The YT player's progress checkpoint must reach the CACHE, not just the server. Before this, the // modal's cleanup only marked `qk.feed()` stale with `refetchType: "none"` — and nothing refetches // the feed until it remounts (staleTime 30s, refetchOnWindowFocus off), so reopening the same card // in the same session resumed from the position the cache had been fetched with, and the next // checkpoint then persisted THAT older value over the newer one. Measured on localdev before the // fix: played to 830s → closed (server had 830) → reopened → the row was back to 751s. // // Its own file on purpose: `loadYouTubeApi` memoises the API promise in a module-level singleton, // so a test that installs `window.YT` cannot share a module instance with tests that do not. import { describe, it, expect, vi, afterEach } from "vitest"; import { renderHook } from "@testing-library/react"; import { QueryClient } from "@tanstack/react-query"; import { createRef, type RefObject } from "react"; import { useYtProgress } from "./playerModalHooks"; import { patchCachedProgress, progressFlushes } from "./progressCache"; import { qk } from "./queryKeys"; import { api, type Video } from "./api"; import type { YTPlayer } from "./youtube"; const VID = "EC5oFYy9z9g"; const video = (over: Partial