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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/app-state.d.ts +34 -0
  2. package/dist/app-state.d.ts.map +1 -0
  3. package/dist/app-state.js +57 -0
  4. package/dist/apple-sign-in.d.ts +116 -0
  5. package/dist/apple-sign-in.d.ts.map +1 -0
  6. package/dist/apple-sign-in.js +179 -0
  7. package/dist/back-button.d.ts +43 -0
  8. package/dist/back-button.d.ts.map +1 -0
  9. package/dist/back-button.js +77 -0
  10. package/dist/barcode-scanner.d.ts +59 -0
  11. package/dist/barcode-scanner.d.ts.map +1 -0
  12. package/dist/barcode-scanner.js +100 -0
  13. package/dist/biometrics.d.ts +79 -0
  14. package/dist/biometrics.d.ts.map +1 -0
  15. package/dist/biometrics.js +151 -0
  16. package/dist/bluetooth.d.ts +121 -0
  17. package/dist/bluetooth.d.ts.map +1 -0
  18. package/dist/bluetooth.js +369 -0
  19. package/dist/calendar.d.ts +68 -0
  20. package/dist/calendar.d.ts.map +1 -0
  21. package/dist/calendar.js +120 -0
  22. package/dist/file-picker.d.ts +76 -0
  23. package/dist/file-picker.d.ts.map +1 -0
  24. package/dist/file-picker.js +125 -0
  25. package/dist/index.d.ts +28 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +15 -0
  28. package/dist/motion.d.ts +90 -0
  29. package/dist/motion.d.ts.map +1 -0
  30. package/dist/motion.js +169 -0
  31. package/dist/nfc.d.ts +85 -0
  32. package/dist/nfc.d.ts.map +1 -0
  33. package/dist/nfc.js +253 -0
  34. package/dist/photo-library.d.ts +58 -0
  35. package/dist/photo-library.d.ts.map +1 -0
  36. package/dist/photo-library.js +91 -0
  37. package/dist/render.d.ts.map +1 -1
  38. package/dist/render.js +19 -1
  39. package/dist/setup.js +59 -0
  40. package/dist/share-target.d.ts +56 -0
  41. package/dist/share-target.d.ts.map +1 -0
  42. package/dist/share-target.js +92 -0
  43. package/dist/store-review.d.ts +30 -0
  44. package/dist/store-review.d.ts.map +1 -0
  45. package/dist/store-review.js +49 -0
  46. package/dist/tracking.d.ts +60 -0
  47. package/dist/tracking.d.ts.map +1 -0
  48. package/dist/tracking.js +94 -0
  49. package/dist/wifi.d.ts +77 -0
  50. package/dist/wifi.d.ts.map +1 -0
  51. package/dist/wifi.js +148 -0
  52. package/package.json +3 -3
@@ -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":"AAAA;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;AAkB5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,KAAG,IA+B7C,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The global prop the shells send the state in (see the runtime's
3
+ * app-state.ts).
4
+ */
5
+ const APP_STATE_PROP = 'appState';
6
+ /**
7
+ * Sends the app to the background, or brings it back, as the person does by
8
+ * leaving the app and coming back to it, so a spec can check what the app
9
+ * does on its return. `LynxAppState.state()` becomes `state`, and
10
+ * `LynxAppState.active()` is `true` only for `'active'`.
11
+ *
12
+ * It reaches the app as it does on a phone, as a change to the host's global
13
+ * props: change detection runs on its own, so wait for it with
14
+ * `waitForUpdate()`. Wait between two states too: an `effect()` runs once
15
+ * for both otherwise, and never sees the app leave. Each test starts `active`.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * await render(Schedule);
20
+ * setAppState('background');
21
+ * await waitForUpdate();
22
+ * vi.setSystemTime(new Date('2026-01-02T09:00'));
23
+ * setAppState('active');
24
+ * await waitForUpdate();
25
+ * expect(screen.getByText('Today: 2 January')).toBeInTheDocument();
26
+ * ```
27
+ *
28
+ * @param state - `'background'` when the app leaves the screen, `'inactive'`
29
+ * while it's on screen but not taking touches (Control Center pulled over
30
+ * it, or a call coming in), and `'active'` when it's back.
31
+ */
32
+ export const setAppState = (state) => {
33
+ // Read through the environment rather than kept here: under `ng test`, the
34
+ // setup file and the specs can load different copies of this module.
35
+ const env = globalThis.lynxTestingEnv;
36
+ // The runtime's callback for the engine, which it puts on the global as it
37
+ // loads: specs run on the main thread, whose globals the environment copies
38
+ // there.
39
+ const update = globalThis.updateGlobalProps;
40
+ if (!env || typeof update !== 'function') {
41
+ throw new Error("setAppState() needs the testing library's environment, which its setup file installs, and the runtime, which render() loads.");
42
+ }
43
+ // The background thread's props, as the engine keeps both threads'. The
44
+ // environment gives each thread a `lynx`.
45
+ const background = env.backgroundThread.globalThis.lynx;
46
+ background.__globalProps = {
47
+ ...background.__globalProps,
48
+ [APP_STATE_PROP]: state,
49
+ };
50
+ // What the engine calls on the main thread, where the app runs, when the
51
+ // host sends new global props: the runtime merges them and LynxGlobalData
52
+ // hears them.
53
+ update({
54
+ ...env.mainThread.globalThis.lynx.__globalProps,
55
+ [APP_STATE_PROP]: state,
56
+ });
57
+ };
@@ -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;QAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,uCAAuC;IACvC,QAAQ,CAAC,cAAc,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,aAAa,CAAC;CACpE,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,wBAAwB,GAChC,YAAY,GACZ,SAAS,GACT,UAAU,GACV,aAAa,CAAC;AAsBlB,KAAK,iBAAiB,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,iBAAiB,KAC/B,IAsDF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mCAAmC,GAAI,eAAe;IACjE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;KAAE,CAAC;CAC/C,KAAG,IAiBH,CAAC;AAwBF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAQ,qBAA0B,KACjC,IAEF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,UAAU,GAAG,QAAQ,EAC3B,UAAU,MAAM,KACf,IAKF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,GAAI,WAAW,OAAO,KAAG,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,43 @@
1
+ /**
2
+ * Gives the environment's background thread an `AngularLynxShell` module with
3
+ * the Android shell's `setBackHandlerEnabled()`, so that {@link
4
+ * pressBackButton} knows whether the app takes back, as Android does.
5
+ * `LynxBackButton` reaches it through the background thread, as it reaches
6
+ * the shell's module, so specs see the runtime's own behavior.
7
+ *
8
+ * It runs each time the environment injects the background thread's globals:
9
+ * when it's created, and on the reset after each test, so each test starts
10
+ * with the handler off, as an app does. Only `NativeModules.AngularLynxShell`
11
+ * is added: every other module stays as it was.
12
+ */
13
+ export declare const installShellModule: (threadGlobals: {
14
+ NativeModules?: Record<string, unknown>;
15
+ }) => void;
16
+ /**
17
+ * Presses Android's back button, so a spec can check what the app does with
18
+ * it: close what's open on top (a handler registered with
19
+ * `LynxBackButton.on()`), or go back a screen through the router.
20
+ *
21
+ * As on Android, the press reaches the app only while the app has said it
22
+ * takes back. Otherwise Android would leave the app, and nothing reaches it:
23
+ * the call returns `false` then. The press reaches the app as it does on a
24
+ * phone, through the background thread: wait for it with `waitForUpdate()`.
25
+ *
26
+ * An `<overlay>` takes back before the app does, on a phone: fire its
27
+ * `requestclose` event for that instead.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * await render(Search);
32
+ * fireEvent.tap(screen.getByText('Search'));
33
+ * await waitForUpdate();
34
+ * expect(pressBackButton()).toBe(true);
35
+ * await waitForUpdate();
36
+ * expect(screen.queryByText('Results')).toBeNull();
37
+ * ```
38
+ *
39
+ * @returns Whether the app took the press: `false` when Android would have
40
+ * left the app.
41
+ */
42
+ export declare const pressBackButton: () => boolean;
43
+ //# sourceMappingURL=back-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"back-button.d.ts","sourceRoot":"","sources":["../src/back-button.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,eAAe;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAWH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,QAAO,OA2BlC,CAAC"}
@@ -0,0 +1,77 @@
1
+ /** What `LynxBackButton` calls and hears, named as the Android shell names them. */
2
+ const MODULE = 'AngularLynxShell';
3
+ const EVENT = 'angularLynxBack';
4
+ /**
5
+ * Gives the environment's background thread an `AngularLynxShell` module with
6
+ * the Android shell's `setBackHandlerEnabled()`, so that {@link
7
+ * pressBackButton} knows whether the app takes back, as Android does.
8
+ * `LynxBackButton` reaches it through the background thread, as it reaches
9
+ * the shell's 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 each test starts
13
+ * with the handler off, as an app does. Only `NativeModules.AngularLynxShell`
14
+ * is added: every other module stays as it was.
15
+ */
16
+ export const installShellModule = (threadGlobals) => {
17
+ const module = {
18
+ enabled: false,
19
+ setBackHandlerEnabled(enabled) {
20
+ module.enabled = enabled;
21
+ },
22
+ };
23
+ threadGlobals.NativeModules = {
24
+ ...threadGlobals.NativeModules,
25
+ [MODULE]: module,
26
+ };
27
+ };
28
+ /**
29
+ * Presses Android's back button, so a spec can check what the app does with
30
+ * it: close what's open on top (a handler registered with
31
+ * `LynxBackButton.on()`), or go back a screen through the router.
32
+ *
33
+ * As on Android, the press reaches the app only while the app has said it
34
+ * takes back. Otherwise Android would leave the app, and nothing reaches it:
35
+ * the call returns `false` then. The press reaches the app as it does on a
36
+ * phone, through the background thread: wait for it with `waitForUpdate()`.
37
+ *
38
+ * An `<overlay>` takes back before the app does, on a phone: fire its
39
+ * `requestclose` event for that instead.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * await render(Search);
44
+ * fireEvent.tap(screen.getByText('Search'));
45
+ * await waitForUpdate();
46
+ * expect(pressBackButton()).toBe(true);
47
+ * await waitForUpdate();
48
+ * expect(screen.queryByText('Results')).toBeNull();
49
+ * ```
50
+ *
51
+ * @returns Whether the app took the press: `false` when Android would have
52
+ * left the app.
53
+ */
54
+ export const pressBackButton = () => {
55
+ // Read through the environment rather than kept here: under `ng test`, the
56
+ // setup file and the specs can load different copies of this module.
57
+ const env = globalThis.lynxTestingEnv;
58
+ const background = env?.backgroundThread.globalThis;
59
+ const module = background?.NativeModules?.[MODULE];
60
+ if (!env || !module) {
61
+ throw new Error("pressBackButton() needs the testing library's environment, which its setup file installs.");
62
+ }
63
+ if (!module.enabled)
64
+ return false;
65
+ // What the shell sends while its handler is enabled. A global event
66
+ // arrives on the background thread, and the listener there calls the
67
+ // app's on the main thread through that thread's `lynx`, so the event is
68
+ // sent from it. Specs run on the main thread, which comes back afterwards.
69
+ env.switchToBackgroundThread();
70
+ try {
71
+ background?.lynx?.getJSModule?.('GlobalEventEmitter')?.emit(EVENT);
72
+ }
73
+ finally {
74
+ env.switchToMainThread();
75
+ }
76
+ return true;
77
+ };
@@ -0,0 +1,59 @@
1
+ /** A code the fake scanner reads, as `LynxBarcodeScanner.scan()` resolves. */
2
+ export type QueuedBarcodeScan = {
3
+ /** The kind of code, one of `@blotch/angular-lynx`'s `BarcodeFormat`s. */
4
+ readonly format: string;
5
+ /** What the code holds. */
6
+ readonly value: string;
7
+ };
8
+ /** Why a scan read no code, as `BarcodeScannerError`'s `code` names it. */
9
+ export type BarcodeScanFailure = 'unavailable' | 'denied' | 'failed';
10
+ /**
11
+ * Gives the environment's background thread an `AngularLynxBarcodeScanner`
12
+ * module, as the apps `ng build --platform` makes with `permissions.camera`
13
+ * have. There's no camera to point in a spec, so a scan stays open until
14
+ * {@link queueBarcodeScan}, {@link cancelBarcodeScan} or
15
+ * {@link failBarcodeScan} answers it, or ends at once with what one of them
16
+ * queued before it opened. `LynxBarcodeScanner` reaches it through the
17
+ * background thread, as it reaches the shells' module, so specs see the
18
+ * runtime's own behavior.
19
+ *
20
+ * It runs each time the environment injects the background thread's globals:
21
+ * when it's created, and on the reset after each test, so each test starts
22
+ * with no scan open and nothing queued. Only
23
+ * `NativeModules.AngularLynxBarcodeScanner` is added: every other module
24
+ * stays as it was.
25
+ */
26
+ export declare const installBarcodeScannerModule: (threadGlobals: {
27
+ NativeModules?: Record<string, unknown>;
28
+ }) => void;
29
+ /**
30
+ * Has the scanner read `scan`, as if the person pointed the camera at it: the
31
+ * open `LynxBarcodeScanner.scan()` resolves with it, or, when none is open,
32
+ * the next one does as soon as it's called. Each call answers one scan, in
33
+ * order. The answer reaches the app through the background thread, as on a
34
+ * phone: wait for it with `waitForUpdate()`.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * await render(CheckIn);
39
+ * queueBarcodeScan({ format: 'qr', value: 'TICKET-42' });
40
+ * fireEvent.tap(screen.getByText('Scan ticket'));
41
+ * await waitForUpdate();
42
+ * expect(screen.getByText('Welcome, ticket 42')).toBeInTheDocument();
43
+ * ```
44
+ */
45
+ export declare const queueBarcodeScan: (scan: QueuedBarcodeScan) => void;
46
+ /**
47
+ * Closes the scanner without a code, as the person does with Cancel: the open
48
+ * `LynxBarcodeScanner.scan()`, or the next one, rejects with a
49
+ * `BarcodeScannerError` whose code is `canceled`.
50
+ */
51
+ export declare const cancelBarcodeScan: () => void;
52
+ /**
53
+ * Ends the open `LynxBarcodeScanner.scan()`, or the next one, with a
54
+ * `BarcodeScannerError` of `code`: `denied` for a person who doesn't let the
55
+ * app use the camera, `unavailable` for a phone without a scanner, or
56
+ * `failed`.
57
+ */
58
+ export declare const failBarcodeScan: (code: BarcodeScanFailure, message?: string) => void;
59
+ //# sourceMappingURL=barcode-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barcode-scanner.d.ts","sourceRoot":"","sources":["../src/barcode-scanner.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AA0BrE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,2BAA2B,GAAI,eAAe;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAqBH,CAAC;AAgCF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,iBAAiB,KAAG,IACa,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAO,IAIjC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,kBAAkB,EACxB,UAAU,MAAM,KACf,IAIC,CAAC"}