-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
jest-setup.ts
113 lines (106 loc) · 3.45 KB
/
jest-setup.ts
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
/* eslint-disable no-undef, import/no-extraneous-dependencies */
import "@testing-library/react-native/extend-expect";
import { NativeModules } from "react-native";
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
function keyMirror(keys: string[]) {
const obj: Record<string, string> = {};
keys.forEach((key) => (obj[key] = key));
return obj;
}
// Mock of what the native code puts on the JS object
NativeModules.MLRNModule = {
// constants
UserTrackingModes: keyMirror([
"None",
"Follow",
"FollowWithCourse",
"FollowWithHeading",
]),
StyleURL: keyMirror(["Default"]),
EventTypes: keyMirror([
"MapClick",
"MapLongClick",
"RegionWillChange",
"RegionIsChanging",
"RegionDidChange",
"WillStartLoadingMap",
"DidFinishLoadingMap",
"DidFailLoadingMap",
"WillStartRenderingFrame",
"DidFinishRenderingFrame",
"DidFinishRenderingFrameFully",
"DidFinishLoadingStyle",
"SetCameraComplete",
]),
CameraModes: keyMirror(["Flight", "Ease", "None"]),
StyleSource: keyMirror(["DefaultSourceID"]),
InterpolationMode: keyMirror([
"Exponential",
"Categorical",
"Interval",
"Identity",
]),
LineJoin: keyMirror(["Bevel", "Round", "Miter"]),
LineCap: keyMirror(["Butt", "Round", "Square"]),
LineTranslateAnchor: keyMirror(["Map", "Viewport"]),
CirclePitchScale: keyMirror(["Map", "Viewport"]),
CircleTranslateAnchor: keyMirror(["Map", "Viewport"]),
FillExtrusionTranslateAnchor: keyMirror(["Map", "Viewport"]),
FillTranslateAnchor: keyMirror(["Map", "Viewport"]),
IconRotationAlignment: keyMirror(["Auto", "Map", "Viewport"]),
IconTextFit: keyMirror(["None", "Width", "Height", "Both"]),
IconTranslateAnchor: keyMirror(["Map", "Viewport"]),
SymbolPlacement: keyMirror(["Line", "Point"]),
TextAnchor: keyMirror([
"Center",
"Left",
"Right",
"Top",
"Bottom",
"TopLeft",
"TopRight",
"BottomLeft",
"BottomRight",
]),
TextJustify: keyMirror(["Center", "Left", "Right"]),
TextPitchAlignment: keyMirror(["Auto", "Map", "Viewport"]),
TextRotationAlignment: keyMirror(["Auto", "Map", "Viewport"]),
TextTransform: keyMirror(["None", "Lowercase", "Uppercase"]),
TextTranslateAnchor: keyMirror(["Map", "Viewport"]),
LightAnchor: keyMirror(["Map", "Viewport"]),
OfflinePackDownloadState: keyMirror(["Inactive", "Active", "Complete"]),
OfflineCallbackName: keyMirror(["Progress", "Error"]),
// methods
setAccessToken: jest.fn(),
getAccessToken: () => Promise.resolve("test-token"),
setConnected: jest.fn(),
};
NativeModules.MLRNOfflineModule = {
createPack: (packOptions: any) => {
return Promise.resolve({
bounds: packOptions.bounds,
metadata: JSON.stringify({ name: packOptions.name }),
});
},
getPacks: () => Promise.resolve([]),
deletePack: () => Promise.resolve(),
getPackStatus: () => Promise.resolve({}),
pausePackDownload: () => Promise.resolve(),
resumePackDownload: () => Promise.resolve(),
setPackObserver: () => Promise.resolve(),
setTileCountLimit: jest.fn(),
setProgressEventThrottle: jest.fn(),
};
NativeModules.MLRNSnapshotModule = {
takeSnap: () => {
return Promise.resolve("file://test.png");
},
};
NativeModules.MLRNLocationModule = {
getLastKnownLocation: jest.fn(),
setMinDisplacement: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
pause: jest.fn(),
};