@blotch/angular-lynx-testing-library 22.3.1 → 22.3.2

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 (52) 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 +57 -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/back-button.d.ts +43 -0
  8. package/dist/back-button.d.ts.map +1 -0
  9. package/dist/back-button.js +77 -0
  10. package/dist/barcode-scanner.d.ts +59 -0
  11. package/dist/barcode-scanner.d.ts.map +1 -0
  12. package/dist/barcode-scanner.js +100 -0
  13. package/dist/biometrics.d.ts +79 -0
  14. package/dist/biometrics.d.ts.map +1 -0
  15. package/dist/biometrics.js +151 -0
  16. package/dist/bluetooth.d.ts +121 -0
  17. package/dist/bluetooth.d.ts.map +1 -0
  18. package/dist/bluetooth.js +369 -0
  19. package/dist/calendar.d.ts +68 -0
  20. package/dist/calendar.d.ts.map +1 -0
  21. package/dist/calendar.js +120 -0
  22. package/dist/file-picker.d.ts +76 -0
  23. package/dist/file-picker.d.ts.map +1 -0
  24. package/dist/file-picker.js +125 -0
  25. package/dist/index.d.ts +28 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +15 -0
  28. package/dist/motion.d.ts +90 -0
  29. package/dist/motion.d.ts.map +1 -0
  30. package/dist/motion.js +169 -0
  31. package/dist/nfc.d.ts +85 -0
  32. package/dist/nfc.d.ts.map +1 -0
  33. package/dist/nfc.js +253 -0
  34. package/dist/photo-library.d.ts +58 -0
  35. package/dist/photo-library.d.ts.map +1 -0
  36. package/dist/photo-library.js +91 -0
  37. package/dist/render.d.ts.map +1 -1
  38. package/dist/render.js +19 -1
  39. package/dist/setup.js +59 -0
  40. package/dist/share-target.d.ts +56 -0
  41. package/dist/share-target.d.ts.map +1 -0
  42. package/dist/share-target.js +92 -0
  43. package/dist/store-review.d.ts +30 -0
  44. package/dist/store-review.d.ts.map +1 -0
  45. package/dist/store-review.js +49 -0
  46. package/dist/tracking.d.ts +60 -0
  47. package/dist/tracking.d.ts.map +1 -0
  48. package/dist/tracking.js +94 -0
  49. package/dist/wifi.d.ts +77 -0
  50. package/dist/wifi.d.ts.map +1 -0
  51. package/dist/wifi.js +148 -0
  52. package/package.json +3 -3
package/dist/nfc.js ADDED
@@ -0,0 +1,253 @@
1
+ import { ɵencodeNfcRecord, ɵparseNfcRecord, } from '@blotch/angular-lynx';
2
+ /** What `LynxNfc` calls, named as the shells name their module. */
3
+ const MODULE = 'AngularLynxNfc';
4
+ const STOPPED = { error: 'stopped' };
5
+ /**
6
+ * The bytes of a record's base64 field, which records cross the module as.
7
+ */
8
+ const fromBase64 = (text) => Uint8Array.from(atob(text), (character) => character.charCodeAt(0));
9
+ /**
10
+ * The bytes an NDEF message of `records` takes on a tag: each record's
11
+ * header, lengths, type and payload (NFC Forum NDEF 1.0, 3.2), with a
12
+ * short record's one-byte length for a payload under 256 bytes.
13
+ */
14
+ const messageLength = (records) => records.reduce((sum, record) => {
15
+ // The runtime writes no record IDs.
16
+ const payload = fromBase64(record.payload).length;
17
+ return (sum +
18
+ 1 +
19
+ 1 +
20
+ (payload < 256 ? 1 : 4) +
21
+ fromBase64(record.type).length +
22
+ payload);
23
+ }, 0);
24
+ const tagAnswer = (records, tag) => ({
25
+ tag: {
26
+ records,
27
+ writable: tag.writable ?? true,
28
+ capacity: tag.capacity ?? 888,
29
+ ...(tag.id !== undefined && { id: tag.id }),
30
+ },
31
+ });
32
+ /**
33
+ * The module's answer to a tap, as the shells work it out.
34
+ */
35
+ const answerTap = (module, tag) => {
36
+ if (tag.ndef === false) {
37
+ return {
38
+ error: 'tagNotNdef',
39
+ message: "This tag doesn't hold NDEF records.",
40
+ };
41
+ }
42
+ const write = module.session?.write;
43
+ if (!write) {
44
+ return tagAnswer((tag.records ?? []).map(ɵencodeNfcRecord), tag);
45
+ }
46
+ if (tag.writable === false) {
47
+ return {
48
+ error: 'readOnly',
49
+ message: "This tag is locked, so it can't be written to.",
50
+ };
51
+ }
52
+ const length = messageLength(write);
53
+ const capacity = tag.capacity ?? 888;
54
+ if (length > capacity) {
55
+ return {
56
+ error: 'tooLarge',
57
+ message: `The records take ${length} bytes, and this tag holds ${capacity}.`,
58
+ };
59
+ }
60
+ module.writes.push(write.map((record) => ɵparseNfcRecord(record)));
61
+ return tagAnswer(write, tag);
62
+ };
63
+ const deliver = (module, answer) => {
64
+ // A scan skips a tag it couldn't read, as the shells do.
65
+ if (module.session?.multiple && answer['error'] !== undefined)
66
+ return;
67
+ const waiting = module.waiting;
68
+ if (waiting) {
69
+ module.waiting = undefined;
70
+ waiting(answer);
71
+ }
72
+ else {
73
+ module.answers.push(answer);
74
+ }
75
+ };
76
+ const end = (module, answer) => {
77
+ module.session = undefined;
78
+ module.ended = answer;
79
+ const waiting = module.waiting;
80
+ module.waiting = undefined;
81
+ waiting?.(answer);
82
+ };
83
+ const handle = (module, pending) => {
84
+ if ('tap' in pending) {
85
+ if (module.claimed) {
86
+ module.pending.push(pending);
87
+ return;
88
+ }
89
+ if (!module.session?.multiple)
90
+ module.claimed = true;
91
+ deliver(module, answerTap(module, pending.tap));
92
+ }
93
+ else {
94
+ end(module, pending.fail);
95
+ }
96
+ };
97
+ /**
98
+ * Gives the environment's background thread an `AngularLynxNfc` module, as
99
+ * the apps `ng build --platform` makes with angular.json's `permissions.nfc`
100
+ * have. Its phone reads tags (`ready`) until {@link setNfcState} says
101
+ * otherwise, and a tag comes near it only when {@link tapNfcTag} brings one.
102
+ * `LynxNfc` reaches it through the background thread, as it reaches the
103
+ * shells' module, so specs see the runtime's own behavior.
104
+ *
105
+ * It runs each time the environment injects the background thread's
106
+ * globals: when it's created, and on the reset after each test, so each test
107
+ * starts with a phone that reads tags, no session and no writes.
108
+ */
109
+ export const installNfcModule = (threadGlobals) => {
110
+ const module = {
111
+ phone: 'ready',
112
+ session: undefined,
113
+ claimed: false,
114
+ waiting: undefined,
115
+ answers: [],
116
+ pending: [],
117
+ ended: STOPPED,
118
+ writes: [],
119
+ state(done) {
120
+ done({ state: this.phone });
121
+ },
122
+ start(options, done) {
123
+ if (this.phone !== 'ready') {
124
+ done({ error: this.phone });
125
+ return;
126
+ }
127
+ // LynxNfc opens one session at a time itself.
128
+ this.session = options;
129
+ this.claimed = false;
130
+ this.answers.length = 0;
131
+ done({});
132
+ // What the spec did before the app asked.
133
+ // One at a time: a failure ends the session, a read or a write takes
134
+ // only one tag, and what came after waits for the next session.
135
+ while (this.session && !this.claimed && this.pending.length > 0) {
136
+ handle(this, this.pending.shift());
137
+ }
138
+ },
139
+ next(done) {
140
+ if (this.answers.length > 0) {
141
+ done(this.answers.shift());
142
+ }
143
+ else if (!this.session) {
144
+ done(this.ended);
145
+ }
146
+ else {
147
+ this.waiting = done;
148
+ }
149
+ },
150
+ stop(_options, done) {
151
+ if (this.session)
152
+ end(this, STOPPED);
153
+ done({});
154
+ },
155
+ };
156
+ threadGlobals.NativeModules = {
157
+ ...threadGlobals.NativeModules,
158
+ [MODULE]: module,
159
+ };
160
+ };
161
+ /**
162
+ * The fake module, read through the environment rather than kept here:
163
+ * under `ng test`, the setup file and the specs can load different copies of
164
+ * this file.
165
+ */
166
+ const fakeModule = (name) => {
167
+ const env = globalThis.lynxTestingEnv;
168
+ const module = env?.backgroundThread.globalThis.NativeModules?.[MODULE];
169
+ if (!env || !module) {
170
+ throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
171
+ }
172
+ return { env, module };
173
+ };
174
+ /**
175
+ * Runs `action` on the background thread, where the shells answer.
176
+ */
177
+ const onBackground = (env, action) => {
178
+ env.switchToBackgroundThread();
179
+ try {
180
+ action();
181
+ }
182
+ finally {
183
+ env.switchToMainThread();
184
+ }
185
+ };
186
+ /**
187
+ * Brings a tag near the phone, as the person would: the open
188
+ * `LynxNfc.read()` resolves with its records, the open `write()` writes to
189
+ * it, and an open `scan()` calls back with it. When no session is open yet,
190
+ * the next one that opens takes it. The answer reaches the app through the
191
+ * background thread, as on a phone: wait for it with `waitForUpdate()`.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * fireEvent.tap(screen.getByText('Scan your card'));
196
+ * tapNfcTag({ records: [{ type: 'url', value: 'https://example.com/m/42' }] });
197
+ * await waitForUpdate();
198
+ * expect(screen.getByText('Member 42')).toBeInTheDocument();
199
+ * ```
200
+ */
201
+ export const tapNfcTag = (tag = {}) => {
202
+ const { env, module } = fakeModule('tapNfcTag');
203
+ if (!module.session) {
204
+ module.pending.push({ tap: tag });
205
+ return;
206
+ }
207
+ onBackground(env, () => handle(module, { tap: tag }));
208
+ };
209
+ /**
210
+ * Ends the open session, or the next one as soon as it opens, as iOS ends
211
+ * one: `canceled` when the person closes the scan sheet, `timeout` after a
212
+ * minute without a tag, `failed` otherwise. The open `read()` or `write()`
213
+ * rejects with an `NfcError` of `code`, and an open `scan()` ends with it.
214
+ */
215
+ export const failNfcSession = (code, message) => {
216
+ const { env, module } = fakeModule('failNfcSession');
217
+ const fail = { error: code, ...(message !== undefined && { message }) };
218
+ if (!module.session) {
219
+ module.pending.push({ fail });
220
+ return;
221
+ }
222
+ onBackground(env, () => handle(module, { fail }));
223
+ };
224
+ /**
225
+ * Whether the phone reads tags: `ready` (the default each test starts
226
+ * with), `disabled` (NFC turned off in Android's settings) or
227
+ * `unsupported` (no reader). `LynxNfc.state()` reads it when the app starts
228
+ * and each time it comes back to the foreground; send it there with
229
+ * `setAppState()`.
230
+ */
231
+ export const setNfcState = (state) => {
232
+ fakeModule('setNfcState').module.phone = state;
233
+ };
234
+ /** The session the app has open, or undefined while none is. */
235
+ export const nfcSession = () => {
236
+ const session = fakeModule('nfcSession').module.session;
237
+ if (!session)
238
+ return undefined;
239
+ return {
240
+ ...(session.alertMessage !== undefined && {
241
+ alertMessage: session.alertMessage,
242
+ }),
243
+ multiple: session.multiple === true,
244
+ writing: session.write !== undefined,
245
+ };
246
+ };
247
+ /**
248
+ * The records each `LynxNfc.write()` wrote to a tag in this test, oldest
249
+ * first, as a read would give them back.
250
+ */
251
+ export const nfcWrites = () => [
252
+ ...fakeModule('nfcWrites').module.writes,
253
+ ];
@@ -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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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,22 @@
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 { installBarcodeScannerModule } from './barcode-scanner.js';
29
+ import { installBluetoothModule } from './bluetooth.js';
30
+ import { installCalendarModule } from './calendar.js';
31
+ import { installNfcModule } from './nfc.js';
32
+ import { installPhotoLibraryModule } from './photo-library.js';
25
33
  import { installLinkingModule } from './linking.js';
26
34
  import { installShortcutsModule } from './shortcuts.js';
35
+ import { installShareTargetModule } from './share-target.js';
36
+ import { installStoreReviewModule } from './store-review.js';
37
+ import { answerAppleSignInButtonOnMainThread, installAppleSignInModule, } from './apple-sign-in.js';
38
+ import { installTrackingModule } from './tracking.js';
39
+ import { installWifiModule } from './wifi.js';
40
+ import { installMotionModule } from './motion.js';
27
41
  // ─── CSS fetch intercept ─────────────────────────────────────────────────────
28
42
  /**
29
43
  * Angular JIT calls fetch('./component.css') to load external styleUrls.
@@ -90,6 +104,9 @@ const frameOnInstalledTimers = (threadGlobals) => {
90
104
  globalThis.onInjectMainThreadGlobals = (threadGlobals) => {
91
105
  returnOnWarnings(threadGlobals);
92
106
  frameOnInstalledTimers(threadGlobals);
107
+ // <apple-sign-in-button> is iOS's while the fake Sign in with Apple module
108
+ // is there (see apple-sign-in.ts).
109
+ answerAppleSignInButtonOnMainThread(threadGlobals);
93
110
  };
94
111
  globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
95
112
  returnOnWarnings(threadGlobals);
@@ -98,6 +115,48 @@ globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
98
115
  installLinkingModule(threadGlobals);
99
116
  // LynxShortcuts takes the shortcuts runShortcut() runs (see shortcuts.ts).
100
117
  installShortcutsModule(threadGlobals);
118
+ // LynxShareTarget takes the shares receiveShare() sends (see
119
+ // share-target.ts).
120
+ installShareTargetModule(threadGlobals);
121
+ // LynxBarcodeScanner reads the codes queueBarcodeScan() queues (see
122
+ // barcode-scanner.ts).
123
+ installBarcodeScannerModule(threadGlobals);
124
+ // LynxStoreReview's requests, which reviewRequests() counts (see
125
+ // store-review.ts).
126
+ installStoreReviewModule(threadGlobals);
127
+ // LynxTracking's status and prompt, which setTrackingStatus() and
128
+ // setTrackingAnswer() steer and trackingPrompts() counts (see tracking.ts).
129
+ installTrackingModule(threadGlobals);
130
+ // LynxCalendar's events, which calendarEvents() lists and
131
+ // answerCalendarSheet() closes the editor for (see calendar.ts).
132
+ installCalendarModule(threadGlobals);
133
+ // LynxNfc's sessions, which tapNfcTag() brings tags to and nfcWrites()
134
+ // lists the writes of (see nfc.ts).
135
+ installNfcModule(threadGlobals);
136
+ // LynxWifi's network and joins, which setWifiNetwork() and
137
+ // queueWifiJoinResult() steer and wifiJoins() lists (see wifi.ts).
138
+ installWifiModule(threadGlobals);
139
+ // LynxAppleSignIn's sign-ins, which setAppleSignInResult() and the other
140
+ // setters in apple-sign-in.ts steer.
141
+ installAppleSignInModule(threadGlobals);
142
+ // LynxPhotoLibrary saves into the library savedPhotos() lists, with the
143
+ // permission setPhotoLibraryPermission() sets (see photo-library.ts).
144
+ installPhotoLibraryModule(threadGlobals);
145
+ // LynxMotion's sensors, which emitMotion(), setHeading() and
146
+ // shakeDevice() sample (see motion.ts).
147
+ installMotionModule(threadGlobals);
148
+ // LynxBackButton enables the back handler pressBackButton() checks (see
149
+ // back-button.ts).
150
+ installShellModule(threadGlobals);
151
+ // LynxBiometrics' prompts and LynxSecureStorage's guarded values, which
152
+ // setBiometrics() and queueBiometricResult() steer (see biometrics.ts).
153
+ installBiometricsModule(threadGlobals);
154
+ // LynxBluetooth finds the devices addBluetoothDevice() adds (see
155
+ // bluetooth.ts).
156
+ installBluetoothModule(threadGlobals);
157
+ // LynxFilePicker's picks and saves, which setPickedFiles(),
158
+ // setFilePickerCanceled() and savedFiles() steer (see file-picker.ts).
159
+ installFilePickerModule(threadGlobals);
101
160
  };
102
161
  // ─── Install LynxTestingEnv ──────────────────────────────────────────────────
103
162
  /**
@@ -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"}