-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuse-subscriptions.spec.ts
More file actions
52 lines (40 loc) · 1.59 KB
/
use-subscriptions.spec.ts
File metadata and controls
52 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { it, vi } from "vitest";
import fc from "fast-check";
import type {
CtrlStateQuery,
CtrlStateSSubscription,
CtrlRunNoQuery,
CtrlRunNoSSubscription,
} from "@/graphql/codegen/generated";
import { useSubscribeRunNo } from "../use-run-no-subscription";
import { useSubscribeState } from "../use-state-subscription";
import { runPropertyTest } from "./run-property-test";
// Mock functions used in runPropertyTest()
vi.mock("@urql/vue", () => ({
useQuery: vi.fn(),
useSubscription: vi.fn(),
}));
it("useSubscribeState", async () => {
type QueryData = CtrlStateQuery;
type SubData = CtrlStateSSubscription;
const mapQuery = (d: QueryData | undefined) => d?.ctrl.state;
const mapSub = (d: SubData | undefined) => d?.ctrlState;
const fcCtrlState = fc.string();
const fcQueryData: fc.Arbitrary<QueryData> = fc.record({
ctrl: fc.record({ state: fcCtrlState }),
});
const fcSubData: fc.Arbitrary<SubData> = fc.record({ ctrlState: fcCtrlState });
await runPropertyTest(useSubscribeState, mapQuery, mapSub, fcQueryData, fcSubData);
});
it("useSubscribeRunNo", async () => {
type QueryData = CtrlRunNoQuery;
type SubData = CtrlRunNoSSubscription;
const mapQuery = (d: QueryData | undefined) => d?.ctrl.runNo;
const mapSub = (d: SubData | undefined) => d?.ctrlRunNo;
const fcCtrlRunNo = fc.integer();
const fcQueryData: fc.Arbitrary<QueryData> = fc.record({
ctrl: fc.record({ runNo: fcCtrlRunNo }),
});
const fcSubData: fc.Arbitrary<SubData> = fc.record({ ctrlRunNo: fcCtrlRunNo });
await runPropertyTest(useSubscribeRunNo, mapQuery, mapSub, fcQueryData, fcSubData);
});