-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
jest-setup.ts
80 lines (72 loc) · 2.12 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
/* eslint-disable no-undef, import/no-extraneous-dependencies */
import "@testing-library/react-native/extend-expect";
import { NativeModules } from "react-native";
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
UserTrackingMode: 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"]),
OfflinePackDownloadState: keyMirror(["Inactive", "Active", "Complete"]),
OfflineCallbackName: keyMirror(["Progress", "Error"]),
// Methods
setAccessToken: jest.fn(),
getAccessToken: () => Promise.resolve("test-token"),
addCustomHeader: jest.fn(),
removeCustomHeader: jest.fn(),
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(),
};