@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,58 @@
1
+ /**
2
+ * Whether the fake phone lets the app add to its photo library, as
3
+ * `@blotch/angular-lynx`'s `PhotoLibraryPermission` names it.
4
+ */
5
+ export type FakePhotoLibraryPermission = 'granted' | 'limited' | 'denied' | 'undetermined' | 'unsupported';
6
+ /** A photo or a video `LynxPhotoLibrary.save()` added to the fake library. */
7
+ export type SavedPhoto = {
8
+ /** The ID `save()` resolved with. */
9
+ readonly id: string;
10
+ /** The file's name, given or made up by `save()`. */
11
+ readonly name: string;
12
+ /** Its type, such as `image/jpeg` or `video/mp4`. */
13
+ readonly type: string;
14
+ /** Its bytes. */
15
+ readonly bytes: Uint8Array;
16
+ };
17
+ /**
18
+ * Gives the environment's background thread an `AngularLynxPhotoLibrary`
19
+ * module, as the apps `ng build --platform` makes with
20
+ * `permissions.savePhotos` have. Its library starts empty, and its person
21
+ * hasn't been asked yet: the first save asks, and they allow it, unless
22
+ * {@link setPhotoLibraryPermission} says otherwise. `LynxPhotoLibrary`
23
+ * reaches it through the background thread, as it reaches the shells'
24
+ * module, so specs see the runtime's own behavior.
25
+ *
26
+ * It runs each time the environment injects the background thread's globals:
27
+ * when it's created, and on the reset after each test, so each test starts
28
+ * with an empty library. Only `NativeModules.AngularLynxPhotoLibrary` is
29
+ * added: every other module stays as it was.
30
+ */
31
+ export declare const installPhotoLibraryModule: (threadGlobals: {
32
+ NativeModules?: Record<string, unknown>;
33
+ }) => void;
34
+ /**
35
+ * What `LynxPhotoLibrary.save()` has added to the fake photo library in
36
+ * this test, oldest first.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * await render(Editor);
41
+ * fireEvent.tap(screen.getByText('Save to Photos'));
42
+ * await waitForUpdate();
43
+ * expect(savedPhotos()).toMatchObject([{ name: 'edit.jpg', type: 'image/jpeg' }]);
44
+ * ```
45
+ */
46
+ export declare const savedPhotos: () => readonly SavedPhoto[];
47
+ /**
48
+ * Sets whether the fake phone lets the app add to its photo library: what
49
+ * `LynxPhotoLibrary.addPermission` reads, and what `save()` finds. `denied`
50
+ * has `save()` reject with `permission-denied`, and `unsupported` with
51
+ * `unavailable`, as on a phone without the module. `undetermined`, where
52
+ * each test starts, has the next save ask and the person allow it.
53
+ *
54
+ * Set it before the component that injects `LynxPhotoLibrary` renders: the
55
+ * service reads the permission when it's created, and again after each save.
56
+ */
57
+ export declare const setPhotoLibraryPermission: (permission: FakePhotoLibraryPermission) => void;
58
+ //# sourceMappingURL=photo-library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"photo-library.d.ts","sourceRoot":"","sources":["../src/photo-library.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAClC,SAAS,GACT,SAAS,GACT,QAAQ,GACR,cAAc,GACd,aAAa,CAAC;AAElB,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG;IACvB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B,CAAC;AA0BF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GAAI,eAAe;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAmCH,CAAC;AAmBF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,QAAO,SAAS,UAAU,EAEjD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,0BAA0B,KACrC,IAEF,CAAC"}
@@ -0,0 +1,91 @@
1
+ /** What `LynxPhotoLibrary` calls, named as the shells name their module. */
2
+ const MODULE = 'AngularLynxPhotoLibrary';
3
+ const decode = (base64) => Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
4
+ /**
5
+ * Gives the environment's background thread an `AngularLynxPhotoLibrary`
6
+ * module, as the apps `ng build --platform` makes with
7
+ * `permissions.savePhotos` have. Its library starts empty, and its person
8
+ * hasn't been asked yet: the first save asks, and they allow it, unless
9
+ * {@link setPhotoLibraryPermission} says otherwise. `LynxPhotoLibrary`
10
+ * reaches it through the background thread, as it reaches the shells'
11
+ * module, so specs see the runtime's own behavior.
12
+ *
13
+ * It runs each time the environment injects the background thread's globals:
14
+ * when it's created, and on the reset after each test, so each test starts
15
+ * with an empty library. Only `NativeModules.AngularLynxPhotoLibrary` is
16
+ * added: every other module stays as it was.
17
+ */
18
+ export const installPhotoLibraryModule = (threadGlobals) => {
19
+ const module = {
20
+ permissionState: 'undetermined',
21
+ saved: [],
22
+ permission(done) {
23
+ done({ permission: this.permissionState });
24
+ },
25
+ save(request, done) {
26
+ // The person allows it when asked, as most do.
27
+ if (this.permissionState === 'undetermined') {
28
+ this.permissionState = 'granted';
29
+ }
30
+ const permission = this.permissionState;
31
+ if (permission === 'unsupported') {
32
+ done({ error: 'unavailable', permission });
33
+ return;
34
+ }
35
+ if (permission === 'denied') {
36
+ done({ error: 'permission-denied', permission });
37
+ return;
38
+ }
39
+ const id = `fake-photo-${this.saved.length + 1}`;
40
+ this.saved.push({
41
+ id,
42
+ name: request.name,
43
+ type: request.type,
44
+ bytes: decode(request.base64),
45
+ });
46
+ done({ id, permission });
47
+ },
48
+ };
49
+ threadGlobals.NativeModules = {
50
+ ...threadGlobals.NativeModules,
51
+ [MODULE]: module,
52
+ };
53
+ };
54
+ const fakeModule = (name) => {
55
+ // Read through the environment rather than kept here: under `ng test`, the
56
+ // setup file and the specs can load different copies of this module.
57
+ const env = globalThis.lynxTestingEnv;
58
+ const module = env?.backgroundThread.globalThis.NativeModules?.[MODULE];
59
+ if (!module) {
60
+ throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
61
+ }
62
+ return module;
63
+ };
64
+ /**
65
+ * What `LynxPhotoLibrary.save()` has added to the fake photo library in
66
+ * this test, oldest first.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * await render(Editor);
71
+ * fireEvent.tap(screen.getByText('Save to Photos'));
72
+ * await waitForUpdate();
73
+ * expect(savedPhotos()).toMatchObject([{ name: 'edit.jpg', type: 'image/jpeg' }]);
74
+ * ```
75
+ */
76
+ export const savedPhotos = () => [
77
+ ...fakeModule('savedPhotos').saved,
78
+ ];
79
+ /**
80
+ * Sets whether the fake phone lets the app add to its photo library: what
81
+ * `LynxPhotoLibrary.addPermission` reads, and what `save()` finds. `denied`
82
+ * has `save()` reject with `permission-denied`, and `unsupported` with
83
+ * `unavailable`, as on a phone without the module. `undetermined`, where
84
+ * each test starts, has the next save ask and the person allow it.
85
+ *
86
+ * Set it before the component that injects `LynxPhotoLibrary` renders: the
87
+ * service reads the permission when it's created, and again after each save.
88
+ */
89
+ export const setPhotoLibraryPermission = (permission) => {
90
+ fakeModule('setPhotoLibraryPermission').permissionState = permission;
91
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EAKb,KAAK,IAAI,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEhF;;;;GAIG;AACH,KAAK,UAAU,CAAC,CAAC,IAIf,CAAC,SAAS,wBAAwB,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI;KACrC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,EAAE,CAAC,GAAG,OAAO,IAAI;IACxE,SAAS,CAAC,EAAE,CAAC,QAAQ,GAAG,oBAAoB,CAAC,EAAE,CAAC;IAChD;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAiCF,MAAM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CAAC;IACpB;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3E;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EACzC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAClB,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GACrC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B;;OAEG;IACH,UAAU,EAAE,MAAM,gBAAgB,CAAC;IACnC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC/B,GAAG,gBAAgB,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC;AAIpB,eAAO,MAAM,OAAO,QAAO,IAM1B,CAAC;AAmFF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAU,CAAC,SAAS,OAAO,GAAG,WAAW,EAAE,CAAC,GAAG,OAAO,EACvE,eAAe,IAAI,CAAC,CAAC,CAAC,EACtB,UAAS,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAM,KACzC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAuH5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,IAAI,CAKlD,CAAC"}
package/dist/render.js CHANGED
@@ -17,8 +17,26 @@
17
17
  import { inputBinding, provideZonelessChangeDetection, reflectComponentType, signal, } from '@angular/core';
18
18
  import { createApplication } from '@angular/platform-browser';
19
19
  import { getQueriesForElement, } from '@testing-library/dom';
20
- import { provideRenderer, ɵhideSplashScreenUnlessProvided, } from '@blotch/angular-lynx';
20
+ import { provideRenderer, ɵenableBlob, ɵenableCanvas, ɵenableCanvas2D, ɵenableFetch, ɵenableIntersectionObserver, ɵenableReadableStream, ɵenableTextDecoder, ɵenableTextEncoder, ɵenableXMLHttpRequest, ɵhideSplashScreenUnlessProvided, } from '@blotch/angular-lynx';
21
21
  import { queries } from './queries.js';
22
+ // An app's build gives its main thread fetch, XMLHttpRequest,
23
+ // IntersectionObserver, TextEncoder, TextDecoder, ReadableStream, Blob, the
24
+ // canvas and its 2D context only where a module names them (the build
25
+ // plugin's on-demand.ts). Tests
26
+ // aren't built by the plugin, so they get them all, as the runtime gave every
27
+ // app before: a component that observes its elements, or one with
28
+ // `@defer (on viewport)`, renders as it does in the app. Each keeps the
29
+ // environment's own where it has one (jsdom's XMLHttpRequest, Node's fetch
30
+ // and Blob).
31
+ ɵenableFetch();
32
+ ɵenableXMLHttpRequest();
33
+ ɵenableIntersectionObserver();
34
+ ɵenableTextEncoder();
35
+ ɵenableTextDecoder();
36
+ ɵenableReadableStream();
37
+ ɵenableBlob();
38
+ ɵenableCanvas();
39
+ ɵenableCanvas2D();
22
40
  /**
23
41
  * The global prop the shells hand the link that started the app in, which
24
42
  * `LynxLinking.getInitialURL()` reads (see the runtime's linking.ts).
package/dist/setup.js CHANGED
@@ -22,8 +22,25 @@
22
22
  import '@angular/compiler';
23
23
  import '@testing-library/jest-dom/vitest';
24
24
  import { LynxTestingEnv } from '@lynx-js/testing-environment';
25
+ import { installShellModule } from './back-button.js';
26
+ import { installBiometricsModule } from './biometrics.js';
27
+ import { installFilePickerModule } from './file-picker.js';
28
+ import { installImagePickerModule } from './image-picker.js';
29
+ import { installAudioRecorderModule } from './audio-recorder.js';
30
+ import { installBarcodeScannerModule } from './barcode-scanner.js';
31
+ import { installBluetoothModule } from './bluetooth.js';
32
+ import { installCalendarModule } from './calendar.js';
33
+ import { installNfcModule } from './nfc.js';
34
+ import { installPhotoLibraryModule } from './photo-library.js';
25
35
  import { installLinkingModule } from './linking.js';
26
36
  import { installShortcutsModule } from './shortcuts.js';
37
+ import { installShareTargetModule } from './share-target.js';
38
+ import { installStoreReviewModule } from './store-review.js';
39
+ import { answerAppleSignInButtonOnMainThread, installAppleSignInModule, } from './apple-sign-in.js';
40
+ import { installTrackingModule } from './tracking.js';
41
+ import { installWifiModule } from './wifi.js';
42
+ import { installGeolocationModule } from './geolocation.js';
43
+ import { installMotionModule } from './motion.js';
27
44
  // ─── CSS fetch intercept ─────────────────────────────────────────────────────
28
45
  /**
29
46
  * Angular JIT calls fetch('./component.css') to load external styleUrls.
@@ -90,6 +107,9 @@ const frameOnInstalledTimers = (threadGlobals) => {
90
107
  globalThis.onInjectMainThreadGlobals = (threadGlobals) => {
91
108
  returnOnWarnings(threadGlobals);
92
109
  frameOnInstalledTimers(threadGlobals);
110
+ // <apple-sign-in-button> is iOS's while the fake Sign in with Apple module
111
+ // is there (see apple-sign-in.ts).
112
+ answerAppleSignInButtonOnMainThread(threadGlobals);
93
113
  };
94
114
  globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
95
115
  returnOnWarnings(threadGlobals);
@@ -98,6 +118,58 @@ globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
98
118
  installLinkingModule(threadGlobals);
99
119
  // LynxShortcuts takes the shortcuts runShortcut() runs (see shortcuts.ts).
100
120
  installShortcutsModule(threadGlobals);
121
+ // LynxShareTarget takes the shares receiveShare() sends (see
122
+ // share-target.ts).
123
+ installShareTargetModule(threadGlobals);
124
+ // LynxBarcodeScanner reads the codes queueBarcodeScan() queues (see
125
+ // barcode-scanner.ts).
126
+ installBarcodeScannerModule(threadGlobals);
127
+ // LynxStoreReview's requests, which reviewRequests() counts (see
128
+ // store-review.ts).
129
+ installStoreReviewModule(threadGlobals);
130
+ // LynxTracking's status and prompt, which setTrackingStatus() and
131
+ // setTrackingAnswer() steer and trackingPrompts() counts (see tracking.ts).
132
+ installTrackingModule(threadGlobals);
133
+ // LynxCalendar's events, which calendarEvents() lists and
134
+ // answerCalendarSheet() closes the editor for (see calendar.ts).
135
+ installCalendarModule(threadGlobals);
136
+ // LynxNfc's sessions, which tapNfcTag() brings tags to and nfcWrites()
137
+ // lists the writes of (see nfc.ts).
138
+ installNfcModule(threadGlobals);
139
+ // LynxAudioRecorder's recordings, which setMicrophonePermission() and
140
+ // setRecordedAudio() steer and emitAudioLevel() meters (see
141
+ // audio-recorder.ts).
142
+ installAudioRecorderModule(threadGlobals);
143
+ // LynxWifi's network and joins, which setWifiNetwork() and
144
+ // queueWifiJoinResult() steer and wifiJoins() lists (see wifi.ts).
145
+ installWifiModule(threadGlobals);
146
+ // LynxAppleSignIn's sign-ins, which setAppleSignInResult() and the other
147
+ // setters in apple-sign-in.ts steer.
148
+ installAppleSignInModule(threadGlobals);
149
+ // LynxPhotoLibrary saves into the library savedPhotos() lists, with the
150
+ // permission setPhotoLibraryPermission() sets (see photo-library.ts).
151
+ installPhotoLibraryModule(threadGlobals);
152
+ // LynxMotion's sensors, which emitMotion(), setHeading() and
153
+ // shakeDevice() sample (see motion.ts).
154
+ installMotionModule(threadGlobals);
155
+ // LynxBackButton enables the back handler pressBackButton() checks (see
156
+ // back-button.ts).
157
+ installShellModule(threadGlobals);
158
+ // LynxBiometrics' prompts and LynxSecureStorage's guarded values, which
159
+ // setBiometrics() and queueBiometricResult() steer (see biometrics.ts).
160
+ installBiometricsModule(threadGlobals);
161
+ // LynxBluetooth finds the devices addBluetoothDevice() adds (see
162
+ // bluetooth.ts).
163
+ installBluetoothModule(threadGlobals);
164
+ // LynxGeolocation finds the phone where setLocation() puts it, with the
165
+ // permission setLocationPermission() sets (see geolocation.ts).
166
+ installGeolocationModule(threadGlobals);
167
+ // LynxFilePicker's picks and saves, which setPickedFiles(),
168
+ // setFilePickerCanceled() and savedFiles() steer (see file-picker.ts).
169
+ installFilePickerModule(threadGlobals);
170
+ // LynxImagePicker's library and camera, which setPickedImage(),
171
+ // setTakenPhoto() and failImagePicker() steer (see image-picker.ts).
172
+ installImagePickerModule(threadGlobals);
101
173
  };
102
174
  // ─── Install LynxTestingEnv ──────────────────────────────────────────────────
103
175
  /**
@@ -153,12 +225,10 @@ lynxTestingEnv.switchToMainThread();
153
225
  // __AddEvent in the testing environment calls runWorklet(handler, [event]) when
154
226
  // an event handler is registered as type:'worklet'. AngularLynx registers all
155
227
  // event handlers this way (see LynxElement.addEventListener). runWorklet simply
156
- // invokes the callback — same as the polyfill in runtime.ts for the real device.
157
- globalThis.runWorklet = (value, params) => {
158
- if (typeof value === 'function') {
159
- value(...params);
160
- }
161
- };
228
+ // invokes the callback and returns its result, as the polyfill in
229
+ // global-callbacks.ts does on a device, where Lynx reads the stop bits a
230
+ // listener's stopPropagation() sets from it (see fire-event.ts's deliver()).
231
+ globalThis.runWorklet = (value, params) => typeof value === 'function' ? value(...params) : undefined;
162
232
  // ─── Missing PAPI polyfills ──────────────────────────────────────────────────
163
233
  // The testing-environment's ElementPAPI uses real JSDOM HTMLElements as the
164
234
  // native element representation. So DOM traversal methods work natively on them.
@@ -233,13 +303,22 @@ const isTextField = (element) => /^(input|textarea)$/i.test(element?.tagName ??
233
303
  * text in the JSDOM field's `value`, where a test reads it (`input.value`,
234
304
  * `toHaveValue`), and `getValue` reads it back: the runtime shows a bound
235
305
  * value with setValue (see LynxElement's setProperty), so a field shows on
236
- * screen what it reads here. Other methods do nothing. Each answers at once
306
+ * screen what it reads here. `focus` and `blur` move JSDOM's focus. Other
307
+ * methods do nothing. Each answers at once
237
308
  * that it ran, as a device answers for an element whose UI it has made.
238
309
  */
239
310
  globalThis.__InvokeUIMethod = (element, methodName, params, callback) => {
240
311
  if (isTextField(element) && methodName === 'setValue') {
241
312
  element.value = String(params?.value ?? '');
242
313
  }
314
+ // A field's focus and blur move JSDOM's focus, so a test can read which
315
+ // field has it (`document.activeElement`, `toHaveFocus()`), as after a
316
+ // form's focusBoundControl(). They don't fire bindfocus or bindblur, which
317
+ // fireEvent.focus and fireEvent.blur do.
318
+ if (isTextField(element) && methodName === 'focus')
319
+ element.focus();
320
+ if (isTextField(element) && methodName === 'blur')
321
+ element.blur();
243
322
  if (isTextField(element) && methodName === 'getValue') {
244
323
  callback?.({
245
324
  code: 0,
@@ -0,0 +1,56 @@
1
+ /** What {@link receiveShare} shares to the app. */
2
+ export type FakeShare = {
3
+ /** Text, such as a selection or a note. */
4
+ readonly text?: string;
5
+ /** A link, such as a page from the browser. */
6
+ readonly url?: string;
7
+ /** The share's subject, such as the page's title. */
8
+ readonly title?: string;
9
+ /**
10
+ * Files, each a Blob with its name. The type is the Blob's, or
11
+ * `application/octet-stream` when it has none.
12
+ */
13
+ readonly files?: readonly {
14
+ readonly blob: Blob;
15
+ readonly name: string;
16
+ }[];
17
+ };
18
+ /**
19
+ * Gives the environment's background thread an `AngularLynxShareTarget`
20
+ * module, as the apps `ng build --platform` makes with `shareTarget` have:
21
+ * it keeps the shares {@link receiveShare} sends until `LynxShareTarget`
22
+ * takes them. `LynxShareTarget` reaches it through the background thread, as
23
+ * it reaches the shells' module, so specs see the runtime's own behavior.
24
+ *
25
+ * It runs each time the environment injects the background thread's globals:
26
+ * when it's created, and on the reset after each test, so no share is left
27
+ * waiting for the next test. Only `NativeModules.AngularLynxShareTarget` is
28
+ * added: every other module stays as it was.
29
+ */
30
+ export declare const installShareTargetModule: (threadGlobals: {
31
+ NativeModules?: Record<string, unknown>;
32
+ }) => void;
33
+ /**
34
+ * Shares to the app, as the person does by picking it in another app's
35
+ * share sheet, so a spec can check what the app does with what it receives
36
+ * through `LynxShareTarget.onShare()`.
37
+ *
38
+ * A spec doesn't read angular.json's `shareTarget`, so any text, link or
39
+ * file arrives, whatever `mimeTypes` lists. The share reaches the app as it
40
+ * does on a phone, through the background thread: await this, then wait for
41
+ * it with `waitForUpdate()`. Sent before the app has registered a handler,
42
+ * it waits for the first one, as the share that starts an app does.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * await render(Inbox);
47
+ * await receiveShare({
48
+ * text: 'Read later',
49
+ * files: [{ blob: new Blob(['…'], { type: 'image/jpeg' }), name: 'photo.jpg' }],
50
+ * });
51
+ * await waitForUpdate();
52
+ * expect(screen.getByText('photo.jpg')).toBeInTheDocument();
53
+ * ```
54
+ */
55
+ export declare const receiveShare: (share: FakeShare) => Promise<void>;
56
+ //# sourceMappingURL=share-target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-target.d.ts","sourceRoot":"","sources":["../src/share-target.ts"],"names":[],"mappings":"AAmCA,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAUH,CAAC;AAcF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,YAAY,GAAU,OAAO,SAAS,KAAG,OAAO,CAAC,IAAI,CAuCjE,CAAC"}
@@ -0,0 +1,92 @@
1
+ /** What `LynxShareTarget` calls and hears, named as the shells name them. */
2
+ const MODULE = 'AngularLynxShareTarget';
3
+ const EVENT = 'angularLynxShare';
4
+ /**
5
+ * Gives the environment's background thread an `AngularLynxShareTarget`
6
+ * module, as the apps `ng build --platform` makes with `shareTarget` have:
7
+ * it keeps the shares {@link receiveShare} sends until `LynxShareTarget`
8
+ * takes them. `LynxShareTarget` reaches it through the background thread, as
9
+ * it reaches the shells' module, so specs see the runtime's own behavior.
10
+ *
11
+ * It runs each time the environment injects the background thread's globals:
12
+ * when it's created, and on the reset after each test, so no share is left
13
+ * waiting for the next test. Only `NativeModules.AngularLynxShareTarget` is
14
+ * added: every other module stays as it was.
15
+ */
16
+ export const installShareTargetModule = (threadGlobals) => {
17
+ const waiting = [];
18
+ const module = {
19
+ waiting,
20
+ take: (done) => done({ shares: waiting.splice(0) }),
21
+ };
22
+ threadGlobals.NativeModules = {
23
+ ...threadGlobals.NativeModules,
24
+ [MODULE]: module,
25
+ };
26
+ };
27
+ /**
28
+ * Bytes as base64, as the shells send a file's.
29
+ */
30
+ const toBase64 = (bytes) => {
31
+ let binary = '';
32
+ // In pieces: String.fromCharCode takes only so many arguments.
33
+ for (let i = 0; i < bytes.length; i += 0x8000) {
34
+ binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
35
+ }
36
+ return btoa(binary);
37
+ };
38
+ /**
39
+ * Shares to the app, as the person does by picking it in another app's
40
+ * share sheet, so a spec can check what the app does with what it receives
41
+ * through `LynxShareTarget.onShare()`.
42
+ *
43
+ * A spec doesn't read angular.json's `shareTarget`, so any text, link or
44
+ * file arrives, whatever `mimeTypes` lists. The share reaches the app as it
45
+ * does on a phone, through the background thread: await this, then wait for
46
+ * it with `waitForUpdate()`. Sent before the app has registered a handler,
47
+ * it waits for the first one, as the share that starts an app does.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * await render(Inbox);
52
+ * await receiveShare({
53
+ * text: 'Read later',
54
+ * files: [{ blob: new Blob(['…'], { type: 'image/jpeg' }), name: 'photo.jpg' }],
55
+ * });
56
+ * await waitForUpdate();
57
+ * expect(screen.getByText('photo.jpg')).toBeInTheDocument();
58
+ * ```
59
+ */
60
+ export const receiveShare = async (share) => {
61
+ // Read through the environment rather than kept here: under `ng test`, the
62
+ // setup file and the specs can load different copies of this module.
63
+ const env = globalThis.lynxTestingEnv;
64
+ const background = env?.backgroundThread.globalThis;
65
+ const module = background?.NativeModules?.[MODULE];
66
+ if (!env || !module) {
67
+ throw new Error("receiveShare() needs the testing library's environment, which its setup file installs.");
68
+ }
69
+ const files = await Promise.all((share.files ?? []).map(async ({ blob, name }) => ({
70
+ base64: toBase64(new Uint8Array(await blob.arrayBuffer())),
71
+ name,
72
+ type: blob.type || 'application/octet-stream',
73
+ })));
74
+ module.waiting.push({
75
+ files,
76
+ ...(share.title !== undefined && { title: share.title }),
77
+ ...(share.text !== undefined && { text: share.text }),
78
+ ...(share.url !== undefined && { url: share.url }),
79
+ });
80
+ // What the shells send when a share arrives: LynxShareTarget answers by
81
+ // taking the ones waiting. A global event arrives on the background
82
+ // thread, and the listener there calls the app's on the main thread
83
+ // through that thread's `lynx`, so the event is sent from it. Specs run on
84
+ // the main thread, which comes back afterwards.
85
+ env.switchToBackgroundThread();
86
+ try {
87
+ background?.lynx?.getJSModule?.('GlobalEventEmitter')?.emit(EVENT);
88
+ }
89
+ finally {
90
+ env.switchToMainThread();
91
+ }
92
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Gives the environment's background thread an `AngularLynxStoreReview`
3
+ * module, as the apps `ng build --platform` makes with angular.json's
4
+ * `storeReview` have, which counts each request rather than asking a store.
5
+ * `LynxStoreReview` reaches it through the background thread, as it reaches
6
+ * the shells' module, so `request()` resolves as it does on a phone once
7
+ * the store has the request.
8
+ *
9
+ * It runs each time the environment injects the background thread's
10
+ * globals: when it's created, and on the reset after each test, so each test
11
+ * starts with no requests counted.
12
+ */
13
+ export declare const installStoreReviewModule: (threadGlobals: {
14
+ NativeModules?: Record<string, unknown>;
15
+ }) => void;
16
+ /**
17
+ * How many times the app has asked for a rating with
18
+ * `LynxStoreReview.request()` in this test, so a spec can check it asks at
19
+ * the right moment, and only then. Each test starts at 0. Nothing shows:
20
+ * whether a store would show its prompt can't be known, on a phone either.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * fireEvent.tap(screen.getByText('Place order'));
25
+ * await waitForUpdate();
26
+ * expect(reviewRequests()).toBe(1);
27
+ * ```
28
+ */
29
+ export declare const reviewRequests: () => number;
30
+ //# sourceMappingURL=store-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-review.d.ts","sourceRoot":"","sources":["../src/store-review.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAYH,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,QAAO,MAMjC,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * What `LynxStoreReview` calls, named as the shells name their module.
3
+ */
4
+ const MODULE = 'AngularLynxStoreReview';
5
+ /**
6
+ * Gives the environment's background thread an `AngularLynxStoreReview`
7
+ * module, as the apps `ng build --platform` makes with angular.json's
8
+ * `storeReview` have, which counts each request rather than asking a store.
9
+ * `LynxStoreReview` reaches it through the background thread, as it reaches
10
+ * the shells' module, so `request()` resolves as it does on a phone once
11
+ * the store has the request.
12
+ *
13
+ * It runs each time the environment injects the background thread's
14
+ * globals: when it's created, and on the reset after each test, so each test
15
+ * starts with no requests counted.
16
+ */
17
+ export const installStoreReviewModule = (threadGlobals) => {
18
+ const module = {
19
+ requests: 0,
20
+ request(done) {
21
+ this.requests++;
22
+ done({});
23
+ },
24
+ };
25
+ threadGlobals.NativeModules = {
26
+ ...threadGlobals.NativeModules,
27
+ [MODULE]: module,
28
+ };
29
+ };
30
+ /**
31
+ * How many times the app has asked for a rating with
32
+ * `LynxStoreReview.request()` in this test, so a spec can check it asks at
33
+ * the right moment, and only then. Each test starts at 0. Nothing shows:
34
+ * whether a store would show its prompt can't be known, on a phone either.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * fireEvent.tap(screen.getByText('Place order'));
39
+ * await waitForUpdate();
40
+ * expect(reviewRequests()).toBe(1);
41
+ * ```
42
+ */
43
+ export const reviewRequests = () => {
44
+ // Read through the environment rather than kept here: under `ng test`, the
45
+ // setup file and the specs can load different copies of this module.
46
+ const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
47
+ .NativeModules?.[MODULE];
48
+ return module?.requests ?? 0;
49
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Whether the app may track the person, as `LynxTracking`'s `status()`
3
+ * reports it.
4
+ */
5
+ export type FakeTrackingStatus = 'authorized' | 'denied' | 'restricted' | 'notDetermined' | 'unsupported';
6
+ /**
7
+ * Gives the environment's background thread an `AngularLynxTracking` module,
8
+ * as the apps `ng build --platform` makes with `permissions.tracking` have.
9
+ * It starts where a fresh install on an iPhone does, `notDetermined`, and
10
+ * the person allows tracking when the app asks. `LynxTracking` reaches it
11
+ * through the background thread, as it reaches the shells' module.
12
+ *
13
+ * It runs each time the environment injects the background thread's
14
+ * globals: when it's created, and on the reset after each test, so each test
15
+ * starts from a fresh install.
16
+ */
17
+ export declare const installTrackingModule: (threadGlobals: {
18
+ NativeModules?: Record<string, unknown>;
19
+ }) => void;
20
+ /**
21
+ * Sets whether the app may track the person, as if they'd answered the
22
+ * prompt or changed it in Settings: what `LynxTracking.status()` reads, and
23
+ * what `requestPermission()` resolves with, without a prompt unless it's
24
+ * `notDetermined`. Each test starts at `notDetermined`.
25
+ *
26
+ * `LynxTracking` reads the status when it's created, and again when the app
27
+ * comes back to the foreground, so set it before `render()`, or follow it
28
+ * with `setAppState('background')` and `setAppState('active')`, as a person
29
+ * coming back from Settings would. Wait with `waitForUpdate()` after each:
30
+ * the service watches the app's state with an `effect()`, which runs once
31
+ * for two changes made together and never sees the app leave.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * setTrackingStatus('denied');
36
+ * await render(AdBanner);
37
+ * expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();
38
+ * ```
39
+ */
40
+ export declare const setTrackingStatus: (status: FakeTrackingStatus) => void;
41
+ /**
42
+ * Sets what the person answers when `requestPermission()` shows the prompt:
43
+ * `authorized` (the default) or `denied`. The prompt shows only while the
44
+ * status is `notDetermined`.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * setTrackingAnswer('denied');
49
+ * fireEvent.tap(screen.getByText('Continue'));
50
+ * await waitForUpdate();
51
+ * expect(trackingPrompts()).toBe(1);
52
+ * ```
53
+ */
54
+ export declare const setTrackingAnswer: (answer: "authorized" | "denied") => void;
55
+ /**
56
+ * How many times `requestPermission()` has shown the prompt in this test, so
57
+ * a spec can check the app asks at the right moment, and only once.
58
+ */
59
+ export declare const trackingPrompts: () => number;
60
+ //# sourceMappingURL=tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../src/tracking.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ,QAAQ,GACR,YAAY,GACZ,eAAe,GACf,aAAa,CAAC;AAiBlB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,eAAe;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAyBH,CAAC;AAUF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,kBAAkB,KAAG,IAG9D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,YAAY,GAAG,QAAQ,KAAG,IAGnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,MAAmC,CAAC"}