generated from DeskproApps/app-template-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.tsx
51 lines (49 loc) · 1.93 KB
/
jest.setup.tsx
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
import "regenerator-runtime/runtime";
import "@testing-library/jest-dom";
import "intersection-observer";
import { useQuery } from "@tanstack/react-query";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { TextDecoder, TextEncoder } from "util";
import * as React from "react";
import { lightTheme } from "@deskpro/deskpro-ui";
import { mockClient, mockContext } from "./testing";
import type { IDeskproClient } from "@deskpro/app-sdk";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
global.TextEncoder = TextEncoder;
//for some reason the types are wrong, but this works
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
global.TextDecoder = TextDecoder;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
global.React = React;
jest.mock("@deskpro/app-sdk", () => ({
...jest.requireActual("@deskpro/app-sdk"),
useDeskproAppClient: () => ({ client: mockClient }),
useDeskproAppEvents: (
hooks: { [key: string]: (param: Record<string, unknown>) => void },
deps: [] = []
) => {
React.useEffect(() => {
!!hooks.onChange && hooks.onChange(mockContext);
!!hooks.onShow && hooks.onShow(mockContext);
!!hooks.onReady && hooks.onReady(mockContext);
!!hooks.onAdminSettingsChange && hooks.onAdminSettingsChange(mockContext.settings);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, deps);
},
useInitialisedDeskproAppClient: (callback: (param: typeof mockClient) => void) => {
callback(mockClient);
},
useDeskproLatestAppContext: () => ({ context: mockContext }),
useDeskproAppTheme: () => ({ theme: lightTheme }),
proxyFetch: async () => fetch,
LoadingSpinner: () => <>Loading...</>,
useQueryWithClient: (
queryKey: string[],
queryFn: (client: IDeskproClient) => Promise<void>,
options: object,
) => useQuery(queryKey, () => queryFn(mockClient as never), options),
}));