@blotch/angular-lynx-testing-library 22.3.2 → 22.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-state.d.ts.map +1 -1
- package/dist/app-state.js +2 -26
- package/dist/audio-recorder.d.ts +95 -0
- package/dist/audio-recorder.d.ts.map +1 -0
- package/dist/audio-recorder.js +250 -0
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +58 -8
- package/dist/geolocation.d.ts +94 -0
- package/dist/geolocation.d.ts.map +1 -0
- package/dist/geolocation.js +255 -0
- package/dist/global-props.d.ts +17 -0
- package/dist/global-props.d.ts.map +1 -0
- package/dist/global-props.js +35 -0
- package/dist/image-picker.d.ts +84 -0
- package/dist/image-picker.d.ts.map +1 -0
- package/dist/image-picker.js +140 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/network.d.ts +26 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +31 -0
- package/dist/setup.js +27 -7
- package/package.json +2 -2
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/** What `LynxGeolocation` calls and hears, named as the shells name them. */
|
|
2
|
+
const MODULE = 'AngularLynxGeolocation';
|
|
3
|
+
const EVENT = 'angularLynxGeolocation';
|
|
4
|
+
const environment = () => globalThis.lynxTestingEnv;
|
|
5
|
+
/**
|
|
6
|
+
* Sends one of the shells' global events. They arrive on the background
|
|
7
|
+
* thread, whose listener calls the app's on the main thread, so the event is
|
|
8
|
+
* sent from it. A fake method the runtime called is on that thread already;
|
|
9
|
+
* a spec is on the main thread, which comes back afterwards.
|
|
10
|
+
*/
|
|
11
|
+
const emit = (payload) => {
|
|
12
|
+
const env = environment();
|
|
13
|
+
const background = env.backgroundThread.globalThis;
|
|
14
|
+
const onMainThread = globalThis.lynx !== background.lynx;
|
|
15
|
+
if (onMainThread)
|
|
16
|
+
env.switchToBackgroundThread();
|
|
17
|
+
try {
|
|
18
|
+
background.lynx.getJSModule('GlobalEventEmitter').emit(EVENT, [payload]);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
if (onMainThread)
|
|
22
|
+
env.switchToMainThread();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const failure = (error, message) => ({ error, message });
|
|
26
|
+
/**
|
|
27
|
+
* The state the shells report: Location being off comes first.
|
|
28
|
+
*/
|
|
29
|
+
const stateOf = (state) => state.enabled ? state.permission : 'off';
|
|
30
|
+
/**
|
|
31
|
+
* A location as the shells send it.
|
|
32
|
+
*/
|
|
33
|
+
const positionOf = (location) => ({
|
|
34
|
+
latitude: location.latitude,
|
|
35
|
+
longitude: location.longitude,
|
|
36
|
+
accuracy: location.accuracy ?? 5,
|
|
37
|
+
altitude: location.altitude ?? null,
|
|
38
|
+
altitudeAccuracy: location.altitudeAccuracy ?? null,
|
|
39
|
+
heading: location.heading ?? null,
|
|
40
|
+
speed: location.speed ?? null,
|
|
41
|
+
timestamp: location.timestamp ?? Date.now(),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* The distance between two locations in meters, on a spherical Earth.
|
|
45
|
+
*/
|
|
46
|
+
const metersBetween = (a, b) => {
|
|
47
|
+
const radians = Math.PI / 180;
|
|
48
|
+
const dLat = (b.latitude - a.latitude) * radians;
|
|
49
|
+
const dLon = (b.longitude - a.longitude) * radians;
|
|
50
|
+
const h = Math.sin(dLat / 2) ** 2 +
|
|
51
|
+
Math.cos(a.latitude * radians) *
|
|
52
|
+
Math.cos(b.latitude * radians) *
|
|
53
|
+
Math.sin(dLon / 2) ** 2;
|
|
54
|
+
return 2 * 6_371_000 * Math.asin(Math.sqrt(h));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Sends `location` to a watch, unless it's nearer the last one it got than
|
|
58
|
+
* its distance filter, as the shells filter.
|
|
59
|
+
*/
|
|
60
|
+
const deliver = (id, watch, location) => {
|
|
61
|
+
if (watch.last &&
|
|
62
|
+
metersBetween(watch.last, location) < watch.distanceFilter) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
watch.last = location;
|
|
66
|
+
emit({ type: 'position', watch: id, position: positionOf(location) });
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Ends every watch, as the shells do when the app may no longer find the phone.
|
|
70
|
+
*/
|
|
71
|
+
const endWatches = (state, error) => {
|
|
72
|
+
for (const id of state.watches.keys()) {
|
|
73
|
+
emit({ type: 'watchStopped', watch: id, ...error });
|
|
74
|
+
}
|
|
75
|
+
state.watches.clear();
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Gives the environment's background thread an `AngularLynxGeolocation`
|
|
79
|
+
* module, as the apps `ng build --platform` makes have when angular.json's
|
|
80
|
+
* `permissions` list `location`. It starts where a fresh install does: the
|
|
81
|
+
* person hasn't been asked, allows precise location when the app asks, and
|
|
82
|
+
* the phone has no position until {@link setLocation} gives it one.
|
|
83
|
+
* `LynxGeolocation` reaches it through the background thread, as it reaches
|
|
84
|
+
* the shells' module, so specs see the runtime's own behavior.
|
|
85
|
+
*
|
|
86
|
+
* It runs each time the environment injects the background thread's
|
|
87
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
88
|
+
* starts from a fresh install.
|
|
89
|
+
*/
|
|
90
|
+
export const installGeolocationModule = (threadGlobals) => {
|
|
91
|
+
const state = {
|
|
92
|
+
permission: 'unknown',
|
|
93
|
+
answer: 'precise',
|
|
94
|
+
enabled: true,
|
|
95
|
+
location: null,
|
|
96
|
+
prompts: 0,
|
|
97
|
+
watches: new Map(),
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Shows the prompt when the person hasn't been asked, as the shells do
|
|
101
|
+
* before the first position, and answers what the spec said to.
|
|
102
|
+
*/
|
|
103
|
+
const ask = () => {
|
|
104
|
+
if (state.permission !== 'unknown')
|
|
105
|
+
return;
|
|
106
|
+
state.prompts++;
|
|
107
|
+
state.permission = state.answer;
|
|
108
|
+
emit({ type: 'state', state: stateOf(state) });
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Why the app can't find the phone now, or undefined when it can.
|
|
112
|
+
*/
|
|
113
|
+
const refusal = () => {
|
|
114
|
+
if (!state.enabled) {
|
|
115
|
+
return failure('off', 'Location is turned off for the phone.');
|
|
116
|
+
}
|
|
117
|
+
ask();
|
|
118
|
+
return state.permission === 'denied'
|
|
119
|
+
? failure('denied', "The app isn't allowed to find the phone.")
|
|
120
|
+
: undefined;
|
|
121
|
+
};
|
|
122
|
+
const module = {
|
|
123
|
+
state,
|
|
124
|
+
getState(done) {
|
|
125
|
+
done({ state: stateOf(state) });
|
|
126
|
+
},
|
|
127
|
+
requestPermission(done) {
|
|
128
|
+
ask();
|
|
129
|
+
done({ state: stateOf(state) });
|
|
130
|
+
},
|
|
131
|
+
getCurrentPosition(_options, done) {
|
|
132
|
+
const refused = refusal();
|
|
133
|
+
if (refused)
|
|
134
|
+
return done(refused);
|
|
135
|
+
// A phone that can't find itself answers once the time is up.
|
|
136
|
+
if (!state.location) {
|
|
137
|
+
return done(failure('timeout', 'No position came in time: setLocation() gives the fake one.'));
|
|
138
|
+
}
|
|
139
|
+
done({ position: positionOf(state.location) });
|
|
140
|
+
},
|
|
141
|
+
startWatch({ watch: id, distanceFilter }, done) {
|
|
142
|
+
const refused = refusal();
|
|
143
|
+
if (refused)
|
|
144
|
+
return done(refused);
|
|
145
|
+
const watch = { distanceFilter };
|
|
146
|
+
state.watches.set(id, watch);
|
|
147
|
+
done({});
|
|
148
|
+
// A phone that knows where it is reports it soon after the start.
|
|
149
|
+
if (state.location)
|
|
150
|
+
deliver(id, watch, state.location);
|
|
151
|
+
},
|
|
152
|
+
stopWatch(id, done) {
|
|
153
|
+
state.watches.delete(id);
|
|
154
|
+
done({});
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
threadGlobals.NativeModules = {
|
|
158
|
+
...threadGlobals.NativeModules,
|
|
159
|
+
[MODULE]: module,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The fake module's state in this test's environment. Read through the
|
|
164
|
+
* environment rather than kept here: under `ng test`, the setup file and the
|
|
165
|
+
* specs can load different copies of this module.
|
|
166
|
+
*/
|
|
167
|
+
const fakeState = (caller) => {
|
|
168
|
+
const module = environment()?.backgroundThread.globalThis.NativeModules?.[MODULE];
|
|
169
|
+
if (!module) {
|
|
170
|
+
throw new Error(`${caller}() needs the testing library's environment, which its setup file installs.`);
|
|
171
|
+
}
|
|
172
|
+
return module.state;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Puts the phone at `location`, or nowhere it can find with `null`: what
|
|
176
|
+
* `LynxGeolocation.getCurrentPosition()` resolves with, and the next
|
|
177
|
+
* position each running watch gets, unless it's nearer the last one than
|
|
178
|
+
* the watch's `distanceFilter`. Until a spec sets one, the phone can't find
|
|
179
|
+
* itself, and `getCurrentPosition()` rejects with `timeout`.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* setLocationPermission('precise');
|
|
184
|
+
* setLocation({ latitude: 51.5007, longitude: -0.1246 });
|
|
185
|
+
* await render(NearbyShops);
|
|
186
|
+
* expect(await screen.findByText('2 shops near you')).toBeInTheDocument();
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export const setLocation = (location) => {
|
|
190
|
+
const state = fakeState('setLocation');
|
|
191
|
+
// A copy, so a spec that moves one object and sets it again still moves
|
|
192
|
+
// the phone: each watch compares the new position with the one it kept.
|
|
193
|
+
const stored = location && { ...location };
|
|
194
|
+
state.location = stored;
|
|
195
|
+
if (!stored)
|
|
196
|
+
return;
|
|
197
|
+
for (const [id, watch] of state.watches)
|
|
198
|
+
deliver(id, watch, stored);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Sets what the app is allowed, as if the person had answered the prompt or
|
|
202
|
+
* changed it in Settings: what `LynxGeolocation.state()` reports, without a
|
|
203
|
+
* prompt unless it's `unknown` (each test starts there). `denied` ends every
|
|
204
|
+
* running watch, as it does on a phone.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* setLocationPermission('denied');
|
|
209
|
+
* await render(NearbyShops);
|
|
210
|
+
* expect(screen.getByText('Allow location in Settings')).toBeInTheDocument();
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export const setLocationPermission = (permission) => {
|
|
214
|
+
const state = fakeState('setLocationPermission');
|
|
215
|
+
state.permission = permission;
|
|
216
|
+
emit({ type: 'state', state: stateOf(state) });
|
|
217
|
+
if (permission === 'denied' && state.enabled) {
|
|
218
|
+
endWatches(state, failure('denied', "The app isn't allowed to find the phone."));
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Sets what the person answers when `LynxGeolocation` shows the prompt:
|
|
223
|
+
* `precise` (the default), `approximate` (Android 12's and iOS's choice of
|
|
224
|
+
* an approximate location), or `denied`. The prompt shows only while the
|
|
225
|
+
* permission is `unknown`.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* setLocationAnswer('approximate');
|
|
230
|
+
* fireEvent.tap(screen.getByText('Find shops near me'));
|
|
231
|
+
* await waitForUpdate();
|
|
232
|
+
* expect(locationPrompts()).toBe(1);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export const setLocationAnswer = (answer) => {
|
|
236
|
+
fakeState('setLocationAnswer').answer = answer;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Turns Location on or off for the whole phone. Off, the state is `off`,
|
|
240
|
+
* whatever the app is allowed, every call rejects with `off`, and every
|
|
241
|
+
* running watch ends with it.
|
|
242
|
+
*/
|
|
243
|
+
export const setLocationEnabled = (enabled) => {
|
|
244
|
+
const state = fakeState('setLocationEnabled');
|
|
245
|
+
state.enabled = enabled;
|
|
246
|
+
emit({ type: 'state', state: stateOf(state) });
|
|
247
|
+
if (!enabled) {
|
|
248
|
+
endWatches(state, failure('off', 'Location is turned off for the phone.'));
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* How many times the location prompt has shown in this test, so a spec can
|
|
253
|
+
* check the app asks at the right moment, and only once.
|
|
254
|
+
*/
|
|
255
|
+
export const locationPrompts = () => fakeState('locationPrompts').prompts;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changes one of the host's global props, as a shell does when what it sends
|
|
3
|
+
* changes (the app leaves the screen, the phone goes offline): the runtime
|
|
4
|
+
* hears it as it does on a phone, so change detection runs on its own.
|
|
5
|
+
*
|
|
6
|
+
* Each test starts with the environment's own props: its reset after each
|
|
7
|
+
* test gives each thread a fresh `lynx`, and each `render()` a fresh root
|
|
8
|
+
* injector that reads them again, so a change can't leak into the next test.
|
|
9
|
+
*
|
|
10
|
+
* @param name - The global prop, as the shells send it.
|
|
11
|
+
* @param value - Its new value.
|
|
12
|
+
* @param caller - The public function that called this, named in the error.
|
|
13
|
+
* @throws Error outside the testing library's environment, or before the
|
|
14
|
+
* runtime has loaded.
|
|
15
|
+
*/
|
|
16
|
+
export declare const setGlobalProp: (name: string, value: unknown, caller: string) => void;
|
|
17
|
+
//# sourceMappingURL=global-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-props.d.ts","sourceRoot":"","sources":["../src/global-props.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,EACZ,OAAO,OAAO,EACd,QAAQ,MAAM,KACb,IAyBF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changes one of the host's global props, as a shell does when what it sends
|
|
3
|
+
* changes (the app leaves the screen, the phone goes offline): the runtime
|
|
4
|
+
* hears it as it does on a phone, so change detection runs on its own.
|
|
5
|
+
*
|
|
6
|
+
* Each test starts with the environment's own props: its reset after each
|
|
7
|
+
* test gives each thread a fresh `lynx`, and each `render()` a fresh root
|
|
8
|
+
* injector that reads them again, so a change can't leak into the next test.
|
|
9
|
+
*
|
|
10
|
+
* @param name - The global prop, as the shells send it.
|
|
11
|
+
* @param value - Its new value.
|
|
12
|
+
* @param caller - The public function that called this, named in the error.
|
|
13
|
+
* @throws Error outside the testing library's environment, or before the
|
|
14
|
+
* runtime has loaded.
|
|
15
|
+
*/
|
|
16
|
+
export const setGlobalProp = (name, value, caller) => {
|
|
17
|
+
// Read through the environment rather than kept here: under `ng test`, the
|
|
18
|
+
// setup file and the specs can load different copies of this module.
|
|
19
|
+
const env = globalThis.lynxTestingEnv;
|
|
20
|
+
// The runtime's callback for the engine, which it puts on the global as it
|
|
21
|
+
// loads: specs run on the main thread, whose globals the environment copies
|
|
22
|
+
// there.
|
|
23
|
+
const update = globalThis.updateGlobalProps;
|
|
24
|
+
if (!env || typeof update !== 'function') {
|
|
25
|
+
throw new Error(`${caller}() needs the testing library's environment, which its setup file installs, and the runtime, which render() loads.`);
|
|
26
|
+
}
|
|
27
|
+
// The background thread's props, as the engine keeps both threads'. The
|
|
28
|
+
// environment gives each thread a `lynx`.
|
|
29
|
+
const background = env.backgroundThread.globalThis.lynx;
|
|
30
|
+
background.__globalProps = { ...background.__globalProps, [name]: value };
|
|
31
|
+
// What the engine calls on the main thread, where the app runs, when the
|
|
32
|
+
// host sends new global props: the runtime merges them and LynxGlobalData
|
|
33
|
+
// hears them.
|
|
34
|
+
update({ ...env.mainThread.globalThis.lynx.__globalProps, [name]: value });
|
|
35
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** An image {@link setPickedImage} or {@link setTakenPhoto} hands the app. */
|
|
2
|
+
export type FakeImage = {
|
|
3
|
+
/** Its file name, such as `me.jpg`. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Its MIME type. `image/jpeg` when it's left out. */
|
|
6
|
+
readonly type?: string;
|
|
7
|
+
/** Its bytes, or text, which is stored as UTF-8. */
|
|
8
|
+
readonly content: string | Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
/** Where `LynxImagePicker.pick()` gets the image, as its `source` names it. */
|
|
11
|
+
export type FakeImageSource = 'library' | 'camera';
|
|
12
|
+
/** Why a pick gave no image, as `ImagePickerError`'s `code` names it. */
|
|
13
|
+
export type ImagePickFailure = 'unavailable' | 'denied' | 'failed';
|
|
14
|
+
/** A pick the app asked for, as {@link imagePickerRequests} lists it. */
|
|
15
|
+
export type ImagePickerRequest = {
|
|
16
|
+
readonly source: FakeImageSource;
|
|
17
|
+
readonly maxDimension?: number;
|
|
18
|
+
readonly quality?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Gives the environment's background thread an `AngularLynxImagePicker`
|
|
22
|
+
* module, as the apps `ng build --platform` makes have, with the camera's
|
|
23
|
+
* `takePhoto` that `permissions.camera` brings. There's no library to pick
|
|
24
|
+
* from nor camera to point in a spec, so each source rejects with
|
|
25
|
+
* `unavailable` until a spec says what the person picks
|
|
26
|
+
* ({@link setPickedImage}) or takes ({@link setTakenPhoto}), or how it ends
|
|
27
|
+
* ({@link failImagePicker}). The runtime reaches it through the background
|
|
28
|
+
* thread, as it reaches the shells' module, so specs see the runtime's own
|
|
29
|
+
* behavior.
|
|
30
|
+
*
|
|
31
|
+
* The image comes back as the spec gave it: the fake doesn't scale or
|
|
32
|
+
* re-encode it for `maxDimension` or `quality`, which
|
|
33
|
+
* {@link imagePickerRequests} shows the app asked for.
|
|
34
|
+
*
|
|
35
|
+
* It runs each time the environment injects the background thread's
|
|
36
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
37
|
+
* starts with nothing to pick and no requests.
|
|
38
|
+
*/
|
|
39
|
+
export declare const installImagePickerModule: (threadGlobals: {
|
|
40
|
+
NativeModules?: Record<string, unknown>;
|
|
41
|
+
}) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Has the person pick `image` from the library each time the app opens
|
|
44
|
+
* `LynxImagePicker`'s picker in this test, so `pick()` resolves with it, or
|
|
45
|
+
* close the picker without choosing with `null`, so `pick()` resolves with
|
|
46
|
+
* `null`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* setPickedImage({ name: 'me.jpg', content: jpegBytes });
|
|
51
|
+
* fireEvent.tap(screen.getByText('Choose from library'));
|
|
52
|
+
* await waitForUpdate();
|
|
53
|
+
* expect(screen.getByText('me.jpg')).toBeInTheDocument();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const setPickedImage: (image: FakeImage | null) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Has the person take `image` with the camera each time the app opens it
|
|
59
|
+
* with `pick({ source: 'camera' })` in this test, or close the camera
|
|
60
|
+
* without taking one with `null`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* setTakenPhoto({ name: 'IMG_20261129_142305.jpg', content: jpegBytes });
|
|
65
|
+
* fireEvent.tap(screen.getByText('Take photo'));
|
|
66
|
+
* await waitForUpdate();
|
|
67
|
+
* expect(screen.getByText('Receipt added')).toBeInTheDocument();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const setTakenPhoto: (image: FakeImage | null) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Has `LynxImagePicker.pick()` reject with an `ImagePickerError` of `code`
|
|
73
|
+
* for the rest of this test: `denied` for a person who doesn't let the app
|
|
74
|
+
* use the camera, `unavailable` for a phone without one, or `failed`. Both
|
|
75
|
+
* sources fail when `source` is left out.
|
|
76
|
+
*/
|
|
77
|
+
export declare const failImagePicker: (code: ImagePickFailure, source?: FakeImageSource) => void;
|
|
78
|
+
/**
|
|
79
|
+
* The picks the app asked for in this test, oldest first: where from, and
|
|
80
|
+
* the `maxDimension` and `quality` it asked for (whole pixels, as the
|
|
81
|
+
* runtime sends them to the shells).
|
|
82
|
+
*/
|
|
83
|
+
export declare const imagePickerRequests: () => readonly ImagePickerRequest[];
|
|
84
|
+
//# sourceMappingURL=image-picker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-picker.d.ts","sourceRoot":"","sources":["../src/image-picker.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG;IACtB,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;CACvC,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnD,yEAAyE;AACzE,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAiCF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IA8BH,CAAC;AA2BF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,GAAG,IAAI,KAAG,IAExD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,SAAS,GAAG,IAAI,KAAG,IAEvD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,gBAAgB,EACtB,SAAS,eAAe,KACvB,IASF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,SAAS,kBAAkB,EAEjE,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** What `LynxImagePicker` calls, as the shells name their module. */
|
|
2
|
+
const MODULE = 'AngularLynxImagePicker';
|
|
3
|
+
/**
|
|
4
|
+
* What a source answers before a spec says what the person picks: the
|
|
5
|
+
* runtime's own `unavailable`, as a host without the shells' module gives,
|
|
6
|
+
* so a spec written before this fake, which expected that, still passes.
|
|
7
|
+
*/
|
|
8
|
+
const UNSET = {
|
|
9
|
+
error: 'unavailable',
|
|
10
|
+
message: 'The testing library has no image for LynxImagePicker. Give it one with setPickedImage() or setTakenPhoto().',
|
|
11
|
+
};
|
|
12
|
+
const toBase64 = (content) => {
|
|
13
|
+
const bytes = typeof content === 'string' ? new TextEncoder().encode(content) : content;
|
|
14
|
+
let binary = '';
|
|
15
|
+
for (const byte of bytes)
|
|
16
|
+
binary += String.fromCharCode(byte);
|
|
17
|
+
return btoa(binary);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Gives the environment's background thread an `AngularLynxImagePicker`
|
|
21
|
+
* module, as the apps `ng build --platform` makes have, with the camera's
|
|
22
|
+
* `takePhoto` that `permissions.camera` brings. There's no library to pick
|
|
23
|
+
* from nor camera to point in a spec, so each source rejects with
|
|
24
|
+
* `unavailable` until a spec says what the person picks
|
|
25
|
+
* ({@link setPickedImage}) or takes ({@link setTakenPhoto}), or how it ends
|
|
26
|
+
* ({@link failImagePicker}). The runtime reaches it through the background
|
|
27
|
+
* thread, as it reaches the shells' module, so specs see the runtime's own
|
|
28
|
+
* behavior.
|
|
29
|
+
*
|
|
30
|
+
* The image comes back as the spec gave it: the fake doesn't scale or
|
|
31
|
+
* re-encode it for `maxDimension` or `quality`, which
|
|
32
|
+
* {@link imagePickerRequests} shows the app asked for.
|
|
33
|
+
*
|
|
34
|
+
* It runs each time the environment injects the background thread's
|
|
35
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
36
|
+
* starts with nothing to pick and no requests.
|
|
37
|
+
*/
|
|
38
|
+
export const installImagePickerModule = (threadGlobals) => {
|
|
39
|
+
const answer = (module, source, request, done) => {
|
|
40
|
+
module.requests.push({
|
|
41
|
+
source,
|
|
42
|
+
...(request.maxDimension !== undefined && {
|
|
43
|
+
maxDimension: request.maxDimension,
|
|
44
|
+
}),
|
|
45
|
+
...(request.quality !== undefined && { quality: request.quality }),
|
|
46
|
+
});
|
|
47
|
+
done(module.answers[source]);
|
|
48
|
+
};
|
|
49
|
+
const module = {
|
|
50
|
+
answers: { library: UNSET, camera: UNSET },
|
|
51
|
+
requests: [],
|
|
52
|
+
pick(request, done) {
|
|
53
|
+
answer(this, 'library', request, done);
|
|
54
|
+
},
|
|
55
|
+
takePhoto(request, done) {
|
|
56
|
+
answer(this, 'camera', request, done);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
threadGlobals.NativeModules = {
|
|
60
|
+
...threadGlobals.NativeModules,
|
|
61
|
+
[MODULE]: module,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The fake module, read through the environment rather than kept here:
|
|
66
|
+
* under `ng test`, the setup file and the specs can load different copies of
|
|
67
|
+
* this module.
|
|
68
|
+
*/
|
|
69
|
+
const fakeModule = (helper) => {
|
|
70
|
+
const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
|
|
71
|
+
.NativeModules?.[MODULE];
|
|
72
|
+
if (!module) {
|
|
73
|
+
throw new Error(`${helper}() needs the testing library's environment, which its setup file installs.`);
|
|
74
|
+
}
|
|
75
|
+
return module;
|
|
76
|
+
};
|
|
77
|
+
const imageAnswer = (image) => image === null
|
|
78
|
+
? { canceled: true }
|
|
79
|
+
: {
|
|
80
|
+
base64: toBase64(image.content),
|
|
81
|
+
name: image.name,
|
|
82
|
+
type: image.type ?? 'image/jpeg',
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Has the person pick `image` from the library each time the app opens
|
|
86
|
+
* `LynxImagePicker`'s picker in this test, so `pick()` resolves with it, or
|
|
87
|
+
* close the picker without choosing with `null`, so `pick()` resolves with
|
|
88
|
+
* `null`.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* setPickedImage({ name: 'me.jpg', content: jpegBytes });
|
|
93
|
+
* fireEvent.tap(screen.getByText('Choose from library'));
|
|
94
|
+
* await waitForUpdate();
|
|
95
|
+
* expect(screen.getByText('me.jpg')).toBeInTheDocument();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export const setPickedImage = (image) => {
|
|
99
|
+
fakeModule('setPickedImage').answers.library = imageAnswer(image);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Has the person take `image` with the camera each time the app opens it
|
|
103
|
+
* with `pick({ source: 'camera' })` in this test, or close the camera
|
|
104
|
+
* without taking one with `null`.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* setTakenPhoto({ name: 'IMG_20261129_142305.jpg', content: jpegBytes });
|
|
109
|
+
* fireEvent.tap(screen.getByText('Take photo'));
|
|
110
|
+
* await waitForUpdate();
|
|
111
|
+
* expect(screen.getByText('Receipt added')).toBeInTheDocument();
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export const setTakenPhoto = (image) => {
|
|
115
|
+
fakeModule('setTakenPhoto').answers.camera = imageAnswer(image);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Has `LynxImagePicker.pick()` reject with an `ImagePickerError` of `code`
|
|
119
|
+
* for the rest of this test: `denied` for a person who doesn't let the app
|
|
120
|
+
* use the camera, `unavailable` for a phone without one, or `failed`. Both
|
|
121
|
+
* sources fail when `source` is left out.
|
|
122
|
+
*/
|
|
123
|
+
export const failImagePicker = (code, source) => {
|
|
124
|
+
const module = fakeModule('failImagePicker');
|
|
125
|
+
const failure = {
|
|
126
|
+
error: code,
|
|
127
|
+
message: `The testing library's image picker failed with ${code}.`,
|
|
128
|
+
};
|
|
129
|
+
for (const each of source ? [source] : ['library', 'camera']) {
|
|
130
|
+
module.answers[each] = failure;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* The picks the app asked for in this test, oldest first: where from, and
|
|
135
|
+
* the `maxDimension` and `quality` it asked for (whole pixels, as the
|
|
136
|
+
* runtime sends them to the shells).
|
|
137
|
+
*/
|
|
138
|
+
export const imagePickerRequests = () => [
|
|
139
|
+
...fakeModule('imagePickerRequests').requests,
|
|
140
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,19 @@ export { biometricPrompts, queueBiometricResult, setBiometrics, } from './biomet
|
|
|
8
8
|
export type { BiometricPrompt, BiometricResult, FakeBiometrics, } from './biometrics.js';
|
|
9
9
|
export { savedFiles, setFilePickerCanceled, setPickedFiles, } from './file-picker.js';
|
|
10
10
|
export type { FakePickedFile, SavedFile } from './file-picker.js';
|
|
11
|
+
export { failImagePicker, imagePickerRequests, setPickedImage, setTakenPhoto, } from './image-picker.js';
|
|
12
|
+
export type { FakeImage, FakeImageSource, ImagePickerRequest, ImagePickFailure, } from './image-picker.js';
|
|
11
13
|
export { cancelBarcodeScan, failBarcodeScan, queueBarcodeScan, } from './barcode-scanner.js';
|
|
12
14
|
export type { BarcodeScanFailure, QueuedBarcodeScan, } from './barcode-scanner.js';
|
|
15
|
+
export { locationPrompts, setLocation, setLocationAnswer, setLocationEnabled, setLocationPermission, } from './geolocation.js';
|
|
16
|
+
export type { FakeLocation, FakeLocationPermission } from './geolocation.js';
|
|
13
17
|
export { addBluetoothDevice, setBluetoothState } from './bluetooth.js';
|
|
14
18
|
export type { FakeBluetoothCharacteristic, FakeBluetoothDevice, FakeBluetoothDeviceRef, FakeBluetoothWrite, } from './bluetooth.js';
|
|
15
19
|
export { fireEvent, eventMap } from './fire-event.js';
|
|
16
20
|
export { savedPhotos, setPhotoLibraryPermission } from './photo-library.js';
|
|
17
21
|
export type { FakePhotoLibraryPermission, SavedPhoto, } from './photo-library.js';
|
|
18
22
|
export { openedURLs, openLink } from './linking.js';
|
|
23
|
+
export { setOnline } from './network.js';
|
|
19
24
|
export { emitMotion, setHeading, shakeDevice } from './motion.js';
|
|
20
25
|
export type { EmittedHeading, EmittedMotion, MotionVector } from './motion.js';
|
|
21
26
|
export type { OpenedURL } from './linking.js';
|
|
@@ -27,6 +32,8 @@ export { setTrackingAnswer, setTrackingStatus, trackingPrompts, } from './tracki
|
|
|
27
32
|
export type { FakeTrackingStatus } from './tracking.js';
|
|
28
33
|
export { answerCalendarSheet, calendarEvents, failCalendarSheet, } from './calendar.js';
|
|
29
34
|
export type { CalendarSheetAnswer, CalendarSheetEvent, CalendarSheetFailure, } from './calendar.js';
|
|
35
|
+
export { audioRecording, emitAudioLevel, failAudioRecording, interruptAudioRecording, setMicrophonePermission, setRecordedAudio, } from './audio-recorder.js';
|
|
36
|
+
export type { FakeAudioRecordingInfo, FakeMicrophonePermission, FakeRecordedAudio, } from './audio-recorder.js';
|
|
30
37
|
export { failNfcSession, nfcSession, nfcWrites, setNfcState, tapNfcTag, } from './nfc.js';
|
|
31
38
|
export type { FakeNfcTag, NfcSessionFailure, NfcSessionInfo } from './nfc.js';
|
|
32
39
|
export { allowWifiNetworkRead, denyWifiNetworkRead, queueWifiJoinResult, setWifiNetwork, wifiJoins, wifiLeaves, } from './wifi.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7E,YAAY,EAAE,YA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ED
|
@@ -3,17 +3,21 @@ export { setAppState } from './app-state.js';
|
|
|
3
3
|
export { pressBackButton } from './back-button.js';
|
|
4
4
|
export { biometricPrompts, queueBiometricResult, setBiometrics, } from './biometrics.js';
|
|
5
5
|
export { savedFiles, setFilePickerCanceled, setPickedFiles, } from './file-picker.js';
|
|
6
|
+
export { failImagePicker, imagePickerRequests, setPickedImage, setTakenPhoto, } from './image-picker.js';
|
|
6
7
|
export { cancelBarcodeScan, failBarcodeScan, queueBarcodeScan, } from './barcode-scanner.js';
|
|
8
|
+
export { locationPrompts, setLocation, setLocationAnswer, setLocationEnabled, setLocationPermission, } from './geolocation.js';
|
|
7
9
|
export { addBluetoothDevice, setBluetoothState } from './bluetooth.js';
|
|
8
10
|
export { fireEvent, eventMap } from './fire-event.js';
|
|
9
11
|
export { savedPhotos, setPhotoLibraryPermission } from './photo-library.js';
|
|
10
12
|
export { openedURLs, openLink } from './linking.js';
|
|
13
|
+
export { setOnline } from './network.js';
|
|
11
14
|
export { emitMotion, setHeading, shakeDevice } from './motion.js';
|
|
12
15
|
export { runShortcut } from './shortcuts.js';
|
|
13
16
|
export { receiveShare } from './share-target.js';
|
|
14
17
|
export { reviewRequests } from './store-review.js';
|
|
15
18
|
export { setTrackingAnswer, setTrackingStatus, trackingPrompts, } from './tracking.js';
|
|
16
19
|
export { answerCalendarSheet, calendarEvents, failCalendarSheet, } from './calendar.js';
|
|
20
|
+
export { audioRecording, emitAudioLevel, failAudioRecording, interruptAudioRecording, setMicrophonePermission, setRecordedAudio, } from './audio-recorder.js';
|
|
17
21
|
export { failNfcSession, nfcSession, nfcWrites, setNfcState, tapNfcTag, } from './nfc.js';
|
|
18
22
|
export { allowWifiNetworkRead, denyWifiNetworkRead, queueWifiJoinResult, setWifiNetwork, wifiJoins, wifiLeaves, } from './wifi.js';
|
|
19
23
|
export { appleSignInRequests, setAppleCredentialState, setAppleSignInAvailable, setAppleSignInError, setAppleSignInResult, } from './apple-sign-in.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes the phone offline, or brings it back online, so a spec can check what
|
|
3
|
+
* the app shows without a connection and what it does once it's back.
|
|
4
|
+
* `LynxNetwork.online()` becomes `online`.
|
|
5
|
+
*
|
|
6
|
+
* It reaches the app as it does on a phone, as a change to the host's global
|
|
7
|
+
* props: change detection runs on its own, so wait for it with
|
|
8
|
+
* `waitForUpdate()`. Wait between two changes too: an `effect()` runs once
|
|
9
|
+
* for both otherwise, and never sees the phone go offline. Each test starts
|
|
10
|
+
* online.
|
|
11
|
+
*
|
|
12
|
+
* It changes only what `LynxNetwork` reports: requests go on as the spec's
|
|
13
|
+
* fakes answer them.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* await render(Orders);
|
|
18
|
+
* setOnline(false);
|
|
19
|
+
* await waitForUpdate();
|
|
20
|
+
* expect(screen.getByText('An internet connection is required')).toBeTruthy();
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param online - `false` to take the phone offline, `true` to bring it back.
|
|
24
|
+
*/
|
|
25
|
+
export declare const setOnline: (online: boolean) => void;
|
|
26
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,OAAO,KAAG,IACK,CAAC"}
|