Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

desktopUpdateReactQuery.test.ts

49 lines1.4 KB

1import { QueryClient } from "@tanstack/react-query";
2import { describe, expect, it } from "vitest";
3import type { DesktopUpdateState } from "@t3tools/contracts";
4import {
5 desktopUpdateQueryKeys,
6 desktopUpdateStateQueryOptions,
7 setDesktopUpdateStateQueryData,
8} from "./desktopUpdateReactQuery";
9​
10const baseState: DesktopUpdateState = {
11 enabled: true,
12 status: "idle",
13 currentVersion: "1.0.0",
14 hostArch: "x64",
15 appArch: "x64",
16 runningUnderArm64Translation: false,
17 availableVersion: null,
18 downloadedVersion: null,
19 downloadPercent: null,
20 checkedAt: null,
21 message: null,
22 errorContext: null,
23 canRetry: false,
24};
25​
26describe("desktopUpdateStateQueryOptions", () => {
27 it("always refetches on mount so Settings does not reuse stale desktop update state", () => {
28 const options = desktopUpdateStateQueryOptions();
29​
30 expect(options.staleTime).toBe(Infinity);
31 expect(options.refetchOnMount).toBe("always");
32 });
33});
34​
35describe("setDesktopUpdateStateQueryData", () => {
36 it("writes desktop update state into the shared cache key", () => {
37 const queryClient = new QueryClient();
38 const nextState: DesktopUpdateState = {
39 ...baseState,
40 status: "downloaded",
41 availableVersion: "1.1.0",
42 downloadedVersion: "1.1.0",
43 };
44​
45 setDesktopUpdateStateQueryData(queryClient, nextState);
46​
47 expect(queryClient.getQueryData(desktopUpdateQueryKeys.state())).toEqual(nextState);
48 });
49});