@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,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.1",
3
+ "version": "22.3.3",
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.3"
63
63
  },
64
64
  "ng-update": {
65
65
  "packageGroup": [