-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
69 lines (66 loc) · 2.29 KB
/
jest.setup.ts
File metadata and controls
69 lines (66 loc) · 2.29 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import "regenerator-runtime/runtime";
import "@testing-library/jest-dom/extend-expect";
import { useQuery } from "@tanstack/react-query";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { TextDecoder, TextEncoder } from "util";
import React from "react";
import { lightTheme } from "@deskpro/deskpro-ui";
import { mockClient } 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;
const deskproAppEventsObj = {
type: "ticket",
settings: {},
data: {
ticket: { id: "215", subject: "Big ticket", permalinkUrl: "https://permalink.url" },
app: {},
env: {},
currentAgent: {},
},
};
jest.mock("@deskpro/app-sdk", () => ({
...jest.requireActual("@deskpro/app-sdk"),
useDeskproAppClient: () => ({ client: mockClient }),
useDeskproLatestAppContext: () => ({
context: deskproAppEventsObj,
}),
useDeskproAppEvents: (
hooks: { [key: string]: (param: Record<string, unknown>) => void },
deps: [] = []
) => {
React.useEffect(() => {
!!hooks.onChange && hooks.onChange(deskproAppEventsObj);
!!hooks.onShow && hooks.onShow(deskproAppEventsObj);
!!hooks.onReady && hooks.onReady(deskproAppEventsObj);
!!hooks.onAdminSettingsChange && hooks.onAdminSettingsChange(deskproAppEventsObj.settings);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, deps);
},
useInitialisedDeskproAppClient: (
callback: (param: Record<string, unknown>) => void
) => {
callback({
registerElement: () => {},
deregisterElement: () => {},
setTitle: () => {},
});
},
useDeskproAppTheme: () => ({ theme: lightTheme }),
proxyFetch: async () => fetch,
LoadingSpinner: () => React.createElement("span", {}, "LoadingSpinner..."),
useQueryWithClient: (
queryKey: string[],
queryFn: (client: IDeskproClient) => Promise<void>,
options: object,
) => useQuery(queryKey, () => queryFn(mockClient as never), options),
}));