fix(library): a listing poll can no longer put back an older resume point
A poll already out when the player closed answered with the point the server held before the closing beacon, over the row's patch; Continue then opened there and wrote it back. The close now cancels the listings' fetches before patching and reads them again once the beacon has landed.
This commit is contained in:
@@ -198,6 +198,36 @@ describe("LibraryPlayer", () => {
|
||||
expect(rows.map((j) => j.position_seconds)).toEqual([125, undefined]);
|
||||
// Closing the player sends the point the way that survives the page going away.
|
||||
unmount();
|
||||
expect(beacon).toHaveBeenCalledWith(7, 125.4, 600);
|
||||
expect(beacon).toHaveBeenCalledWith(7, 125.4, 600, expect.any(Function));
|
||||
});
|
||||
|
||||
it("keeps the closing point over a list fetch that read the server before the point landed", async () => {
|
||||
// The listing polls. One already out when the player closed answered with the point the server
|
||||
// held BEFORE the closing beacon, over the row's patch — and Continue then opened there, and its
|
||||
// first checkpoint wrote that older point back over the right one.
|
||||
let settled: (() => void) | undefined;
|
||||
vi.spyOn(api, "saveDownloadProgressBeacon").mockImplementation((_id, _at, _dur, onSettled) => {
|
||||
settled = onSettled;
|
||||
});
|
||||
const client = new QueryClient();
|
||||
const job = withAsset({ width: 1280, height: 720 });
|
||||
client.setQueryData(qk.downloads(), [{ ...job, position_seconds: 10 }]);
|
||||
let answer: (jobs: DownloadJob[]) => void = () => {};
|
||||
const poll = client.fetchQuery({
|
||||
queryKey: qk.downloads(),
|
||||
queryFn: () => new Promise<DownloadJob[]>((r) => (answer = r)),
|
||||
});
|
||||
const { unmount } = render(<LibraryPlayer job={job} onClose={() => {}} />, client);
|
||||
const video = loaded();
|
||||
video.dispatchEvent(new Event("playing"));
|
||||
video.currentTime = 300;
|
||||
unmount();
|
||||
answer([{ ...job, position_seconds: 10 }]);
|
||||
await poll;
|
||||
expect(client.getQueryData<DownloadJob[]>(qk.downloads())![0]!.position_seconds).toBe(300);
|
||||
// Once the point has landed, the listing asks the server again.
|
||||
const invalidate = vi.spyOn(client, "invalidateQueries");
|
||||
settled?.();
|
||||
expect(invalidate).toHaveBeenCalledWith({ queryKey: qk.downloads(), exact: true });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user