@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.
- package/dist/app-state.d.ts +34 -0
- package/dist/app-state.d.ts.map +1 -0
- package/dist/app-state.js +33 -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/audio-recorder.d.ts +95 -0
- package/dist/audio-recorder.d.ts.map +1 -0
- package/dist/audio-recorder.js +250 -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/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +58 -8
- package/dist/geolocation.d.ts +94 -0
- package/dist/geolocation.d.ts.map +1 -0
- package/dist/geolocation.js +255 -0
- package/dist/global-props.d.ts +17 -0
- package/dist/global-props.d.ts.map +1 -0
- package/dist/global-props.js +35 -0
- package/dist/image-picker.d.ts +84 -0
- package/dist/image-picker.d.ts.map +1 -0
- package/dist/image-picker.js +140 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/motion.d.ts +90 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +169 -0
- package/dist/network.d.ts +26 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +31 -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 +86 -7
- 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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the app is, as the runtime's `LynxAppState.state` reports it. Kept
|
|
3
|
+
* here rather than imported, so the library's types don't reach into the
|
|
4
|
+
* runtime's.
|
|
5
|
+
*/
|
|
6
|
+
export type AppState = 'active' | 'inactive' | 'background';
|
|
7
|
+
/**
|
|
8
|
+
* Sends the app to the background, or brings it back, as the person does by
|
|
9
|
+
* leaving the app and coming back to it, so a spec can check what the app
|
|
10
|
+
* does on its return. `LynxAppState.state()` becomes `state`, and
|
|
11
|
+
* `LynxAppState.active()` is `true` only for `'active'`.
|
|
12
|
+
*
|
|
13
|
+
* It reaches the app as it does on a phone, as a change to the host's global
|
|
14
|
+
* props: change detection runs on its own, so wait for it with
|
|
15
|
+
* `waitForUpdate()`. Wait between two states too: an `effect()` runs once
|
|
16
|
+
* for both otherwise, and never sees the app leave. Each test starts `active`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* await render(Schedule);
|
|
21
|
+
* setAppState('background');
|
|
22
|
+
* await waitForUpdate();
|
|
23
|
+
* vi.setSystemTime(new Date('2026-01-02T09:00'));
|
|
24
|
+
* setAppState('active');
|
|
25
|
+
* await waitForUpdate();
|
|
26
|
+
* expect(screen.getByText('Today: 2 January')).toBeInTheDocument();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param state - `'background'` when the app leaves the screen, `'inactive'`
|
|
30
|
+
* while it's on screen but not taking touches (Control Center pulled over
|
|
31
|
+
* it, or a call coming in), and `'active'` when it's back.
|
|
32
|
+
*/
|
|
33
|
+
export declare const setAppState: (state: AppState) => void;
|
|
34
|
+
//# sourceMappingURL=app-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-state.d.ts","sourceRoot":"","sources":["../src/app-state.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;AAQ5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,KAAG,IACO,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { setGlobalProp } from './global-props.js';
|
|
2
|
+
/**
|
|
3
|
+
* The global prop the shells send the state in (see the runtime's
|
|
4
|
+
* app-state.ts).
|
|
5
|
+
*/
|
|
6
|
+
const APP_STATE_PROP = 'appState';
|
|
7
|
+
/**
|
|
8
|
+
* Sends the app to the background, or brings it back, as the person does by
|
|
9
|
+
* leaving the app and coming back to it, so a spec can check what the app
|
|
10
|
+
* does on its return. `LynxAppState.state()` becomes `state`, and
|
|
11
|
+
* `LynxAppState.active()` is `true` only for `'active'`.
|
|
12
|
+
*
|
|
13
|
+
* It reaches the app as it does on a phone, as a change to the host's global
|
|
14
|
+
* props: change detection runs on its own, so wait for it with
|
|
15
|
+
* `waitForUpdate()`. Wait between two states too: an `effect()` runs once
|
|
16
|
+
* for both otherwise, and never sees the app leave. Each test starts `active`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* await render(Schedule);
|
|
21
|
+
* setAppState('background');
|
|
22
|
+
* await waitForUpdate();
|
|
23
|
+
* vi.setSystemTime(new Date('2026-01-02T09:00'));
|
|
24
|
+
* setAppState('active');
|
|
25
|
+
* await waitForUpdate();
|
|
26
|
+
* expect(screen.getByText('Today: 2 January')).toBeInTheDocument();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param state - `'background'` when the app leaves the screen, `'inactive'`
|
|
30
|
+
* while it's on screen but not taking touches (Control Center pulled over
|
|
31
|
+
* it, or a call coming in), and `'active'` when it's back.
|
|
32
|
+
*/
|
|
33
|
+
export const setAppState = (state) => setGlobalProp(APP_STATE_PROP, state, 'setAppState');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the person's next sign-ins return, for {@link setAppleSignInResult}.
|
|
3
|
+
* Anything left out takes a test value: `user` is `test-apple-user`, and the
|
|
4
|
+
* tokens are `test-identity-token` and `test-authorization-code`.
|
|
5
|
+
*/
|
|
6
|
+
export type FakeAppleSignInResult = {
|
|
7
|
+
readonly user?: string;
|
|
8
|
+
readonly identityToken?: string;
|
|
9
|
+
readonly authorizationCode?: string;
|
|
10
|
+
/** Returned only when the sign-in asks for the `email` scope, as Apple does. */
|
|
11
|
+
readonly email?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Returned only when the sign-in asks for the `fullName` scope, as Apple
|
|
14
|
+
* does.
|
|
15
|
+
*/
|
|
16
|
+
readonly fullName?: {
|
|
17
|
+
readonly givenName?: string;
|
|
18
|
+
readonly familyName?: string;
|
|
19
|
+
readonly middleName?: string;
|
|
20
|
+
readonly nickname?: string;
|
|
21
|
+
readonly namePrefix?: string;
|
|
22
|
+
readonly nameSuffix?: string;
|
|
23
|
+
};
|
|
24
|
+
/** `likelyReal` when it's left out. */
|
|
25
|
+
readonly realUserStatus?: 'likelyReal' | 'unknown' | 'unsupported';
|
|
26
|
+
};
|
|
27
|
+
/** A sign-in the app opened, as {@link appleSignInRequests} lists it. */
|
|
28
|
+
export type AppleSignInRequest = {
|
|
29
|
+
readonly scopes: readonly string[];
|
|
30
|
+
readonly nonce?: string;
|
|
31
|
+
readonly state?: string;
|
|
32
|
+
};
|
|
33
|
+
/** A user identifier's state, as `LynxAppleSignIn.getCredentialState()` resolves. */
|
|
34
|
+
export type FakeAppleCredentialState = 'authorized' | 'revoked' | 'notFound' | 'transferred';
|
|
35
|
+
type BackgroundGlobals = {
|
|
36
|
+
NativeModules?: Record<string, unknown>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Gives the environment's background thread an `AngularLynxAppleSignIn`
|
|
40
|
+
* module, as the iOS apps `ng build --platform` makes with angular.json's
|
|
41
|
+
* `signInWithApple` have. It stands for a person who closes the sheet until
|
|
42
|
+
* a spec says how they sign in ({@link setAppleSignInResult}), and each
|
|
43
|
+
* user it signs in is `authorized` afterwards. `LynxAppleSignIn` reaches it
|
|
44
|
+
* through the background thread, as it reaches the shell's module, so specs
|
|
45
|
+
* see the runtime's own behavior.
|
|
46
|
+
*
|
|
47
|
+
* It runs each time the environment injects the background thread's
|
|
48
|
+
* globals: when it's created, and on the reset after each test, so each
|
|
49
|
+
* test starts with the module there, no sign-ins and no users.
|
|
50
|
+
*/
|
|
51
|
+
export declare const installAppleSignInModule: (threadGlobals: BackgroundGlobals) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Has the environment's main thread answer for the iOS shell's module as an
|
|
54
|
+
* app with `signInWithApple` does: `lynx.module('AngularLynxAppleSignIn')`'s
|
|
55
|
+
* `button` says the native `<apple-sign-in-button>` is there, so the runtime
|
|
56
|
+
* makes that element rather than drawing the button itself. It follows
|
|
57
|
+
* {@link setAppleSignInAvailable}, as the sheet does: a spec that takes the
|
|
58
|
+
* sheet away gets the drawn button, as Android and the web do. Other
|
|
59
|
+
* modules answer as they did.
|
|
60
|
+
*
|
|
61
|
+
* It runs each time the environment injects the main thread's globals,
|
|
62
|
+
* which give it a new `lynx`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const answerAppleSignInButtonOnMainThread: (threadGlobals: {
|
|
65
|
+
lynx?: {
|
|
66
|
+
module?: (name: string) => unknown;
|
|
67
|
+
};
|
|
68
|
+
}) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Has the person sign in with `result` from now on in this test: each
|
|
71
|
+
* `LynxAppleSignIn.signIn()` resolves with it, the email and name only when
|
|
72
|
+
* the sign-in asks for their scopes, and the user is `authorized` for
|
|
73
|
+
* `getCredentialState()` afterwards. Until a spec calls this or
|
|
74
|
+
* {@link setAppleSignInError}, the person closes the sheet, and `signIn()`
|
|
75
|
+
* rejects with `canceled`. The answer reaches the app through the
|
|
76
|
+
* background thread, as on a phone: wait for it with `waitForUpdate()`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* setAppleSignInResult({ user: 'u1', email: 'ada@example.com' });
|
|
81
|
+
* await render(SignInScreen);
|
|
82
|
+
* fireEvent.tap(screen.getByText('Sign in with Apple'));
|
|
83
|
+
* await waitForUpdate();
|
|
84
|
+
* expect(screen.getByText('Signed in as ada@example.com')).toBeInTheDocument();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const setAppleSignInResult: (result?: FakeAppleSignInResult) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Has the next sign-ins in this test end without a credential:
|
|
90
|
+
* `LynxAppleSignIn.signIn()` rejects with an `AppleSignInError` of `code`,
|
|
91
|
+
* `canceled` for a person who closes the sheet (the default) or `failed`.
|
|
92
|
+
*/
|
|
93
|
+
export declare const setAppleSignInError: (code: "canceled" | "failed", message?: string) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Takes the native sheet away for the rest of this test, or puts it back, so
|
|
96
|
+
* a spec can check what the app offers where there's none (Android, the
|
|
97
|
+
* web): `isAvailable()` is false, and `signIn()` and `getCredentialState()`
|
|
98
|
+
* reject with `unsupported`. An `<apple-sign-in-button>` made while it's
|
|
99
|
+
* away is the one the runtime draws, a view with the logo and the title as
|
|
100
|
+
* text, rather than iOS's. The sign-ins {@link appleSignInRequests} lists
|
|
101
|
+
* and the users' states stay as they were.
|
|
102
|
+
*/
|
|
103
|
+
export declare const setAppleSignInAvailable: (available: boolean) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Sets what `LynxAppleSignIn.getCredentialState(user)` resolves with, such
|
|
106
|
+
* as `revoked` for a person who stopped using their Apple ID with the app.
|
|
107
|
+
* A user nobody signed in is `notFound`.
|
|
108
|
+
*/
|
|
109
|
+
export declare const setAppleCredentialState: (user: string, state: FakeAppleCredentialState) => void;
|
|
110
|
+
/**
|
|
111
|
+
* The sign-ins the app opened in this test, with the scopes, nonce and
|
|
112
|
+
* state each asked for, oldest first.
|
|
113
|
+
*/
|
|
114
|
+
export declare const appleSignInRequests: () => readonly AppleSignInRequest[];
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=apple-sign-in.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apple-sign-in.d.ts","sourceRoot":"","sources":["../src/apple-sign-in.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QA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AAG,IAE5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,MAAM,EACZ,OAAO,wBAAwB,KAC9B,IAEF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAAO,SAAS,kBAAkB,EAIjE,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** What `LynxAppleSignIn` calls, named as the iOS shell names its module. */
|
|
2
|
+
const MODULE = 'AngularLynxAppleSignIn';
|
|
3
|
+
/**
|
|
4
|
+
* Gives the environment's background thread an `AngularLynxAppleSignIn`
|
|
5
|
+
* module, as the iOS apps `ng build --platform` makes with angular.json's
|
|
6
|
+
* `signInWithApple` have. It stands for a person who closes the sheet until
|
|
7
|
+
* a spec says how they sign in ({@link setAppleSignInResult}), and each
|
|
8
|
+
* user it signs in is `authorized` afterwards. `LynxAppleSignIn` reaches it
|
|
9
|
+
* through the background thread, as it reaches the shell's module, so specs
|
|
10
|
+
* see the runtime's own behavior.
|
|
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
|
|
14
|
+
* test starts with the module there, no sign-ins and no users.
|
|
15
|
+
*/
|
|
16
|
+
export const installAppleSignInModule = (threadGlobals) => {
|
|
17
|
+
/**
|
|
18
|
+
* Fails a call as the runtime's relay does for a host without the module,
|
|
19
|
+
* which `LynxAppleSignIn` reads as no native sheet.
|
|
20
|
+
*/
|
|
21
|
+
const refuse = (method) => {
|
|
22
|
+
throw new Error(`NativeModules: ${MODULE}.${method} is not available`);
|
|
23
|
+
};
|
|
24
|
+
const module = {
|
|
25
|
+
unavailable: false,
|
|
26
|
+
outcome: { error: 'canceled' },
|
|
27
|
+
requests: [],
|
|
28
|
+
states: new Map(),
|
|
29
|
+
available(done) {
|
|
30
|
+
if (this.unavailable)
|
|
31
|
+
refuse('available');
|
|
32
|
+
done({ available: true });
|
|
33
|
+
},
|
|
34
|
+
signIn(request, done) {
|
|
35
|
+
if (this.unavailable)
|
|
36
|
+
refuse('signIn');
|
|
37
|
+
this.requests.push(request);
|
|
38
|
+
const outcome = this.outcome;
|
|
39
|
+
if ('error' in outcome) {
|
|
40
|
+
done({
|
|
41
|
+
error: outcome.error,
|
|
42
|
+
...(outcome.message !== undefined && { message: outcome.message }),
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { result } = outcome;
|
|
47
|
+
const user = result.user ?? 'test-apple-user';
|
|
48
|
+
this.states.set(user, 'authorized');
|
|
49
|
+
// Apple shares the email and name only when the sign-in asks for them.
|
|
50
|
+
done({
|
|
51
|
+
user,
|
|
52
|
+
identityToken: result.identityToken ?? 'test-identity-token',
|
|
53
|
+
authorizationCode: result.authorizationCode ?? 'test-authorization-code',
|
|
54
|
+
realUserStatus: result.realUserStatus ?? 'likelyReal',
|
|
55
|
+
...(request.scopes.includes('email') &&
|
|
56
|
+
result.email !== undefined && { email: result.email }),
|
|
57
|
+
...(request.scopes.includes('fullName') &&
|
|
58
|
+
result.fullName !== undefined && { fullName: result.fullName }),
|
|
59
|
+
...(request.state !== undefined && { state: request.state }),
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
credentialState(user, done) {
|
|
63
|
+
if (this.unavailable)
|
|
64
|
+
refuse('credentialState');
|
|
65
|
+
done({ state: this.states.get(user) ?? 'notFound' });
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
threadGlobals.NativeModules = {
|
|
69
|
+
...threadGlobals.NativeModules,
|
|
70
|
+
[MODULE]: module,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Has the environment's main thread answer for the iOS shell's module as an
|
|
75
|
+
* app with `signInWithApple` does: `lynx.module('AngularLynxAppleSignIn')`'s
|
|
76
|
+
* `button` says the native `<apple-sign-in-button>` is there, so the runtime
|
|
77
|
+
* makes that element rather than drawing the button itself. It follows
|
|
78
|
+
* {@link setAppleSignInAvailable}, as the sheet does: a spec that takes the
|
|
79
|
+
* sheet away gets the drawn button, as Android and the web do. Other
|
|
80
|
+
* modules answer as they did.
|
|
81
|
+
*
|
|
82
|
+
* It runs each time the environment injects the main thread's globals,
|
|
83
|
+
* which give it a new `lynx`.
|
|
84
|
+
*/
|
|
85
|
+
export const answerAppleSignInButtonOnMainThread = (threadGlobals) => {
|
|
86
|
+
const { lynx } = threadGlobals;
|
|
87
|
+
if (!lynx)
|
|
88
|
+
return;
|
|
89
|
+
const otherModule = lynx.module;
|
|
90
|
+
lynx.module = (name) => {
|
|
91
|
+
if (name !== MODULE)
|
|
92
|
+
return otherModule?.(name);
|
|
93
|
+
return {
|
|
94
|
+
invoke: (method) => {
|
|
95
|
+
if (method !== 'button')
|
|
96
|
+
return undefined;
|
|
97
|
+
const module = globalThis.lynxTestingEnv?.backgroundThread
|
|
98
|
+
.globalThis.NativeModules?.[MODULE];
|
|
99
|
+
return module && !module.unavailable ? { available: true } : undefined;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const backgroundGlobals = (name) => {
|
|
105
|
+
// Read through the environment rather than kept here: under `ng test`, the
|
|
106
|
+
// setup file and the specs can load different copies of this module.
|
|
107
|
+
const globals = globalThis.lynxTestingEnv?.backgroundThread
|
|
108
|
+
.globalThis;
|
|
109
|
+
if (!globals) {
|
|
110
|
+
throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
|
|
111
|
+
}
|
|
112
|
+
return globals;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The fake module. The setup installs it on every reset, and nothing takes
|
|
116
|
+
* it away.
|
|
117
|
+
*/
|
|
118
|
+
const fakeModule = (name) => backgroundGlobals(name).NativeModules[MODULE];
|
|
119
|
+
/**
|
|
120
|
+
* Has the person sign in with `result` from now on in this test: each
|
|
121
|
+
* `LynxAppleSignIn.signIn()` resolves with it, the email and name only when
|
|
122
|
+
* the sign-in asks for their scopes, and the user is `authorized` for
|
|
123
|
+
* `getCredentialState()` afterwards. Until a spec calls this or
|
|
124
|
+
* {@link setAppleSignInError}, the person closes the sheet, and `signIn()`
|
|
125
|
+
* rejects with `canceled`. The answer reaches the app through the
|
|
126
|
+
* background thread, as on a phone: wait for it with `waitForUpdate()`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* setAppleSignInResult({ user: 'u1', email: 'ada@example.com' });
|
|
131
|
+
* await render(SignInScreen);
|
|
132
|
+
* fireEvent.tap(screen.getByText('Sign in with Apple'));
|
|
133
|
+
* await waitForUpdate();
|
|
134
|
+
* expect(screen.getByText('Signed in as ada@example.com')).toBeInTheDocument();
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const setAppleSignInResult = (result = {}) => {
|
|
138
|
+
fakeModule('setAppleSignInResult').outcome = { result };
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Has the next sign-ins in this test end without a credential:
|
|
142
|
+
* `LynxAppleSignIn.signIn()` rejects with an `AppleSignInError` of `code`,
|
|
143
|
+
* `canceled` for a person who closes the sheet (the default) or `failed`.
|
|
144
|
+
*/
|
|
145
|
+
export const setAppleSignInError = (code, message) => {
|
|
146
|
+
fakeModule('setAppleSignInError').outcome = {
|
|
147
|
+
error: code,
|
|
148
|
+
...(message !== undefined && { message }),
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Takes the native sheet away for the rest of this test, or puts it back, so
|
|
153
|
+
* a spec can check what the app offers where there's none (Android, the
|
|
154
|
+
* web): `isAvailable()` is false, and `signIn()` and `getCredentialState()`
|
|
155
|
+
* reject with `unsupported`. An `<apple-sign-in-button>` made while it's
|
|
156
|
+
* away is the one the runtime draws, a view with the logo and the title as
|
|
157
|
+
* text, rather than iOS's. The sign-ins {@link appleSignInRequests} lists
|
|
158
|
+
* and the users' states stay as they were.
|
|
159
|
+
*/
|
|
160
|
+
export const setAppleSignInAvailable = (available) => {
|
|
161
|
+
fakeModule('setAppleSignInAvailable').unavailable = !available;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Sets what `LynxAppleSignIn.getCredentialState(user)` resolves with, such
|
|
165
|
+
* as `revoked` for a person who stopped using their Apple ID with the app.
|
|
166
|
+
* A user nobody signed in is `notFound`.
|
|
167
|
+
*/
|
|
168
|
+
export const setAppleCredentialState = (user, state) => {
|
|
169
|
+
fakeModule('setAppleCredentialState').states.set(user, state);
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* The sign-ins the app opened in this test, with the scopes, nonce and
|
|
173
|
+
* state each asked for, oldest first.
|
|
174
|
+
*/
|
|
175
|
+
export const appleSignInRequests = () => {
|
|
176
|
+
const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
|
|
177
|
+
.NativeModules?.[MODULE];
|
|
178
|
+
return module ? [...module.requests] : [];
|
|
179
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { MicrophonePermission } from '@blotch/angular-lynx';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the fake phone lets the app use its microphone, as
|
|
4
|
+
* `@blotch/angular-lynx`'s `MicrophonePermission` names it.
|
|
5
|
+
*/
|
|
6
|
+
export type FakeMicrophonePermission = MicrophonePermission;
|
|
7
|
+
/** What the fake phone's recordings hold, which {@link setRecordedAudio} sets. */
|
|
8
|
+
export type FakeRecordedAudio = {
|
|
9
|
+
/** The clip's bytes, which its `blob()` resolves with. */
|
|
10
|
+
readonly bytes?: Uint8Array;
|
|
11
|
+
/** Its type. `audio/mp4` when left out, as the shells record. */
|
|
12
|
+
readonly mimeType?: string;
|
|
13
|
+
/**
|
|
14
|
+
* How long it plays, in milliseconds. When left out, how long it recorded
|
|
15
|
+
* by the clock, which `vi.useFakeTimers()` moves.
|
|
16
|
+
*/
|
|
17
|
+
readonly durationMs?: number;
|
|
18
|
+
};
|
|
19
|
+
/** The recording the app has open, as {@link audioRecording} reports it. */
|
|
20
|
+
export type FakeAudioRecordingInfo = {
|
|
21
|
+
/** `paused` after the app's `pause()` or {@link interruptAudioRecording}. */
|
|
22
|
+
readonly state: 'recording' | 'paused';
|
|
23
|
+
/** The `maxDuration` the app started it with, in milliseconds. */
|
|
24
|
+
readonly maxDuration?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Gives the environment's background thread an `AngularLynxAudioRecorder`
|
|
28
|
+
* module, as the apps `ng build --platform` makes with
|
|
29
|
+
* `permissions.microphone` have. Its person hasn't been asked yet: the first
|
|
30
|
+
* start asks, and they allow it, unless {@link setMicrophonePermission} says
|
|
31
|
+
* otherwise. Each recording holds a few bytes, or what
|
|
32
|
+
* {@link setRecordedAudio} says. `LynxAudioRecorder` reaches it through the
|
|
33
|
+
* background thread, as it reaches the shells' module, so specs see the
|
|
34
|
+
* runtime's own behavior.
|
|
35
|
+
*
|
|
36
|
+
* It runs each time the environment injects the background thread's globals:
|
|
37
|
+
* when it's created, and on the reset after each test, so each test starts
|
|
38
|
+
* afresh. Only `NativeModules.AngularLynxAudioRecorder` is added.
|
|
39
|
+
*/
|
|
40
|
+
export declare const installAudioRecorderModule: (threadGlobals: {
|
|
41
|
+
NativeModules?: Record<string, unknown>;
|
|
42
|
+
}) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets whether the fake phone lets the app use its microphone: what
|
|
45
|
+
* `LynxAudioRecorder.permission` reads, and what `start()` finds. `denied`
|
|
46
|
+
* has `start()` reject with `denied`, and `unsupported` with `unavailable`,
|
|
47
|
+
* as on a phone without the module. `undetermined`, where each test starts,
|
|
48
|
+
* has the next start ask and the person allow it.
|
|
49
|
+
*
|
|
50
|
+
* Set it before the component that injects `LynxAudioRecorder` renders: the
|
|
51
|
+
* service reads the permission when it's created, and each time the app
|
|
52
|
+
* comes back to the foreground.
|
|
53
|
+
*/
|
|
54
|
+
export declare const setMicrophonePermission: (permission: FakeMicrophonePermission) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Sets what the fake phone's recordings hold from now on: the bytes a
|
|
57
|
+
* clip's `blob()` resolves with, its type and its length.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* setRecordedAudio({ bytes: voiceNote, durationMs: 4200 });
|
|
62
|
+
* await render(VoiceNote);
|
|
63
|
+
* fireEvent.tap(screen.getByText('Record'));
|
|
64
|
+
* await waitForUpdate();
|
|
65
|
+
* fireEvent.tap(screen.getByText('Stop'));
|
|
66
|
+
* expect(await screen.findByText('0:04')).toBeInTheDocument();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const setRecordedAudio: (audio: FakeRecordedAudio) => void;
|
|
70
|
+
/**
|
|
71
|
+
* The recording the app has open, or undefined while none is, such as
|
|
72
|
+
* before `start()` and after `stop()`.
|
|
73
|
+
*/
|
|
74
|
+
export declare const audioRecording: () => FakeAudioRecordingInfo | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Sends the open recording's level (0..1) and its length so far by the
|
|
77
|
+
* clock, as the shells do about ten times a second. Once it's as long as its
|
|
78
|
+
* `maxDuration`, it ends instead, as the shells end it, and the app's
|
|
79
|
+
* `stop()` resolves with the clip. Does nothing while none records.
|
|
80
|
+
*/
|
|
81
|
+
export declare const emitAudioLevel: (level: number) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Pauses the open recording as the system does for a phone call or the app
|
|
84
|
+
* going to the background: the app's recording turns `paused`, and its
|
|
85
|
+
* `resume()` carries on. Does nothing while none records.
|
|
86
|
+
*/
|
|
87
|
+
export declare const interruptAudioRecording: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Ends the open recording with an error, as the shells do when the
|
|
90
|
+
* microphone fails: the app's recording turns `stopped`, its `error` holds
|
|
91
|
+
* an `AudioRecorderError` with code `failed` and `message`, and its `stop()`
|
|
92
|
+
* rejects with it. Does nothing while none is open.
|
|
93
|
+
*/
|
|
94
|
+
export declare const failAudioRecording: (message?: string) => void;
|
|
95
|
+
//# s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