@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,68 @@
|
|
|
1
|
+
/** An event the app opened the editor with, as `LynxCalendar` was given it. */
|
|
2
|
+
export type CalendarSheetEvent = {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly start: Date;
|
|
5
|
+
readonly end: Date;
|
|
6
|
+
readonly allDay: boolean;
|
|
7
|
+
readonly location?: string;
|
|
8
|
+
readonly notes?: string;
|
|
9
|
+
};
|
|
10
|
+
/** How the editor closes, as `LynxCalendar.addEvent()` resolves. */
|
|
11
|
+
export type CalendarSheetAnswer = 'saved' | 'canceled' | 'unknown';
|
|
12
|
+
/** Why the editor didn't open, as `CalendarError`'s `code` names it. */
|
|
13
|
+
export type CalendarSheetFailure = 'unavailable' | 'failed';
|
|
14
|
+
/**
|
|
15
|
+
* Gives the environment's background thread an `AngularLynxCalendar` module,
|
|
16
|
+
* as the apps `ng build --platform` makes with angular.json's `calendar`
|
|
17
|
+
* have. It keeps each event the app opens the editor with, for
|
|
18
|
+
* {@link calendarEvents}, and leaves the editor open until
|
|
19
|
+
* {@link answerCalendarSheet} or {@link failCalendarSheet} closes it, or
|
|
20
|
+
* closes it at once with what one of them queued before it opened.
|
|
21
|
+
* `LynxCalendar` 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 with no events, no editor open and nothing queued.
|
|
27
|
+
*/
|
|
28
|
+
export declare const installCalendarModule: (threadGlobals: {
|
|
29
|
+
NativeModules?: Record<string, unknown>;
|
|
30
|
+
}) => void;
|
|
31
|
+
/**
|
|
32
|
+
* The events the app has opened the system's event editor with, through
|
|
33
|
+
* `LynxCalendar.addEvent()`, in this test, oldest first. Each test starts
|
|
34
|
+
* with none.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* fireEvent.tap(screen.getByText('Add to calendar'));
|
|
39
|
+
* await waitForUpdate();
|
|
40
|
+
* expect(calendarEvents()).toEqual([
|
|
41
|
+
* expect.objectContaining({ title: 'Table for 2' }),
|
|
42
|
+
* ]);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const calendarEvents: () => readonly CalendarSheetEvent[];
|
|
46
|
+
/**
|
|
47
|
+
* Closes the event editor as the person would: the open
|
|
48
|
+
* `LynxCalendar.addEvent()` resolves with `result` (`saved` by default), or,
|
|
49
|
+
* when none is open, the next one does as soon as it's called. Each call
|
|
50
|
+
* answers one editor, in order. The answer reaches the app through the
|
|
51
|
+
* background thread, as on a phone: wait for it with `waitForUpdate()`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* fireEvent.tap(screen.getByText('Add to calendar'));
|
|
56
|
+
* answerCalendarSheet('saved');
|
|
57
|
+
* await waitForUpdate();
|
|
58
|
+
* expect(screen.getByText('Added to your calendar')).toBeInTheDocument();
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const answerCalendarSheet: (result?: CalendarSheetAnswer) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Ends the open `LynxCalendar.addEvent()`, or the next one, with a
|
|
64
|
+
* `CalendarError` of `code`: `unavailable` for a phone without an editor
|
|
65
|
+
* (before iOS 17, or Android without a calendar app), or `failed`.
|
|
66
|
+
*/
|
|
67
|
+
export declare const failCalendarSheet: (code: CalendarSheetFailure, message?: string) => void;
|
|
68
|
+
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAGA,+EAA+E;AAC/E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;AAEnE,wEAAwE;AACxE,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,QAAQ,CAAC;AAsC5D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,GAAI,eAAe;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IA8BH,CAAC;AA0CF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,QAAO,SAAS,kBAAkB,EAE5D,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAQ,mBAA6B,KACpC,IAAiD,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,oBAAoB,EAC1B,UAAU,MAAM,KACf,IAIC,CAAC"}
|
package/dist/calendar.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** What `LynxCalendar` calls, named as the shells name their module. */
|
|
2
|
+
const MODULE = 'AngularLynxCalendar';
|
|
3
|
+
/**
|
|
4
|
+
* Gives the environment's background thread an `AngularLynxCalendar` module,
|
|
5
|
+
* as the apps `ng build --platform` makes with angular.json's `calendar`
|
|
6
|
+
* have. It keeps each event the app opens the editor with, for
|
|
7
|
+
* {@link calendarEvents}, and leaves the editor open until
|
|
8
|
+
* {@link answerCalendarSheet} or {@link failCalendarSheet} closes it, or
|
|
9
|
+
* closes it at once with what one of them queued before it opened.
|
|
10
|
+
* `LynxCalendar` reaches it through the background thread, as it reaches the
|
|
11
|
+
* shells' module, so specs see the runtime's own behavior.
|
|
12
|
+
*
|
|
13
|
+
* It runs each time the environment injects the background thread's
|
|
14
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
15
|
+
* starts with no events, no editor open and nothing queued.
|
|
16
|
+
*/
|
|
17
|
+
export const installCalendarModule = (threadGlobals) => {
|
|
18
|
+
const module = {
|
|
19
|
+
events: [],
|
|
20
|
+
queued: [],
|
|
21
|
+
open: undefined,
|
|
22
|
+
addEvent(event, done) {
|
|
23
|
+
if (this.open) {
|
|
24
|
+
done({ error: 'failed', message: 'The event editor is already open.' });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.events.push({
|
|
28
|
+
title: event.title,
|
|
29
|
+
start: new Date(event.start),
|
|
30
|
+
end: new Date(event.end),
|
|
31
|
+
allDay: event.allDay,
|
|
32
|
+
...(event.location !== undefined && { location: event.location }),
|
|
33
|
+
...(event.notes !== undefined && { notes: event.notes }),
|
|
34
|
+
});
|
|
35
|
+
const answer = this.queued.shift();
|
|
36
|
+
if (answer) {
|
|
37
|
+
done(answer);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.open = done;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
threadGlobals.NativeModules = {
|
|
44
|
+
...threadGlobals.NativeModules,
|
|
45
|
+
[MODULE]: module,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The fake module, read through the environment rather than kept here:
|
|
50
|
+
* under `ng test`, the setup file and the specs can load different copies of
|
|
51
|
+
* this file.
|
|
52
|
+
*/
|
|
53
|
+
const fakeModule = (name) => {
|
|
54
|
+
const env = globalThis.lynxTestingEnv;
|
|
55
|
+
const module = env?.backgroundThread.globalThis.NativeModules?.[MODULE];
|
|
56
|
+
if (!env || !module) {
|
|
57
|
+
throw new Error(`${name}() needs the testing library's environment, which its setup file installs.`);
|
|
58
|
+
}
|
|
59
|
+
return { env, module };
|
|
60
|
+
};
|
|
61
|
+
const answer = (name, result) => {
|
|
62
|
+
const { env, module } = fakeModule(name);
|
|
63
|
+
const open = module.open;
|
|
64
|
+
if (!open) {
|
|
65
|
+
module.queued.push(result);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
module.open = undefined;
|
|
69
|
+
// The shells call back on the background thread, which relays the answer
|
|
70
|
+
// to the main thread, where specs run: it comes back afterwards.
|
|
71
|
+
env.switchToBackgroundThread();
|
|
72
|
+
try {
|
|
73
|
+
open(result);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
env.switchToMainThread();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The events the app has opened the system's event editor with, through
|
|
81
|
+
* `LynxCalendar.addEvent()`, in this test, oldest first. Each test starts
|
|
82
|
+
* with none.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* fireEvent.tap(screen.getByText('Add to calendar'));
|
|
87
|
+
* await waitForUpdate();
|
|
88
|
+
* expect(calendarEvents()).toEqual([
|
|
89
|
+
* expect.objectContaining({ title: 'Table for 2' }),
|
|
90
|
+
* ]);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export const calendarEvents = () => [
|
|
94
|
+
...fakeModule('calendarEvents').module.events,
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* Closes the event editor as the person would: the open
|
|
98
|
+
* `LynxCalendar.addEvent()` resolves with `result` (`saved` by default), or,
|
|
99
|
+
* when none is open, the next one does as soon as it's called. Each call
|
|
100
|
+
* answers one editor, in order. The answer reaches the app through the
|
|
101
|
+
* background thread, as on a phone: wait for it with `waitForUpdate()`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* fireEvent.tap(screen.getByText('Add to calendar'));
|
|
106
|
+
* answerCalendarSheet('saved');
|
|
107
|
+
* await waitForUpdate();
|
|
108
|
+
* expect(screen.getByText('Added to your calendar')).toBeInTheDocument();
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export const answerCalendarSheet = (result = 'saved') => answer('answerCalendarSheet', { result });
|
|
112
|
+
/**
|
|
113
|
+
* Ends the open `LynxCalendar.addEvent()`, or the next one, with a
|
|
114
|
+
* `CalendarError` of `code`: `unavailable` for a phone without an editor
|
|
115
|
+
* (before iOS 17, or Android without a calendar app), or `failed`.
|
|
116
|
+
*/
|
|
117
|
+
export const failCalendarSheet = (code, message) => answer('failCalendarSheet', {
|
|
118
|
+
error: code,
|
|
119
|
+
...(message !== undefined && { message }),
|
|
120
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** A file {@link setPickedFiles} has the person pick. */
|
|
2
|
+
export type FakePickedFile = {
|
|
3
|
+
/** Its name, such as `receipt.pdf`. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/**
|
|
6
|
+
* Its MIME type, such as `application/pdf`. `application/octet-stream`
|
|
7
|
+
* when it's left out, as a phone answers for a type it doesn't know.
|
|
8
|
+
*/
|
|
9
|
+
readonly type?: string;
|
|
10
|
+
/** Its bytes, or text, which is stored as UTF-8. */
|
|
11
|
+
readonly content: string | Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
/** A file the app saved, as {@link savedFiles} lists it. */
|
|
14
|
+
export type SavedFile = {
|
|
15
|
+
/** The name it was offered under. */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** Its MIME type: the Blob's `type`, or `application/octet-stream`. */
|
|
18
|
+
readonly type: string;
|
|
19
|
+
/** Its bytes. */
|
|
20
|
+
readonly bytes: Uint8Array;
|
|
21
|
+
/** Its bytes read as UTF-8, for a text file such as a CSV. */
|
|
22
|
+
readonly text: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Gives the environment's background thread an `AngularLynxFilePicker`
|
|
26
|
+
* module, as the apps `ng build --platform` makes with angular.json's
|
|
27
|
+
* `filePicker` have. It stands for a person who closes the picker until a
|
|
28
|
+
* spec says what they pick ({@link setPickedFiles}), and who saves every
|
|
29
|
+
* file the app offers ({@link savedFiles}) unless a spec has them close the
|
|
30
|
+
* screen ({@link setFilePickerCanceled}). The runtime reaches it through the
|
|
31
|
+
* background thread, as it reaches the shells' module, so specs see the
|
|
32
|
+
* runtime's own behavior, its size limit included.
|
|
33
|
+
*
|
|
34
|
+
* It runs each time the environment injects the background thread's
|
|
35
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
36
|
+
* starts with nothing to pick and nothing saved.
|
|
37
|
+
*/
|
|
38
|
+
export declare const installFilePickerModule: (threadGlobals: {
|
|
39
|
+
NativeModules?: Record<string, unknown>;
|
|
40
|
+
}) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Has the person pick `files` each time the app opens `LynxFilePicker`'s
|
|
43
|
+
* picker in this test, so `pick()` resolves with them. Until a spec calls
|
|
44
|
+
* it, the person closes the picker, and `pick()` resolves with `[]`. Files
|
|
45
|
+
* over the runtime's 20 MiB limit, together, reject with `too-large`, as on
|
|
46
|
+
* a phone.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* setPickedFiles([{ name: 'receipt.pdf', type: 'application/pdf', content: pdfBytes }]);
|
|
51
|
+
* fireEvent.tap(screen.getByText('Attach receipt'));
|
|
52
|
+
* await waitForUpdate();
|
|
53
|
+
* expect(screen.getByText('receipt.pdf')).toBeInTheDocument();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const setPickedFiles: (files: readonly FakePickedFile[]) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Has the person close `LynxFilePicker`'s picker and save screen for the
|
|
59
|
+
* rest of this test: `pick()` resolves with `[]`, and `save()` with false.
|
|
60
|
+
* {@link setPickedFiles} undoes it.
|
|
61
|
+
*/
|
|
62
|
+
export declare const setFilePickerCanceled: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* The files the app saved with `LynxFilePicker.save()` in this test, oldest
|
|
65
|
+
* first. Each test starts with none.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* fireEvent.tap(screen.getByText('Export'));
|
|
70
|
+
* await waitForUpdate();
|
|
71
|
+
* expect(savedFiles()).toMatchObject([{ name: 'report.csv', type: 'text/csv' }]);
|
|
72
|
+
* expect(savedFiles()[0]!.text).toContain('Total,42');
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare const savedFiles: () => readonly SavedFile[];
|
|
76
|
+
//# sourceMappingURL=file-picker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-picker.d.ts","sourceRoot":"","sources":["../src/file-picker.ts"],"names":[],"mappings":"AAGA,yDAAyD;AACzD,MAAM,MAAM,cAAc,GAAG;IAC3B,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;CACvC,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG;IACtB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAyBF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAAI,eAAe;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IA2CH,CAAC;AAkBF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,cAAc,EAAE,KAAG,IAIjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,IAExC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,QAAO,SAAS,SAAS,EAE/C,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** What `LynxFilePicker` calls, as the shells name their module. */
|
|
2
|
+
const MODULE = 'AngularLynxFilePicker';
|
|
3
|
+
const toBytes = (content) => typeof content === 'string' ? new TextEncoder().encode(content) : content;
|
|
4
|
+
const toBase64 = (bytes) => {
|
|
5
|
+
let binary = '';
|
|
6
|
+
for (const byte of bytes)
|
|
7
|
+
binary += String.fromCharCode(byte);
|
|
8
|
+
return btoa(binary);
|
|
9
|
+
};
|
|
10
|
+
const fromBase64 = (base64) => Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
|
|
11
|
+
/**
|
|
12
|
+
* Gives the environment's background thread an `AngularLynxFilePicker`
|
|
13
|
+
* module, as the apps `ng build --platform` makes with angular.json's
|
|
14
|
+
* `filePicker` have. It stands for a person who closes the picker until a
|
|
15
|
+
* spec says what they pick ({@link setPickedFiles}), and who saves every
|
|
16
|
+
* file the app offers ({@link savedFiles}) unless a spec has them close the
|
|
17
|
+
* screen ({@link setFilePickerCanceled}). The runtime reaches it through the
|
|
18
|
+
* background thread, as it reaches the shells' module, so specs see the
|
|
19
|
+
* runtime's own behavior, its size limit included.
|
|
20
|
+
*
|
|
21
|
+
* It runs each time the environment injects the background thread's
|
|
22
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
23
|
+
* starts with nothing to pick and nothing saved.
|
|
24
|
+
*/
|
|
25
|
+
export const installFilePickerModule = (threadGlobals) => {
|
|
26
|
+
const module = {
|
|
27
|
+
picks: undefined,
|
|
28
|
+
canceled: false,
|
|
29
|
+
saved: [],
|
|
30
|
+
pick(request, done) {
|
|
31
|
+
if (this.canceled || this.picks === undefined) {
|
|
32
|
+
return done({ canceled: true });
|
|
33
|
+
}
|
|
34
|
+
const files = this.picks.map((file) => ({
|
|
35
|
+
bytes: toBytes(file.content),
|
|
36
|
+
name: file.name,
|
|
37
|
+
type: file.type ?? 'application/octet-stream',
|
|
38
|
+
}));
|
|
39
|
+
const total = files.reduce((sum, file) => sum + file.bytes.length, 0);
|
|
40
|
+
// LynxFilePicker always sends its limit, as it does to the shells.
|
|
41
|
+
if (total > request.maxBytes) {
|
|
42
|
+
return done({ error: 'too-large' });
|
|
43
|
+
}
|
|
44
|
+
done({
|
|
45
|
+
files: files.map(({ bytes, name, type }) => ({
|
|
46
|
+
base64: toBase64(bytes),
|
|
47
|
+
name,
|
|
48
|
+
type,
|
|
49
|
+
})),
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
save(file, done) {
|
|
53
|
+
if (this.canceled)
|
|
54
|
+
return done({ saved: false });
|
|
55
|
+
const bytes = fromBase64(file.base64);
|
|
56
|
+
this.saved.push({
|
|
57
|
+
name: file.name,
|
|
58
|
+
type: file.type,
|
|
59
|
+
bytes,
|
|
60
|
+
text: new TextDecoder().decode(bytes),
|
|
61
|
+
});
|
|
62
|
+
done({ saved: true });
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
threadGlobals.NativeModules = {
|
|
66
|
+
...threadGlobals.NativeModules,
|
|
67
|
+
[MODULE]: module,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The fake module, read through the environment rather than kept here:
|
|
72
|
+
* under `ng test`, the setup file and the specs can load different copies of
|
|
73
|
+
* this module.
|
|
74
|
+
*/
|
|
75
|
+
const fakeModule = (helper) => {
|
|
76
|
+
const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
|
|
77
|
+
.NativeModules?.[MODULE];
|
|
78
|
+
if (!module) {
|
|
79
|
+
throw new Error(`${helper}() needs the testing library's environment, which its setup file installs.`);
|
|
80
|
+
}
|
|
81
|
+
return module;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Has the person pick `files` each time the app opens `LynxFilePicker`'s
|
|
85
|
+
* picker in this test, so `pick()` resolves with them. Until a spec calls
|
|
86
|
+
* it, the person closes the picker, and `pick()` resolves with `[]`. Files
|
|
87
|
+
* over the runtime's 20 MiB limit, together, reject with `too-large`, as on
|
|
88
|
+
* a phone.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* setPickedFiles([{ name: 'receipt.pdf', type: 'application/pdf', content: pdfBytes }]);
|
|
93
|
+
* fireEvent.tap(screen.getByText('Attach receipt'));
|
|
94
|
+
* await waitForUpdate();
|
|
95
|
+
* expect(screen.getByText('receipt.pdf')).toBeInTheDocument();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export const setPickedFiles = (files) => {
|
|
99
|
+
const module = fakeModule('setPickedFiles');
|
|
100
|
+
module.picks = [...files];
|
|
101
|
+
module.canceled = false;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Has the person close `LynxFilePicker`'s picker and save screen for the
|
|
105
|
+
* rest of this test: `pick()` resolves with `[]`, and `save()` with false.
|
|
106
|
+
* {@link setPickedFiles} undoes it.
|
|
107
|
+
*/
|
|
108
|
+
export const setFilePickerCanceled = () => {
|
|
109
|
+
fakeModule('setFilePickerCanceled').canceled = true;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* The files the app saved with `LynxFilePicker.save()` in this test, oldest
|
|
113
|
+
* first. Each test starts with none.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* fireEvent.tap(screen.getByText('Export'));
|
|
118
|
+
* await waitForUpdate();
|
|
119
|
+
* expect(savedFiles()).toMatchObject([{ name: 'report.csv', type: 'text/csv' }]);
|
|
120
|
+
* expect(savedFiles()[0]!.text).toContain('Total,42');
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export const savedFiles = () => [
|
|
124
|
+
...fakeModule('savedFiles').saved,
|
|
125
|
+
];
|
package/dist/fire-event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEpB,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,OAAO,QAAQ,CAAC;AACvC,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;AAC/E,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG;KAC3D,CAAC,IAAI,SAAS,GAAG,YAAY;CAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEpB,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,OAAO,QAAQ,CAAC;AACvC,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;AAC/E,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG;KAC3D,CAAC,IAAI,SAAS,GAAG,YAAY;CAC/B,CAAC;AA8OF,eAAO,MAAM,SAAS,EAAE,SAET,CAAC"}
|
package/dist/fire-event.js
CHANGED
|
@@ -143,6 +143,46 @@ const createLynxEvent = (elem, type, name, init) => {
|
|
|
143
143
|
});
|
|
144
144
|
return event;
|
|
145
145
|
};
|
|
146
|
+
/** Each reader runHandler puts in runWorklet's place, to the one it calls. */
|
|
147
|
+
const readers = new WeakMap();
|
|
148
|
+
/** Lynx's `EventResult::kStopPropagationBit`. */
|
|
149
|
+
const STOP_PROPAGATION = 1;
|
|
150
|
+
/** Lynx's `EventResult::kStopImmediatePropagationBit`. */
|
|
151
|
+
const STOP_IMMEDIATE_PROPAGATION = 2;
|
|
152
|
+
/**
|
|
153
|
+
* Runs `handler` with `event`, and returns the bits of Lynx's `EventResult`
|
|
154
|
+
* its worklet returned, which a device reads to stop the event
|
|
155
|
+
* (`TouchEventHandler::HandleEventOperations`): a listener's
|
|
156
|
+
* `$event.stopPropagation()` sets them. The testing environment's handler
|
|
157
|
+
* drops what its worklet returns, so it's read from runWorklet as it
|
|
158
|
+
* returns.
|
|
159
|
+
*/
|
|
160
|
+
const runHandler = (handler, event) => {
|
|
161
|
+
const store = globalThis;
|
|
162
|
+
const run = store.runWorklet;
|
|
163
|
+
// The testing environment's own runWorklet, under any reader an enclosing
|
|
164
|
+
// fireEvent put there: a fireEvent inside a listener reads its own event's
|
|
165
|
+
// bits, which the enclosing one's mustn't take for its listener's.
|
|
166
|
+
const base = run && (readers.get(run) ?? run);
|
|
167
|
+
let bits = 0;
|
|
168
|
+
const reader = (...args) => {
|
|
169
|
+
const result = base?.(...args);
|
|
170
|
+
const returned = result
|
|
171
|
+
?.eventReturnResult;
|
|
172
|
+
if (typeof returned === 'number')
|
|
173
|
+
bits |= returned;
|
|
174
|
+
return result;
|
|
175
|
+
};
|
|
176
|
+
readers.set(reader, base);
|
|
177
|
+
store.runWorklet = reader;
|
|
178
|
+
try {
|
|
179
|
+
handler(event);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
store.runWorklet = run;
|
|
183
|
+
}
|
|
184
|
+
return bits;
|
|
185
|
+
};
|
|
146
186
|
/**
|
|
147
187
|
* Every element in `target`'s tree with a `global-bind` handler for `name`:
|
|
148
188
|
* Lynx runs one for an event on any element of the page.
|
|
@@ -161,8 +201,11 @@ const globalHandlersOf = (target, name) => {
|
|
|
161
201
|
* `window:` listener runs. An event that
|
|
162
202
|
* bubbles goes down from the page to the target, running `capture-bind` and
|
|
163
203
|
* `capture-catch` handlers, then back up, running `bind` and `catch` ones. A
|
|
164
|
-
* `catch` handler of either phase runs and stops the event there
|
|
165
|
-
*
|
|
204
|
+
* `catch` handler of either phase runs and stops the event there, and so
|
|
205
|
+
* does a handler whose listener called `stopPropagation()`, as Lynx reads
|
|
206
|
+
* the bits it returns; after `stopImmediatePropagation()` no other handler
|
|
207
|
+
* runs. Any other event runs the target's own `bind` or `catch` handler and
|
|
208
|
+
* nothing more.
|
|
166
209
|
*
|
|
167
210
|
* It calls the handlers rather than dispatching one DOM event, because the
|
|
168
211
|
* testing environment listens for a separate DOM event per kind
|
|
@@ -186,7 +229,7 @@ const deliver = (target, name, init) => {
|
|
|
186
229
|
let notCanceled = true;
|
|
187
230
|
/**
|
|
188
231
|
* Runs each element's handlers of `types` in turn. Returns true once a
|
|
189
|
-
* catch handler stops the event.
|
|
232
|
+
* catch handler, or a listener's stopPropagation(), stops the event.
|
|
190
233
|
*/
|
|
191
234
|
const runPhase = (elements, types) => {
|
|
192
235
|
for (const element of elements) {
|
|
@@ -196,20 +239,27 @@ const deliver = (target, name, init) => {
|
|
|
196
239
|
if (!handler)
|
|
197
240
|
continue;
|
|
198
241
|
const event = createLynxEvent(target, type, name, init);
|
|
199
|
-
handler
|
|
242
|
+
const bits = runHandler(handler, event);
|
|
200
243
|
notCanceled &&= !event.defaultPrevented;
|
|
201
|
-
|
|
244
|
+
if (bits & STOP_IMMEDIATE_PROPAGATION)
|
|
245
|
+
return true;
|
|
246
|
+
caught ||= type.endsWith('catchEvent') || !!(bits & STOP_PROPAGATION);
|
|
202
247
|
}
|
|
203
248
|
if (caught)
|
|
204
249
|
return true;
|
|
205
250
|
}
|
|
206
251
|
return false;
|
|
207
252
|
};
|
|
208
|
-
|
|
253
|
+
// Lynx runs them first, so one that stops the event stops it for every
|
|
254
|
+
// element (see native-source.ts in the runtime).
|
|
255
|
+
const stoppedGlobally = globalHandlersOf(target, name).some((element) => {
|
|
209
256
|
const event = createLynxEvent(target, 'global-bindEvent', name, init);
|
|
210
|
-
handlerOf(element, 'global-bindEvent', name)
|
|
257
|
+
const bits = runHandler(handlerOf(element, 'global-bindEvent', name), event);
|
|
211
258
|
notCanceled &&= !event.defaultPrevented;
|
|
212
|
-
|
|
259
|
+
return bits !== 0;
|
|
260
|
+
});
|
|
261
|
+
if (stoppedGlobally)
|
|
262
|
+
return notCanceled;
|
|
213
263
|
// Lynx has no capture phase for the events that stay on their target.
|
|
214
264
|
const captured = !!init['bubbles'] && runPhase([...chain].reverse(), CAPTURE_PHASE);
|
|
215
265
|
if (!captured)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where {@link setLocation} puts the phone. Only the coordinates are needed;
|
|
3
|
+
* the rest is what the platform would know, null when left out.
|
|
4
|
+
*/
|
|
5
|
+
export type FakeLocation = {
|
|
6
|
+
readonly latitude: number;
|
|
7
|
+
readonly longitude: number;
|
|
8
|
+
/** In meters. 5 by default, a good GPS fix. */
|
|
9
|
+
readonly accuracy?: number;
|
|
10
|
+
readonly altitude?: number | null;
|
|
11
|
+
readonly altitudeAccuracy?: number | null;
|
|
12
|
+
readonly heading?: number | null;
|
|
13
|
+
readonly speed?: number | null;
|
|
14
|
+
/** When it was found, in milliseconds since 1970. Now, by default. */
|
|
15
|
+
readonly timestamp?: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* What the app is allowed, as `LynxGeolocation.state()` reports it (with
|
|
19
|
+
* `off` coming from {@link setLocationEnabled} instead).
|
|
20
|
+
*/
|
|
21
|
+
export type FakeLocationPermission = 'unknown' | 'denied' | 'approximate' | 'precise';
|
|
22
|
+
/**
|
|
23
|
+
* Gives the environment's background thread an `AngularLynxGeolocation`
|
|
24
|
+
* module, as the apps `ng build --platform` makes have when angular.json's
|
|
25
|
+
* `permissions` list `location`. It starts where a fresh install does: the
|
|
26
|
+
* person hasn't been asked, allows precise location when the app asks, and
|
|
27
|
+
* the phone has no position until {@link setLocation} gives it one.
|
|
28
|
+
* `LynxGeolocation` reaches it through the background thread, as it reaches
|
|
29
|
+
* the shells' module, so specs see the runtime's own behavior.
|
|
30
|
+
*
|
|
31
|
+
* It runs each time the environment injects the background thread's
|
|
32
|
+
* globals: when it's created, and on the reset after each test, so each test
|
|
33
|
+
* starts from a fresh install.
|
|
34
|
+
*/
|
|
35
|
+
export declare const installGeolocationModule: (threadGlobals: {
|
|
36
|
+
NativeModules?: Record<string, unknown>;
|
|
37
|
+
}) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Puts the phone at `location`, or nowhere it can find with `null`: what
|
|
40
|
+
* `LynxGeolocation.getCurrentPosition()` resolves with, and the next
|
|
41
|
+
* position each running watch gets, unless it's nearer the last one than
|
|
42
|
+
* the watch's `distanceFilter`. Until a spec sets one, the phone can't find
|
|
43
|
+
* itself, and `getCurrentPosition()` rejects with `timeout`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* setLocationPermission('precise');
|
|
48
|
+
* setLocation({ latitude: 51.5007, longitude: -0.1246 });
|
|
49
|
+
* await render(NearbyShops);
|
|
50
|
+
* expect(await screen.findByText('2 shops near you')).toBeInTheDocument();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const setLocation: (location: FakeLocation | null) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Sets what the app is allowed, as if the person had answered the prompt or
|
|
56
|
+
* changed it in Settings: what `LynxGeolocation.state()` reports, without a
|
|
57
|
+
* prompt unless it's `unknown` (each test starts there). `denied` ends every
|
|
58
|
+
* running watch, as it does on a phone.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* setLocationPermission('denied');
|
|
63
|
+
* await render(NearbyShops);
|
|
64
|
+
* expect(screen.getByText('Allow location in Settings')).toBeInTheDocument();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare const setLocationPermission: (permission: FakeLocationPermission) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Sets what the person answers when `LynxGeolocation` shows the prompt:
|
|
70
|
+
* `precise` (the default), `approximate` (Android 12's and iOS's choice of
|
|
71
|
+
* an approximate location), or `denied`. The prompt shows only while the
|
|
72
|
+
* permission is `unknown`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* setLocationAnswer('approximate');
|
|
77
|
+
* fireEvent.tap(screen.getByText('Find shops near me'));
|
|
78
|
+
* await waitForUpdate();
|
|
79
|
+
* expect(locationPrompts()).toBe(1);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const setLocationAnswer: (answer: Exclude<FakeLocationPermission, "unknown">) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Turns Location on or off for the whole phone. Off, the state is `off`,
|
|
85
|
+
* whatever the app is allowed, every call rejects with `off`, and every
|
|
86
|
+
* running watch ends with it.
|
|
87
|
+
*/
|
|
88
|
+
export declare const setLocationEnabled: (enabled: boolean) => void;
|
|
89
|
+
/**
|
|
90
|
+
* How many times the location prompt has shown in this test, so a spec can
|
|
91
|
+
* check the app asks at the right moment, and only once.
|
|
92
|
+
*/
|
|
93
|
+
export declare const locationPrompts: () => number;
|
|
94
|
+
//# sourceMappingURL=geolocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,QAAQ,GACR,aAAa,GACb,SAAS,CAAC;AAiId;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAwEH,CAAC;AAmBF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,YAAY,GAAG,IAAI,KAAG,IAQ3D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAChC,YAAY,sBAAsB,KACjC,IAUF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,OAAO,CAAC,sBAAsB,EAAE,SAAS,CAAC,KACjD,IAEF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,OAAO,KAAG,IAOrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,MACG,CAAC"}
|