forked from rnmapbox/maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-jest.js
122 lines (115 loc) · 3.36 KB
/
setup-jest.js
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
import {NativeModules} from 'react-native';
function keyMirror(keys) {
const obj = {};
keys.forEach((key) => (obj[key] = key));
return obj;
}
// Mock of what the native code puts on the JS object
NativeModules.MGLModule = {
// constants
UserTrackingModes: keyMirror([
'None',
'Follow',
'FollowWithCourse',
'FollowWithHeading',
]),
StyleURL: keyMirror([
'Street',
'Dark',
'Light',
'Outdoors',
'Satellite',
'SatelliteStreet',
'TrafficDay',
'TrafficNight',
]),
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'),
setTelemetryEnabled: jest.fn(),
setConnected: jest.fn(),
};
NativeModules.MGLOfflineModule = {
createPack: (packOptions) => {
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.MGLSnapshotModule = {
takeSnap: () => {
return Promise.resolve('file://test.png');
},
};
NativeModules.MGLLocationModule = {
getLastKnownLocation: jest.fn(),
start: jest.fn(),
pause: jest.fn(),
};
// Mock for AbortController. Will probably not be required during testing.
window = {};
window.AbortController = class {
abort = jest.fn();
};