@blotch/angular-lynx-testing-library 22.3.1 → 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.
Files changed (69) hide show
  1. package/dist/app-state.d.ts +34 -0
  2. package/dist/app-state.d.ts.map +1 -0
  3. package/dist/app-state.js +33 -0
  4. package/dist/apple-sign-in.d.ts +116 -0
  5. package/dist/apple-sign-in.d.ts.map +1 -0
  6. package/dist/apple-sign-in.js +179 -0
  7. package/dist/audio-recorder.d.ts +95 -0
  8. package/dist/audio-recorder.d.ts.map +1 -0
  9. package/dist/audio-recorder.js +250 -0
  10. package/dist/back-button.d.ts +43 -0
  11. package/dist/back-button.d.ts.map +1 -0
  12. package/dist/back-button.js +77 -0
  13. package/dist/barcode-scanner.d.ts +59 -0
  14. package/dist/barcode-scanner.d.ts.map +1 -0
  15. package/dist/barcode-scanner.js +100 -0
  16. package/dist/biometrics.d.ts +79 -0
  17. package/dist/biometrics.d.ts.map +1 -0
  18. package/dist/biometrics.js +151 -0
  19. package/dist/bluetooth.d.ts +121 -0
  20. package/dist/bluetooth.d.ts.map +1 -0
  21. package/dist/bluetooth.js +369 -0
  22. package/dist/calendar.d.ts +68 -0
  23. package/dist/calendar.d.ts.map +1 -0
  24. package/dist/calendar.js +120 -0
  25. package/dist/file-picker.d.ts +76 -0
  26. package/dist/file-picker.d.ts.map +1 -0
  27. package/dist/file-picker.js +125 -0
  28. package/dist/fire-event.d.ts.map +1 -1
  29. package/dist/fire-event.js +58 -8
  30. package/dist/geolocation.d.ts +94 -0
  31. package/dist/geolocation.d.ts.map +1 -0
  32. package/dist/geolocation.js +255 -0
  33. package/dist/global-props.d.ts +17 -0
  34. package/dist/global-props.d.ts.map +1 -0
  35. package/dist/global-props.js +35 -0
  36. package/dist/image-picker.d.ts +84 -0
  37. package/dist/image-picker.d.ts.map +1 -0
  38. package/dist/image-picker.js +140 -0
  39. package/dist/index.d.ts +35 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +19 -0
  42. package/dist/motion.d.ts +90 -0
  43. package/dist/motion.d.ts.map +1 -0
  44. package/dist/motion.js +169 -0
  45. package/dist/network.d.ts +26 -0
  46. package/dist/network.d.ts.map +1 -0
  47. package/dist/network.js +31 -0
  48. package/dist/nfc.d.ts +85 -0
  49. package/dist/nfc.d.ts.map +1 -0
  50. package/dist/nfc.js +253 -0
  51. package/dist/photo-library.d.ts +58 -0
  52. package/dist/photo-library.d.ts.map +1 -0
  53. package/dist/photo-library.js +91 -0
  54. package/dist/render.d.ts.map +1 -1
  55. package/dist/render.js +19 -1
  56. package/dist/setup.js +86 -7
  57. package/dist/share-target.d.ts +56 -0
  58. package/dist/share-target.d.ts.map +1 -0
  59. package/dist/share-target.js +92 -0
  60. package/dist/store-review.d.ts +30 -0
  61. package/dist/store-review.d.ts.map +1 -0
  62. package/dist/store-review.js +49 -0
  63. package/dist/tracking.d.ts +60 -0
  64. package/dist/tracking.d.ts.map +1 -0
  65. package/dist/tracking.js +94 -0
  66. package/dist/wifi.d.ts +77 -0
  67. package/dist/wifi.d.ts.map +1 -0
  68. package/dist/wifi.js +148 -0
  69. package/package.json +3 -3
@@ -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
@@ -1,10 +1,45 @@
1
1
  export { render, cleanup, waitForUpdate } from './render.js';
2
2
  export type { RenderInputs, RenderOptions, RenderResult } from './render.js';
3
3
  export type { ComponentRef } from '@angular/core';
4
+ export { setAppState } from './app-state.js';
5
+ export type { AppState } from './app-state.js';
6
+ export { pressBackButton } from './back-button.js';
7
+ export { biometricPrompts, queueBiometricResult, setBiometrics, } from './biometrics.js';
8
+ export type { BiometricPrompt, BiometricResult, FakeBiometrics, } from './biometrics.js';
9
+ export { savedFiles, setFilePickerCanceled, setPickedFiles, } from './file-picker.js';
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';
13
+ export { cancelBarcodeScan, failBarcodeScan, queueBarcodeScan, } from './barcode-scanner.js';
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';
17
+ export { addBluetoothDevice, setBluetoothState } from './bluetooth.js';
18
+ export type { FakeBluetoothCharacteristic, FakeBluetoothDevice, FakeBluetoothDeviceRef, FakeBluetoothWrite, } from './bluetooth.js';
4
19
  export { fireEvent, eventMap } from './fire-event.js';
20
+ export { savedPhotos, setPhotoLibraryPermission } from './photo-library.js';
21
+ export type { FakePhotoLibraryPermission, SavedPhoto, } from './photo-library.js';
5
22
  export { openedURLs, openLink } from './linking.js';
23
+ export { setOnline } from './network.js';
24
+ export { emitMotion, setHeading, shakeDevice } from './motion.js';
25
+ export type { EmittedHeading, EmittedMotion, MotionVector } from './motion.js';
6
26
  export type { OpenedURL } from './linking.js';
7
27
  export { runShortcut } from './shortcuts.js';
28
+ export { receiveShare } from './share-target.js';
29
+ export type { FakeShare } from './share-target.js';
30
+ export { reviewRequests } from './store-review.js';
31
+ export { setTrackingAnswer, setTrackingStatus, trackingPrompts, } from './tracking.js';
32
+ export type { FakeTrackingStatus } from './tracking.js';
33
+ export { answerCalendarSheet, calendarEvents, failCalendarSheet, } from './calendar.js';
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';
37
+ export { failNfcSession, nfcSession, nfcWrites, setNfcState, tapNfcTag, } from './nfc.js';
38
+ export type { FakeNfcTag, NfcSessionFailure, NfcSessionInfo } from './nfc.js';
39
+ export { allowWifiNetworkRead, denyWifiNetworkRead, queueWifiJoinResult, setWifiNetwork, wifiJoins, wifiLeaves, } from './wifi.js';
40
+ export type { FakeWifiFailure, FakeWifiNetwork, WifiJoinRequest, } from './wifi.js';
41
+ export { appleSignInRequests, setAppleCredentialState, setAppleSignInAvailable, setAppleSignInError, setAppleSignInResult, } from './apple-sign-in.js';
42
+ export type { AppleSignInRequest, FakeAppleCredentialState, FakeAppleSignInResult, } from './apple-sign-in.js';
8
43
  export { screen, within, getQueriesForElement, queries } from './queries.js';
9
44
  export type { BoundAccessibilityLabelQueries, BoundLynxQueries, LynxQueries, LynxScreen, } from './queries.js';
10
45
  export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
@@ -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,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC7E,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
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,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD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,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,UAAU,GACX,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,eAAe,EACf,eAAe,EACf,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC7E,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,26 @@
1
1
  export { render, cleanup, waitForUpdate } from './render.js';
2
+ export { setAppState } from './app-state.js';
3
+ export { pressBackButton } from './back-button.js';
4
+ export { biometricPrompts, queueBiometricResult, setBiometrics, } from './biometrics.js';
5
+ export { savedFiles, setFilePickerCanceled, setPickedFiles, } from './file-picker.js';
6
+ export { failImagePicker, imagePickerRequests, setPickedImage, setTakenPhoto, } from './image-picker.js';
7
+ export { cancelBarcodeScan, failBarcodeScan, queueBarcodeScan, } from './barcode-scanner.js';
8
+ export { locationPrompts, setLocation, setLocationAnswer, setLocationEnabled, setLocationPermission, } from './geolocation.js';
9
+ export { addBluetoothDevice, setBluetoothState } from './bluetooth.js';
2
10
  export { fireEvent, eventMap } from './fire-event.js';
11
+ export { savedPhotos, setPhotoLibraryPermission } from './photo-library.js';
3
12
  export { openedURLs, openLink } from './linking.js';
13
+ export { setOnline } from './network.js';
14
+ export { emitMotion, setHeading, shakeDevice } from './motion.js';
4
15
  export { runShortcut } from './shortcuts.js';
16
+ export { receiveShare } from './share-target.js';
17
+ export { reviewRequests } from './store-review.js';
18
+ export { setTrackingAnswer, setTrackingStatus, trackingPrompts, } from './tracking.js';
19
+ export { answerCalendarSheet, calendarEvents, failCalendarSheet, } from './calendar.js';
20
+ export { audioRecording, emitAudioLevel, failAudioRecording, interruptAudioRecording, setMicrophonePermission, setRecordedAudio, } from './audio-recorder.js';
21
+ export { failNfcSession, nfcSession, nfcWrites, setNfcState, tapNfcTag, } from './nfc.js';
22
+ export { allowWifiNetworkRead, denyWifiNetworkRead, queueWifiJoinResult, setWifiNetwork, wifiJoins, wifiLeaves, } from './wifi.js';
23
+ export { appleSignInRequests, setAppleCredentialState, setAppleSignInAvailable, setAppleSignInError, setAppleSignInResult, } from './apple-sign-in.js';
5
24
  export { screen, within, getQueriesForElement, queries } from './queries.js';
6
25
  export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
7
26
  export { queryAllByRole, queryByRole, getAllByRole, getByRole, findAllByRole, findByRole, } from './role-queries.js';