@blotch/angular-lynx-testing-library 22.3.0 → 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
@@ -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"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * What `LynxTracking` calls, named as the shells name their module.
3
+ */
4
+ const MODULE = 'AngularLynxTracking';
5
+ /**
6
+ * Gives the environment's background thread an `AngularLynxTracking` module,
7
+ * as the apps `ng build --platform` makes with `permissions.tracking` have.
8
+ * It starts where a fresh install on an iPhone does, `notDetermined`, and
9
+ * the person allows tracking when the app asks. `LynxTracking` reaches it
10
+ * through the background thread, as it reaches the shells' module.
11
+ *
12
+ * It runs each time the environment injects the background thread's
13
+ * globals: when it's created, and on the reset after each test, so each test
14
+ * starts from a fresh install.
15
+ */
16
+ export const installTrackingModule = (threadGlobals) => {
17
+ const state = {
18
+ status: 'notDetermined',
19
+ answer: 'authorized',
20
+ prompts: 0,
21
+ };
22
+ const module = {
23
+ state,
24
+ status(done) {
25
+ done({ status: state.status });
26
+ },
27
+ // iOS shows the prompt only to a person who hasn't answered, and answers
28
+ // with the status after that.
29
+ request(done) {
30
+ if (state.status === 'notDetermined') {
31
+ state.prompts++;
32
+ state.status = state.answer;
33
+ }
34
+ done({ status: state.status });
35
+ },
36
+ };
37
+ threadGlobals.NativeModules = {
38
+ ...threadGlobals.NativeModules,
39
+ [MODULE]: module,
40
+ };
41
+ };
42
+ const fakeState = () =>
43
+ // Read through the environment rather than kept here: under `ng test`, the
44
+ // setup file and the specs can load different copies of this module.
45
+ globalThis.lynxTestingEnv?.backgroundThread.globalThis
46
+ .NativeModules?.[MODULE]?.state;
47
+ /**
48
+ * Sets whether the app may track the person, as if they'd answered the
49
+ * prompt or changed it in Settings: what `LynxTracking.status()` reads, and
50
+ * what `requestPermission()` resolves with, without a prompt unless it's
51
+ * `notDetermined`. Each test starts at `notDetermined`.
52
+ *
53
+ * `LynxTracking` reads the status when it's created, and again when the app
54
+ * comes back to the foreground, so set it before `render()`, or follow it
55
+ * with `setAppState('background')` and `setAppState('active')`, as a person
56
+ * coming back from Settings would. Wait with `waitForUpdate()` after each:
57
+ * the service watches the app's state with an `effect()`, which runs once
58
+ * for two changes made together and never sees the app leave.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * setTrackingStatus('denied');
63
+ * await render(AdBanner);
64
+ * expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();
65
+ * ```
66
+ */
67
+ export const setTrackingStatus = (status) => {
68
+ const state = fakeState();
69
+ if (state)
70
+ state.status = status;
71
+ };
72
+ /**
73
+ * Sets what the person answers when `requestPermission()` shows the prompt:
74
+ * `authorized` (the default) or `denied`. The prompt shows only while the
75
+ * status is `notDetermined`.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * setTrackingAnswer('denied');
80
+ * fireEvent.tap(screen.getByText('Continue'));
81
+ * await waitForUpdate();
82
+ * expect(trackingPrompts()).toBe(1);
83
+ * ```
84
+ */
85
+ export const setTrackingAnswer = (answer) => {
86
+ const state = fakeState();
87
+ if (state)
88
+ state.answer = answer;
89
+ };
90
+ /**
91
+ * How many times `requestPermission()` has shown the prompt in this test, so
92
+ * a spec can check the app asks at the right moment, and only once.
93
+ */
94
+ export const trackingPrompts = () => fakeState()?.prompts ?? 0;
package/dist/wifi.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ /** A Wi-Fi network the spec's phone is on, as `LynxWifi.currentNetwork()` resolves it. */
2
+ export type FakeWifiNetwork = {
3
+ readonly ssid: string;
4
+ readonly bssid?: string;
5
+ };
6
+ /** A network the app joined, as `LynxWifi.join()` was given it. */
7
+ export type WifiJoinRequest = {
8
+ readonly ssid: string;
9
+ readonly password?: string;
10
+ readonly joinOnce: boolean;
11
+ };
12
+ /** Why a `LynxWifi` call fails, as `WifiError`'s `code` names it. */
13
+ export type FakeWifiFailure = 'denied' | 'notFound' | 'canceled' | 'unavailable' | 'failed';
14
+ /**
15
+ * Gives the environment's background thread an `AngularLynxWifi` module, as
16
+ * the apps `ng build --platform` makes with angular.json's `wifi` have. The
17
+ * phone starts off Wi-Fi (`currentNetwork()` resolves null) until
18
+ * {@link setWifiNetwork} puts it on one, and every `join()` succeeds, putting
19
+ * the phone on the network, unless {@link queueWifiJoinResult} queued
20
+ * another answer. `leave()` puts it back on the network it was on before.
21
+ * `LynxWifi` reaches it through the background thread, as it reaches the
22
+ * shells' module, so specs see the runtime's own behavior.
23
+ *
24
+ * It runs each time the environment injects the background thread's
25
+ * globals: when it's created, and on the reset after each test, so each test
26
+ * starts off Wi-Fi, with no joins and nothing queued.
27
+ */
28
+ export declare const installWifiModule: (threadGlobals: {
29
+ NativeModules?: Record<string, unknown>;
30
+ }) => void;
31
+ /**
32
+ * Puts the spec's phone on `network`, which `LynxWifi.currentNetwork()`
33
+ * resolves from then on, or off Wi-Fi with null. Each test starts off it.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * setWifiNetwork({ ssid: 'Home' });
38
+ * await render(FrameSetup);
39
+ * await waitForUpdate();
40
+ * expect(screen.getByText('Home')).toBeInTheDocument();
41
+ * ```
42
+ */
43
+ export declare const setWifiNetwork: (network: FakeWifiNetwork | null) => void;
44
+ /**
45
+ * Makes `LynxWifi.currentNetwork()` reject with a `WifiError` of `code`
46
+ * from then on, `denied` by default, as on a phone whose owner refused the
47
+ * app their location, which both platforms ask for on the first read. `allowWifiNetworkRead()` undoes it.
48
+ */
49
+ export declare const denyWifiNetworkRead: (code?: FakeWifiFailure, message?: string | undefined) => void;
50
+ /** Lets `LynxWifi.currentNetwork()` read the network again. */
51
+ export declare const allowWifiNetworkRead: () => void;
52
+ /**
53
+ * Answers the next `LynxWifi.join()` with `result`: `joined` (the default
54
+ * answer, which puts the phone on the network) or a `WifiError` of that
55
+ * code, such as `notFound` for a device that isn't in range or `canceled`
56
+ * for a person who said no. Each call answers one join, in order.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * queueWifiJoinResult('notFound');
61
+ * fireEvent.tap(screen.getByText('Connect to the frame'));
62
+ * await waitForUpdate();
63
+ * expect(screen.getByText('Is the frame switched on?')).toBeInTheDocument();
64
+ * ```
65
+ */
66
+ export declare const queueWifiJoinResult: (result: "joined" | FakeWifiFailure, message?: string) => void;
67
+ /**
68
+ * The networks the app has joined through `LynxWifi.join()` in this test,
69
+ * oldest first, with the password it gave, answered or not.
70
+ */
71
+ export declare const wifiJoins: () => readonly WifiJoinRequest[];
72
+ /**
73
+ * The networks the app has left through `LynxWifi.leave()` in this test,
74
+ * oldest first.
75
+ */
76
+ export declare const wifiLeaves: () => readonly string[];
77
+ //# sourceMappingURL=wifi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wifi.d.ts","sourceRoot":"","sources":["../src/wifi.ts"],"names":[],"mappings":"AAKA,0FAA0F;AAC1F,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,UAAU,GACV,UAAU,GACV,aAAa,GACb,QAAQ,CAAC;AA2Cb;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,eAAe;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAkDH,CAAC;AAsBF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,eAAe,GAAG,IAAI,KAAG,IAEhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAM,eAA0B,EAChC,UAAS,MAAM,GAAG,SAA0D,KAC3E,IAKF,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,QAAO,IAEvC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,QAAQ,GAAG,eAAe,EAClC,UAAU,MAAM,KACf,IAMF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAO,SAAS,eAAe,EAEpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAO,SAAS,MAAM,EAE5C,CAAC"}
package/dist/wifi.js ADDED
@@ -0,0 +1,148 @@
1
+ /** What `LynxWifi` calls, named as the shells name their module. */
2
+ const MODULE = 'AngularLynxWifi';
3
+ /**
4
+ * What Android answers once the person refuses the location prompt: the
5
+ * message an app on a phone shows.
6
+ */
7
+ const DENIED_MESSAGE = "The person didn't give the app their precise location, which Android needs to give the Wi-Fi network's name. Once they've refused it twice, Android stops asking, and only Settings can grant it.";
8
+ /**
9
+ * Gives the environment's background thread an `AngularLynxWifi` module, as
10
+ * the apps `ng build --platform` makes with angular.json's `wifi` have. The
11
+ * phone starts off Wi-Fi (`currentNetwork()` resolves null) until
12
+ * {@link setWifiNetwork} puts it on one, and every `join()` succeeds, putting
13
+ * the phone on the network, unless {@link queueWifiJoinResult} queued
14
+ * another answer. `leave()` puts it back on the network it was on before.
15
+ * `LynxWifi` reaches it through the background thread, as it reaches the
16
+ * shells' module, so specs see the runtime's own behavior.
17
+ *
18
+ * It runs each time the environment injects the background thread's
19
+ * globals: when it's created, and on the reset after each test, so each test
20
+ * starts off Wi-Fi, with no joins and nothing queued.
21
+ */
22
+ export const installWifiModule = (threadGlobals) => {
23
+ const module = {
24
+ network: null,
25
+ before: new Map(),
26
+ readFailure: undefined,
27
+ joins: [],
28
+ leaves: [],
29
+ queued: [],
30
+ currentNetwork(done) {
31
+ if (this.readFailure) {
32
+ done({
33
+ error: this.readFailure.code,
34
+ ...(this.readFailure.message !== undefined && {
35
+ message: this.readFailure.message,
36
+ }),
37
+ });
38
+ return;
39
+ }
40
+ done(this.network ? { ...this.network } : { none: true });
41
+ },
42
+ join(options, done) {
43
+ this.joins.push({
44
+ ssid: options.ssid,
45
+ joinOnce: options.joinOnce,
46
+ ...(options.password !== undefined && { password: options.password }),
47
+ });
48
+ const answer = this.queued.shift() ?? { done: true };
49
+ if ('done' in answer) {
50
+ if (!this.before.has(options.ssid)) {
51
+ this.before.set(options.ssid, this.network);
52
+ }
53
+ this.network = { ssid: options.ssid };
54
+ }
55
+ done(answer);
56
+ },
57
+ leave(ssid, done) {
58
+ this.leaves.push(ssid);
59
+ if (this.before.has(ssid)) {
60
+ if (this.network?.ssid === ssid) {
61
+ this.network = this.before.get(ssid) ?? null;
62
+ }
63
+ this.before.delete(ssid);
64
+ }
65
+ done({ done: true });
66
+ },
67
+ };
68
+ threadGlobals.NativeModules = {
69
+ ...threadGlobals.NativeModules,
70
+ [MODULE]: module,
71
+ };
72
+ };
73
+ /**
74
+ * The fake module, read through the environment rather than kept here:
75
+ * under `ng test`, the setup file and the specs can load different copies of
76
+ * this file.
77
+ */
78
+ const fakeModule = (name) => {
79
+ const env = globalThis.lynxTestingEnv;
80
+ const module = env?.backgroundThread.globalThis.NativeModules?.[MODULE];
81
+ if (!module) {
82
+ throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
83
+ }
84
+ return module;
85
+ };
86
+ /**
87
+ * Puts the spec's phone on `network`, which `LynxWifi.currentNetwork()`
88
+ * resolves from then on, or off Wi-Fi with null. Each test starts off it.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * setWifiNetwork({ ssid: 'Home' });
93
+ * await render(FrameSetup);
94
+ * await waitForUpdate();
95
+ * expect(screen.getByText('Home')).toBeInTheDocument();
96
+ * ```
97
+ */
98
+ export const setWifiNetwork = (network) => {
99
+ fakeModule('setWifiNetwork').network = network ? { ...network } : null;
100
+ };
101
+ /**
102
+ * Makes `LynxWifi.currentNetwork()` reject with a `WifiError` of `code`
103
+ * from then on, `denied` by default, as on a phone whose owner refused the
104
+ * app their location, which both platforms ask for on the first read. `allowWifiNetworkRead()` undoes it.
105
+ */
106
+ export const denyWifiNetworkRead = (code = 'denied', message = code === 'denied' ? DENIED_MESSAGE : undefined) => {
107
+ fakeModule('denyWifiNetworkRead').readFailure = {
108
+ code,
109
+ ...(message !== undefined && { message }),
110
+ };
111
+ };
112
+ /** Lets `LynxWifi.currentNetwork()` read the network again. */
113
+ export const allowWifiNetworkRead = () => {
114
+ fakeModule('allowWifiNetworkRead').readFailure = undefined;
115
+ };
116
+ /**
117
+ * Answers the next `LynxWifi.join()` with `result`: `joined` (the default
118
+ * answer, which puts the phone on the network) or a `WifiError` of that
119
+ * code, such as `notFound` for a device that isn't in range or `canceled`
120
+ * for a person who said no. Each call answers one join, in order.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * queueWifiJoinResult('notFound');
125
+ * fireEvent.tap(screen.getByText('Connect to the frame'));
126
+ * await waitForUpdate();
127
+ * expect(screen.getByText('Is the frame switched on?')).toBeInTheDocument();
128
+ * ```
129
+ */
130
+ export const queueWifiJoinResult = (result, message) => {
131
+ fakeModule('queueWifiJoinResult').queued.push(result === 'joined'
132
+ ? { done: true }
133
+ : { error: result, ...(message !== undefined && { message }) });
134
+ };
135
+ /**
136
+ * The networks the app has joined through `LynxWifi.join()` in this test,
137
+ * oldest first, with the password it gave, answered or not.
138
+ */
139
+ export const wifiJoins = () => [
140
+ ...fakeModule('wifiJoins').joins,
141
+ ];
142
+ /**
143
+ * The networks the app has left through `LynxWifi.leave()` in this test,
144
+ * oldest first.
145
+ */
146
+ export const wifiLeaves = () => [
147
+ ...fakeModule('wifiLeaves').leaves,
148
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/angular-lynx-testing-library",
3
- "version": "22.3.0",
3
+ "version": "22.3.2",
4
4
  "description": "Testing utilities for AngularLynx apps",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {
@@ -52,14 +52,14 @@
52
52
  "@angular/platform-browser": "^22.3.0",
53
53
  "@blotch/angular-lynx": "*",
54
54
  "@types/node": "^22.0.0",
55
- "jsdom": "^31.0.0",
55
+ "jsdom": "^31.0.1",
56
56
  "typescript": "~6.0.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@angular/compiler": "^22.3.0",
60
60
  "@angular/core": "^22.3.0",
61
61
  "@angular/platform-browser": "^22.3.0",
62
- "@blotch/angular-lynx": "^22.3.0"
62
+ "@blotch/angular-lynx": "^22.3.2"
63
63
  },
64
64
  "ng-update": {
65
65
  "packageGroup": [