-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.tsx
More file actions
135 lines (131 loc) · 3.38 KB
/
jest.setup.tsx
File metadata and controls
135 lines (131 loc) · 3.38 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* eslint-disable @typescript-eslint/no-explicit-any */
import "regenerator-runtime/runtime";
import "@testing-library/jest-dom/extend-expect";
import { TextDecoder, TextEncoder } from "util";
import * as React from "react";
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("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useNavigate: () => jest.fn(),
useLocation: () => jest.fn(),
useParams: () => ({ submitType: "file" }),
}));
jest.mock("./src/styles.ts", () => ({
...jest.requireActual("./src/styles.ts"),
StyledLink: () => <div>StyledLink</div>,
}));
jest.mock("@deskpro/app-sdk", () => ({
...jest.requireActual("@deskpro/app-sdk"),
useDeskproAppClient: () => ({
client: {
setHeight: () => {},
getEntityAssociation: () => ({
list: () => {},
delete: () => {},
set: () => {},
}),
},
}),
useDeskproAppEvents: (
hooks: { [key: string]: (param: Record<string, unknown>) => void },
deps: [] = []
) => {
const deskproAppEventsObj = {
data: {
ticket: {
id: 1,
subject: "Test Ticket",
},
},
};
React.useEffect(() => {
!!hooks.onChange && hooks.onChange(deskproAppEventsObj);
!!hooks.onShow && hooks.onShow(deskproAppEventsObj);
!!hooks.onReady && hooks.onReady(deskproAppEventsObj);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, deps);
},
useDeskproAppTheme: () => ({
theme: {
colors: {},
},
}),
useInitialisedDeskproAppClient: (
callback: (param: Record<string, unknown>) => void
) => {
callback({
registerElement: () => {},
deregisterElement: () => {},
setHeight: () => {},
setTitle: () => {},
});
},
proxyFetch: async () => fetch,
HorizontalDivider: ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
),
useQueryWithClient: (queryKey: string, queryFn: () => any, options: any) => {
queryKey;
options;
if (!options || options?.enabled == null || options?.enabled == true) {
return {
isSuccess: true,
data: queryFn(),
isLoading: false,
};
}
return {
isSuccess: false,
data: null,
isLoading: false,
};
},
useMutationWithClient: () => {
return {
mutate: () => {},
isSuccess: true,
isLoading: false,
data: {
result: {
id: 1,
name: {
displayName: "Michael Something",
},
description: "This is a contact description",
email: "email@email.com",
phone: "123456789",
account: "Company",
owner: {
name: "John Doe",
},
tags: ["Test tag"],
address: {
"--primary": {
address_1: "123 Main Street",
address_2: "Apt 1",
adress_3: "Suite 1",
},
},
leads: [],
notes: [],
},
},
};
},
useDeskproLatestAppContext: () => ({
context: {
data: {
user: {
primaryEmail: "email@email.com",
},
},
},
}),
}));