@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.
- package/dist/app-state.d.ts +34 -0
- package/dist/app-state.d.ts.map +1 -0
- package/dist/app-state.js +57 -0
- package/dist/apple-sign-in.d.ts +116 -0
- package/dist/apple-sign-in.d.ts.map +1 -0
- package/dist/apple-sign-in.js +179 -0
- package/dist/back-button.d.ts +43 -0
- package/dist/back-button.d.ts.map +1 -0
- package/dist/back-button.js +77 -0
- package/dist/barcode-scanner.d.ts +59 -0
- package/dist/barcode-scanner.d.ts.map +1 -0
- package/dist/barcode-scanner.js +100 -0
- package/dist/biometrics.d.ts +79 -0
- package/dist/biometrics.d.ts.map +1 -0
- package/dist/biometrics.js +151 -0
- package/dist/bluetooth.d.ts +121 -0
- package/dist/bluetooth.d.ts.map +1 -0
- package/dist/bluetooth.js +369 -0
- package/dist/calendar.d.ts +68 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +120 -0
- package/dist/file-picker.d.ts +76 -0
- package/dist/file-picker.d.ts.map +1 -0
- package/dist/file-picker.js +125 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/motion.d.ts +90 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +169 -0
- package/dist/nfc.d.ts +85 -0
- package/dist/nfc.d.ts.map +1 -0
- package/dist/nfc.js +253 -0
- package/dist/photo-library.d.ts +58 -0
- package/dist/photo-library.d.ts.map +1 -0
- package/dist/photo-library.js +91 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +19 -1
- package/dist/setup.js +59 -0
- package/dist/share-target.d.ts +56 -0
- package/dist/share-target.d.ts.map +1 -0
- package/dist/share-target.js +92 -0
- package/dist/store-review.d.ts +30 -0
- package/dist/store-review.d.ts.map +1 -0
- package/dist/store-review.js +49 -0
- package/dist/tracking.d.ts +60 -0
- package/dist/tracking.d.ts.map +1 -0
- package/dist/tracking.js +94 -0
- package/dist/wifi.d.ts +77 -0
- package/dist/wifi.d.ts.map +1 -0
- package/dist/wifi.js +148 -0
- package/package.json +3 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** What `LynxBarcodeScanner` calls, named as the shells name their module. */
|
|
2
|
+
const MODULE = 'AngularLynxBarcodeScanner';
|
|
3
|
+
/**
|
|
4
|
+
* Gives the environment's background thread an `AngularLynxBarcodeScanner`
|
|
5
|
+
* module, as the apps `ng build --platform` makes with `permissions.camera`
|
|
6
|
+
* have. There's no camera to point in a spec, so a scan stays open until
|
|
7
|
+
* {@link queueBarcodeScan}, {@link cancelBarcodeScan} or
|
|
8
|
+
* {@link failBarcodeScan} answers it, or ends at once with what one of them
|
|
9
|
+
* queued before it opened. `LynxBarcodeScanner` reaches it through the
|
|
10
|
+
* background thread, as it reaches the shells' module, so specs see the
|
|
11
|
+
* 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 no scan open and nothing queued. Only
|
|
16
|
+
* `NativeModules.AngularLynxBarcodeScanner` is added: every other module
|
|
17
|
+
* stays as it was.
|
|
18
|
+
*/
|
|
19
|
+
export const installBarcodeScannerModule = (threadGlobals) => {
|
|
20
|
+
const module = {
|
|
21
|
+
queued: [],
|
|
22
|
+
open: undefined,
|
|
23
|
+
scan(_request, done) {
|
|
24
|
+
if (this.open) {
|
|
25
|
+
done({ error: 'failed', message: 'A scan is already open.' });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const answer = this.queued.shift();
|
|
29
|
+
if (answer) {
|
|
30
|
+
done(answer);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.open = done;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
threadGlobals.NativeModules = {
|
|
37
|
+
...threadGlobals.NativeModules,
|
|
38
|
+
[MODULE]: module,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const answer = (name, result) => {
|
|
42
|
+
// Read through the environment rather than kept here: under `ng test`, the
|
|
43
|
+
// setup file and the specs can load different copies of this module.
|
|
44
|
+
const env = globalThis.lynxTestingEnv;
|
|
45
|
+
const module = env?.backgroundThread.globalThis.NativeModules?.[MODULE];
|
|
46
|
+
if (!env || !module) {
|
|
47
|
+
throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
|
|
48
|
+
}
|
|
49
|
+
const open = module.open;
|
|
50
|
+
if (!open) {
|
|
51
|
+
module.queued.push(result);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
module.open = undefined;
|
|
55
|
+
// The shells call back on the background thread, which relays the answer
|
|
56
|
+
// to the main thread, where specs run: it comes back afterwards.
|
|
57
|
+
env.switchToBackgroundThread();
|
|
58
|
+
try {
|
|
59
|
+
open(result);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
env.switchToMainThread();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Has the scanner read `scan`, as if the person pointed the camera at it: the
|
|
67
|
+
* open `LynxBarcodeScanner.scan()` resolves with it, or, when none is open,
|
|
68
|
+
* the next one does as soon as it's called. Each call answers one scan, in
|
|
69
|
+
* order. The answer reaches the app through the background thread, as on a
|
|
70
|
+
* phone: wait for it with `waitForUpdate()`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* await render(CheckIn);
|
|
75
|
+
* queueBarcodeScan({ format: 'qr', value: 'TICKET-42' });
|
|
76
|
+
* fireEvent.tap(screen.getByText('Scan ticket'));
|
|
77
|
+
* await waitForUpdate();
|
|
78
|
+
* expect(screen.getByText('Welcome, ticket 42')).toBeInTheDocument();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export const queueBarcodeScan = (scan) => answer('queueBarcodeScan', { format: scan.format, value: scan.value });
|
|
82
|
+
/**
|
|
83
|
+
* Closes the scanner without a code, as the person does with Cancel: the open
|
|
84
|
+
* `LynxBarcodeScanner.scan()`, or the next one, rejects with a
|
|
85
|
+
* `BarcodeScannerError` whose code is `canceled`.
|
|
86
|
+
*/
|
|
87
|
+
export const cancelBarcodeScan = () => answer('cancelBarcodeScan', {
|
|
88
|
+
error: 'canceled',
|
|
89
|
+
message: 'The scan was canceled.',
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Ends the open `LynxBarcodeScanner.scan()`, or the next one, with a
|
|
93
|
+
* `BarcodeScannerError` of `code`: `denied` for a person who doesn't let the
|
|
94
|
+
* app use the camera, `unavailable` for a phone without a scanner, or
|
|
95
|
+
* `failed`.
|
|
96
|
+
*/
|
|
97
|
+
export const failBarcodeScan = (code, message) => answer('failBarcodeScan', {
|
|
98
|
+
error: code,
|
|
99
|
+
...(message !== undefined && { message }),
|
|
100
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BiometricsErrorCode, BiometryType } from '@blotch/angular-lynx';
|
|
2
|
+
/** The phone {@link setBiometrics} describes. */
|
|
3
|
+
export type FakeBiometrics = {
|
|
4
|
+
/** The sensor, `faceID` unless it's set. `none` for a phone without one. */
|
|
5
|
+
readonly type?: BiometryType;
|
|
6
|
+
/** Whether a face or a finger is set up, true unless it's set. */
|
|
7
|
+
readonly enrolled?: boolean;
|
|
8
|
+
/** Whether the phone has a passcode, true unless it's set. */
|
|
9
|
+
readonly deviceCredential?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How the next prompt ends, as {@link queueBiometricResult} queues it: the
|
|
13
|
+
* person confirms (`success`), or the error `LynxBiometrics` rejects with.
|
|
14
|
+
*/
|
|
15
|
+
export type BiometricResult = 'success' | BiometricsErrorCode;
|
|
16
|
+
/** A prompt the app showed, as {@link biometricPrompts} lists it. */
|
|
17
|
+
export type BiometricPrompt = {
|
|
18
|
+
/** The reason it gave, or `''` for a guarded read that gave none. */
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
/** Whether it let the person use the passcode instead. */
|
|
21
|
+
readonly allowDeviceCredential: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Gives the environment's background thread an `AngularLynxBiometrics`
|
|
25
|
+
* module, as the apps `ng build --platform` makes with
|
|
26
|
+
* `permissions.biometrics` have. It stands for a phone with Face ID set up
|
|
27
|
+
* (see {@link setBiometrics}), where each prompt succeeds unless a spec
|
|
28
|
+
* queues another outcome ({@link queueBiometricResult}), and it keeps the
|
|
29
|
+
* values `LynxSecureStorage` stores with `requireBiometrics`. The runtime
|
|
30
|
+
* reaches it through the background thread, as it reaches the shells'
|
|
31
|
+
* module, so specs see the runtime's own behavior.
|
|
32
|
+
*
|
|
33
|
+
* It runs each time the environment injects the background thread's
|
|
34
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
35
|
+
* starts with that phone, nothing queued and nothing stored.
|
|
36
|
+
*/
|
|
37
|
+
export declare const installBiometricsModule: (threadGlobals: {
|
|
38
|
+
NativeModules?: Record<string, unknown>;
|
|
39
|
+
}) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Describes the phone `LynxBiometrics` sees in this test: its sensor,
|
|
42
|
+
* whether a face or a finger is set up, and whether it has a passcode. Each
|
|
43
|
+
* test starts with Face ID set up behind a passcode; what isn't given keeps
|
|
44
|
+
* that value. `{ type: 'none' }` is a phone without a sensor, or an app
|
|
45
|
+
* without `permissions.biometrics`: prompts then reject with `unavailable`,
|
|
46
|
+
* as does `LynxSecureStorage`'s `requireBiometrics`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* setBiometrics({ type: 'fingerprint', enrolled: false });
|
|
51
|
+
* await render(Unlock);
|
|
52
|
+
* expect(screen.getByText('Set up a fingerprint to unlock')).toBeInTheDocument();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const setBiometrics: (phone: FakeBiometrics) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Has the next biometric prompt end with `result`: the person confirms
|
|
58
|
+
* (`success`), or `LynxBiometrics.authenticate()`, or a `LynxSecureStorage`
|
|
59
|
+
* read of a value kept behind biometrics, rejects with a `BiometricsError`
|
|
60
|
+
* of that code. Results queue in order, one per prompt; once they run out,
|
|
61
|
+
* prompts succeed. A prompt the phone can't show (see {@link setBiometrics})
|
|
62
|
+
* takes none.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* queueBiometricResult('canceled');
|
|
67
|
+
* fireEvent.tap(screen.getByText('Unlock'));
|
|
68
|
+
* await waitForUpdate();
|
|
69
|
+
* expect(screen.getByText('Still locked')).toBeInTheDocument();
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const queueBiometricResult: (result: BiometricResult) => void;
|
|
73
|
+
/**
|
|
74
|
+
* The biometric prompts the app has shown in this test, oldest first: each
|
|
75
|
+
* `authenticate()`, and each read of a value kept behind biometrics. Each
|
|
76
|
+
* test starts with none.
|
|
77
|
+
*/
|
|
78
|
+
export declare const biometricPrompts: () => readonly BiometricPrompt[];
|
|
79
|
+
//# sourceMappingURL=biometrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"biometrics.d.ts","sourceRoot":"","sources":["../src/biometrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAK9E,iDAAiD;AACjD,MAAM,MAAM,cAAc,GAAG;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,mBAAmB,CAAC;AAE9D,qEAAqE;AACrE,MAAM,MAAM,eAAe,GAAG;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;CACzC,CAAC;AA2BF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAAI,eAAe;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAoDH,CAAC;AAkCF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,cAAc,KAAG,IAGrD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,eAAe,KAAG,IAE9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAO,SAAS,eAAe,EAE3D,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/** What `LynxBiometrics` and `LynxSecureStorage` call, as the shells name it. */
|
|
2
|
+
const MODULE = 'AngularLynxBiometrics';
|
|
3
|
+
/** The phone a test starts with: Face ID, set up, behind a passcode. */
|
|
4
|
+
const DEFAULT_PHONE = {
|
|
5
|
+
type: 'faceID',
|
|
6
|
+
enrolled: true,
|
|
7
|
+
deviceCredential: true,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Gives the environment's background thread an `AngularLynxBiometrics`
|
|
11
|
+
* module, as the apps `ng build --platform` makes with
|
|
12
|
+
* `permissions.biometrics` have. It stands for a phone with Face ID set up
|
|
13
|
+
* (see {@link setBiometrics}), where each prompt succeeds unless a spec
|
|
14
|
+
* queues another outcome ({@link queueBiometricResult}), and it keeps the
|
|
15
|
+
* values `LynxSecureStorage` stores with `requireBiometrics`. The runtime
|
|
16
|
+
* reaches it through the background thread, as it reaches the shells'
|
|
17
|
+
* module, so specs see the runtime's own behavior.
|
|
18
|
+
*
|
|
19
|
+
* It runs each time the environment injects the background thread's
|
|
20
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
21
|
+
* starts with that phone, nothing queued and nothing stored.
|
|
22
|
+
*/
|
|
23
|
+
export const installBiometricsModule = (threadGlobals) => {
|
|
24
|
+
const module = {
|
|
25
|
+
phone: { ...DEFAULT_PHONE },
|
|
26
|
+
queued: [],
|
|
27
|
+
prompts: [],
|
|
28
|
+
guarded: new Map(),
|
|
29
|
+
availability(done) {
|
|
30
|
+
done({ ...this.phone });
|
|
31
|
+
},
|
|
32
|
+
authenticate(options, done) {
|
|
33
|
+
const allowDeviceCredential = options.allowDeviceCredential === true;
|
|
34
|
+
const refusal = refuse(this.phone, allowDeviceCredential);
|
|
35
|
+
if (refusal)
|
|
36
|
+
return done(refusal);
|
|
37
|
+
this.prompts.push({ reason: options.reason, allowDeviceCredential });
|
|
38
|
+
done(outcome(this.queued.shift()));
|
|
39
|
+
},
|
|
40
|
+
getItem(key, reason, done) {
|
|
41
|
+
const value = this.guarded.get(key);
|
|
42
|
+
if (value === undefined)
|
|
43
|
+
return done({});
|
|
44
|
+
// A phone that can't show the prompt can't open the value either.
|
|
45
|
+
const refusal = refuse(this.phone, false);
|
|
46
|
+
if (refusal)
|
|
47
|
+
return done(refusal);
|
|
48
|
+
this.prompts.push({ reason, allowDeviceCredential: false });
|
|
49
|
+
const result = outcome(this.queued.shift());
|
|
50
|
+
done(result['error'] === undefined ? { value } : result);
|
|
51
|
+
},
|
|
52
|
+
setItem(key, value, done) {
|
|
53
|
+
// Biometric values need a sensor, a face or finger set up and a
|
|
54
|
+
// passcode, as on a phone.
|
|
55
|
+
if (this.phone.type === 'none' || !this.phone.deviceCredential) {
|
|
56
|
+
return done({
|
|
57
|
+
error: 'unavailable',
|
|
58
|
+
message: 'This phone has no biometrics to keep the value behind.',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!this.phone.enrolled)
|
|
62
|
+
return done({ error: 'notEnrolled' });
|
|
63
|
+
this.guarded.set(key, value);
|
|
64
|
+
done({});
|
|
65
|
+
},
|
|
66
|
+
removeItem(key, done) {
|
|
67
|
+
this.guarded.delete(key);
|
|
68
|
+
done({});
|
|
69
|
+
},
|
|
70
|
+
clear(done) {
|
|
71
|
+
this.guarded.clear();
|
|
72
|
+
done({});
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
threadGlobals.NativeModules = {
|
|
76
|
+
...threadGlobals.NativeModules,
|
|
77
|
+
[MODULE]: module,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Why `phone` can't show the prompt, if it can't.
|
|
82
|
+
*/
|
|
83
|
+
const refuse = (phone, allowDeviceCredential) => {
|
|
84
|
+
if (allowDeviceCredential && phone.deviceCredential)
|
|
85
|
+
return undefined;
|
|
86
|
+
if (phone.type === 'none')
|
|
87
|
+
return { error: 'unavailable' };
|
|
88
|
+
if (!phone.enrolled)
|
|
89
|
+
return { error: 'notEnrolled' };
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
const outcome = (result = 'success') => result === 'success' ? {} : { error: result };
|
|
93
|
+
/**
|
|
94
|
+
* The fake module, read through the environment rather than kept here:
|
|
95
|
+
* under `ng test`, the setup file and the specs can load different copies of
|
|
96
|
+
* this module.
|
|
97
|
+
*/
|
|
98
|
+
const fakeModule = (helper) => {
|
|
99
|
+
const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
|
|
100
|
+
.NativeModules?.[MODULE];
|
|
101
|
+
if (!module) {
|
|
102
|
+
throw new Error(`${helper}() needs the testing library's environment, which its setup file installs.`);
|
|
103
|
+
}
|
|
104
|
+
return module;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Describes the phone `LynxBiometrics` sees in this test: its sensor,
|
|
108
|
+
* whether a face or a finger is set up, and whether it has a passcode. Each
|
|
109
|
+
* test starts with Face ID set up behind a passcode; what isn't given keeps
|
|
110
|
+
* that value. `{ type: 'none' }` is a phone without a sensor, or an app
|
|
111
|
+
* without `permissions.biometrics`: prompts then reject with `unavailable`,
|
|
112
|
+
* as does `LynxSecureStorage`'s `requireBiometrics`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* setBiometrics({ type: 'fingerprint', enrolled: false });
|
|
117
|
+
* await render(Unlock);
|
|
118
|
+
* expect(screen.getByText('Set up a fingerprint to unlock')).toBeInTheDocument();
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export const setBiometrics = (phone) => {
|
|
122
|
+
const module = fakeModule('setBiometrics');
|
|
123
|
+
module.phone = { ...module.phone, ...phone };
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Has the next biometric prompt end with `result`: the person confirms
|
|
127
|
+
* (`success`), or `LynxBiometrics.authenticate()`, or a `LynxSecureStorage`
|
|
128
|
+
* read of a value kept behind biometrics, rejects with a `BiometricsError`
|
|
129
|
+
* of that code. Results queue in order, one per prompt; once they run out,
|
|
130
|
+
* prompts succeed. A prompt the phone can't show (see {@link setBiometrics})
|
|
131
|
+
* takes none.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* queueBiometricResult('canceled');
|
|
136
|
+
* fireEvent.tap(screen.getByText('Unlock'));
|
|
137
|
+
* await waitForUpdate();
|
|
138
|
+
* expect(screen.getByText('Still locked')).toBeInTheDocument();
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export const queueBiometricResult = (result) => {
|
|
142
|
+
fakeModule('queueBiometricResult').queued.push(result);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The biometric prompts the app has shown in this test, oldest first: each
|
|
146
|
+
* `authenticate()`, and each read of a value kept behind biometrics. Each
|
|
147
|
+
* test starts with none.
|
|
148
|
+
*/
|
|
149
|
+
export const biometricPrompts = () => [
|
|
150
|
+
...fakeModule('biometricPrompts').prompts,
|
|
151
|
+
];
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { BluetoothCharacteristicProperty, BluetoothState } from '@blotch/angular-lynx';
|
|
2
|
+
/** A characteristic of a {@link FakeBluetoothDevice}. */
|
|
3
|
+
export type FakeBluetoothCharacteristic = {
|
|
4
|
+
/** What it lets a connection do. By default it can be read, written and notified. */
|
|
5
|
+
readonly properties?: readonly BluetoothCharacteristicProperty[];
|
|
6
|
+
/** What a read gets. Change it to change what the next read gets. */
|
|
7
|
+
value?: Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Called with each value the app writes, and the device, so a spec can
|
|
10
|
+
* answer the way the real device does, such as notifying a status.
|
|
11
|
+
*/
|
|
12
|
+
readonly onWrite?: (value: Uint8Array, device: FakeBluetoothDeviceRef) => void;
|
|
13
|
+
};
|
|
14
|
+
/** A device {@link addBluetoothDevice} puts in range of the app. */
|
|
15
|
+
export type FakeBluetoothDevice = {
|
|
16
|
+
/** What `LynxBluetooth.connect()` takes. */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly name?: string | null;
|
|
19
|
+
/** Its signal strength, in dBm. */
|
|
20
|
+
readonly rssi?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The services it advertises, which a scan matches against. By default,
|
|
23
|
+
* every service in {@link services}.
|
|
24
|
+
*/
|
|
25
|
+
readonly advertisedServices?: readonly string[];
|
|
26
|
+
/** The data it advertises for a service, by the service's UUID. */
|
|
27
|
+
readonly serviceData?: Readonly<Record<string, Uint8Array>>;
|
|
28
|
+
/** The data it advertises for a manufacturer, by company identifier. */
|
|
29
|
+
readonly manufacturerData?: Readonly<Record<number, Uint8Array>>;
|
|
30
|
+
/** Its services: each service's characteristics, by UUID. */
|
|
31
|
+
readonly services?: Readonly<Record<string, Readonly<Record<string, FakeBluetoothCharacteristic>>>>;
|
|
32
|
+
/**
|
|
33
|
+
* The most bytes one write without response carries. A longer one is
|
|
34
|
+
* refused, as the shells refuse it, so a spec catches an app that doesn't
|
|
35
|
+
* split what it writes.
|
|
36
|
+
*/
|
|
37
|
+
readonly maxWriteLength?: number;
|
|
38
|
+
};
|
|
39
|
+
/** A value the app wrote to a {@link FakeBluetoothDevice}. */
|
|
40
|
+
export type FakeBluetoothWrite = {
|
|
41
|
+
readonly service: string;
|
|
42
|
+
readonly characteristic: string;
|
|
43
|
+
readonly value: Uint8Array;
|
|
44
|
+
readonly withResponse: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** What {@link addBluetoothDevice} gives a spec to drive the device with. */
|
|
47
|
+
export type FakeBluetoothDeviceRef = {
|
|
48
|
+
/** Whether the app is connected to it. */
|
|
49
|
+
readonly connected: boolean;
|
|
50
|
+
/** What the app wrote to it, oldest first. */
|
|
51
|
+
readonly writes: readonly FakeBluetoothWrite[];
|
|
52
|
+
/**
|
|
53
|
+
* Sends a value from a characteristic, as a notification. It reaches the
|
|
54
|
+
* app only while it's connected and subscribed to the characteristic.
|
|
55
|
+
*/
|
|
56
|
+
notify(service: string, characteristic: string, value: Uint8Array): void;
|
|
57
|
+
/** Ends the app's connection from the device's side, as going out of range does. */
|
|
58
|
+
disconnect(): void;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Gives the environment's background thread an `AngularLynxBluetooth`
|
|
62
|
+
* module, as the apps `ng build --platform` makes have when angular.json's
|
|
63
|
+
* `permissions` list `bluetooth`. The devices in range are the ones
|
|
64
|
+
* {@link addBluetoothDevice} adds, and the radio is on and allowed until
|
|
65
|
+
* {@link setBluetoothState} says otherwise. `LynxBluetooth` reaches it
|
|
66
|
+
* through the background thread, as it reaches the shells' module, so specs
|
|
67
|
+
* see the runtime's own behavior.
|
|
68
|
+
*
|
|
69
|
+
* It runs each time the environment injects the background thread's
|
|
70
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
71
|
+
* starts with no devices and the radio on.
|
|
72
|
+
*/
|
|
73
|
+
export declare const installBluetoothModule: (threadGlobals: {
|
|
74
|
+
NativeModules?: Record<string, unknown>;
|
|
75
|
+
}) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Puts a Bluetooth LE device in range of the app, for `LynxBluetooth` to
|
|
78
|
+
* find, connect to and talk to as it would a real one. A scan that's running
|
|
79
|
+
* sees it at once, and one that starts later sees it as it starts. Each test
|
|
80
|
+
* starts with none, and adding an id a second time throws.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const frame = addBluetoothDevice({
|
|
85
|
+
* id: 'frame',
|
|
86
|
+
* name: 'Blotch - XyZ1',
|
|
87
|
+
* services: {
|
|
88
|
+
* [SETUP_SERVICE]: {
|
|
89
|
+
* [CREDENTIALS]: {
|
|
90
|
+
* properties: ['write'],
|
|
91
|
+
* onWrite: (_value, device) =>
|
|
92
|
+
* device.notify(SETUP_SERVICE, STATUS, encode('connected')),
|
|
93
|
+
* },
|
|
94
|
+
* [STATUS]: { properties: ['notify'] },
|
|
95
|
+
* },
|
|
96
|
+
* },
|
|
97
|
+
* });
|
|
98
|
+
* await render(SetUpFrame);
|
|
99
|
+
* fireEvent.tap(await screen.findByText('Blotch - XyZ1'));
|
|
100
|
+
* // …
|
|
101
|
+
* expect(frame.writes).toHaveLength(1);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare const addBluetoothDevice: (device: FakeBluetoothDevice) => FakeBluetoothDeviceRef;
|
|
105
|
+
/**
|
|
106
|
+
* Sets the state of the phone's Bluetooth, as the person turning it off or
|
|
107
|
+
* refusing permission does, so a spec can check what the app shows then.
|
|
108
|
+
* Anything but `poweredOn` ends a running scan and every connection, as it
|
|
109
|
+
* does on a phone. `unknown` stands for not asked yet: the person allows it
|
|
110
|
+
* when `LynxBluetooth` asks, as `requestPermission()`, `scan()` and
|
|
111
|
+
* `connect()` do.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* setBluetoothState('poweredOff');
|
|
116
|
+
* await render(SetUpFrame);
|
|
117
|
+
* expect(await screen.findByText('Turn on Bluetooth')).toBeInTheDocument();
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare const setBluetoothState: (state: BluetoothState) => void;
|
|
121
|
+
//# sourceMappingURL=bluetooth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bluetooth.d.ts","sourceRoot":"","sources":["../src/bluetooth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+BAA+B,EAC/B,cAAc,EACf,MAAM,sBAAsB,CAAC;AAM9B,yDAAyD;AACzD,MAAM,MAAM,2BAA2B,GAAG;IACxC,qFAAqF;IACrF,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACjE,qEAAqE;IACrE,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CACjB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,sBAAsB,KAC3B,IAAI,CAAC;CACX,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG;IAChC,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,mCAAmC;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,mEAAmE;IACnE,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC5D,wEAAwE;IACxE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACjE,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAC1B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC,CAAC,CACtE,CAAC;IACF;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,sBAAsB,GAAG;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC/C;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzE,oFAAoF;IACpF,UAAU,IAAI,IAAI,CAAC;CACpB,CAAC;AA8LF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,GAAI,eAAe;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAgKH,CAAC;AAmBF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,mBAAmB,KAC1B,sBA6CF,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,cAAc,KAAG,IAWzD,CAAC"}
|