@blotch/angular-lynx-testing-library 22.2.24 → 22.2.26
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +5 -1
- package/dist/setup.js +3 -0
- package/dist/shortcuts.d.ts +42 -0
- package/dist/shortcuts.d.ts.map +1 -0
- package/dist/shortcuts.js +75 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { ComponentRef } from '@angular/core';
|
|
|
4
4
|
export { fireEvent, eventMap } from './fire-event.js';
|
|
5
5
|
export { openedURLs } from './linking.js';
|
|
6
6
|
export type { OpenedURL } from './linking.js';
|
|
7
|
+
export { runShortcut } from './shortcuts.js';
|
|
7
8
|
export { screen, within, getQueriesForElement, queries } from './queries.js';
|
|
8
9
|
export type { BoundAccessibilityLabelQueries, BoundLynxQueries, LynxQueries, LynxScreen, } from './queries.js';
|
|
9
10
|
export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY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AC1C,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { render, cleanup, waitForUpdate } from './render.js';
|
|
2
2
|
export { fireEvent, eventMap } from './fire-event.js';
|
|
3
3
|
export { openedURLs } from './linking.js';
|
|
4
|
+
export { runShortcut } from './shortcuts.js';
|
|
4
5
|
export { screen, within, getQueriesForElement, queries } from './queries.js';
|
|
5
6
|
export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
|
|
6
7
|
export { queryAllByRole, queryByRole, getAllByRole, getByRole, findAllByRole, findByRole, } from './role-queries.js';
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EAKb,KAAK,IAAI,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EAKb,KAAK,IAAI,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,KAAK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C,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GACrC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B;;OAEG;IACH,UAAU,EAAE,MAAM,gBAAgB,CAAC;IACnC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC/B,GAAG,gBAAgB,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC;AAIpB,eAAO,MAAM,OAAO,QAAO,IAM1B,CAAC;AAmFF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAU,CAAC,SAAS,OAAO,GAAG,WAAW,EAAE,CAAC,GAAG,OAAO,EACvE,eAAe,IAAI,CAAC,CAAC,CAAC,EACtB,UAAS,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAM,KACzC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAmH5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,IAAI,CAKlD,CAAC"}
|
package/dist/render.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { inputBinding, provideZonelessChangeDetection, reflectComponentType, signal, } from '@angular/core';
|
|
18
18
|
import { createApplication } from '@angular/platform-browser';
|
|
19
19
|
import { getQueriesForElement, } from '@testing-library/dom';
|
|
20
|
-
import { provideRenderer } from '@blotch/angular-lynx';
|
|
20
|
+
import { provideRenderer, ɵhideSplashScreenUnlessProvided, } from '@blotch/angular-lynx';
|
|
21
21
|
import { queries } from './queries.js';
|
|
22
22
|
let currentAppRef = null;
|
|
23
23
|
export const cleanup = () => {
|
|
@@ -133,6 +133,10 @@ export const render = async (rootComponent, options = {}) => {
|
|
|
133
133
|
// LynxDocument.createRootElement() runs during bootstrap, calling
|
|
134
134
|
// __CreatePage which appends the <page> element to document.body.
|
|
135
135
|
const componentRef = appRef.bootstrap(rootComponent, { bindings });
|
|
136
|
+
// What bootstrapApplication() does next: the splash screen goes at the
|
|
137
|
+
// first frame, unless the app's provideSplashScreen() says when. A spec
|
|
138
|
+
// reads LynxSplashScreen.visible() to see that it went.
|
|
139
|
+
ɵhideSplashScreenUnlessProvided(appRef);
|
|
136
140
|
// Force a synchronous CD cycle so signal-initialized state is reflected in
|
|
137
141
|
// the DOM before we return. bootstrap already triggers one CD, but work it
|
|
138
142
|
// starts may defer follow-up updates to a microtask: ngModel writes its
|
package/dist/setup.js
CHANGED
|
@@ -23,6 +23,7 @@ import '@angular/compiler';
|
|
|
23
23
|
import '@testing-library/jest-dom/vitest';
|
|
24
24
|
import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
25
25
|
import { installLinkingModule } from './linking.js';
|
|
26
|
+
import { installShortcutsModule } from './shortcuts.js';
|
|
26
27
|
// ─── CSS fetch intercept ─────────────────────────────────────────────────────
|
|
27
28
|
/**
|
|
28
29
|
* Angular JIT calls fetch('./component.css') to load external styleUrls.
|
|
@@ -95,6 +96,8 @@ globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
|
|
|
95
96
|
frameOnInstalledTimers(threadGlobals);
|
|
96
97
|
// LynxLinking records the URLs it opens (see linking.ts).
|
|
97
98
|
installLinkingModule(threadGlobals);
|
|
99
|
+
// LynxShortcuts takes the shortcuts runShortcut() runs (see shortcuts.ts).
|
|
100
|
+
installShortcutsModule(threadGlobals);
|
|
98
101
|
};
|
|
99
102
|
// ─── Install LynxTestingEnv ──────────────────────────────────────────────────
|
|
100
103
|
/**
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gives the environment's background thread an `AngularLynxShortcuts` module,
|
|
3
|
+
* as the apps `ng build --platform` makes have: it keeps the shortcuts
|
|
4
|
+
* {@link runShortcut} runs until `LynxShortcuts` takes them. `LynxShortcuts`
|
|
5
|
+
* reaches it through the background thread, as it reaches the shells' module,
|
|
6
|
+
* 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 no shortcut is left
|
|
10
|
+
* waiting for the next test. Only `NativeModules.AngularLynxShortcuts` is
|
|
11
|
+
* added: every other module stays as it was.
|
|
12
|
+
*/
|
|
13
|
+
export declare const installShortcutsModule: (threadGlobals: {
|
|
14
|
+
NativeModules?: Record<string, unknown>;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Runs one of the app's shortcuts, as the person does by asking Siri or from
|
|
18
|
+
* the app icon's menu, so a spec can check what the app does with it.
|
|
19
|
+
*
|
|
20
|
+
* A spec doesn't read angular.json's `shortcuts`, so the `id` only has to be
|
|
21
|
+
* one the code under test handles with `LynxShortcuts.on()`, and a shortcut
|
|
22
|
+
* that has a `route` there gets it here. The shortcut reaches the app as it
|
|
23
|
+
* does on a phone, through the background thread: wait for it with
|
|
24
|
+
* `waitForUpdate()`. Run before the app has injected `LynxShortcuts`, it
|
|
25
|
+
* waits for it, as the shortcut that starts an app does.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* await render(Feed);
|
|
30
|
+
* runShortcut('refresh');
|
|
31
|
+
* await waitForUpdate();
|
|
32
|
+
* expect(screen.getByText('Refreshed')).toBeInTheDocument();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param id - The shortcut's `id` in angular.json's `shortcuts`.
|
|
36
|
+
* @param options - `route`: the shortcut's `route` there, which the router
|
|
37
|
+
* navigates to.
|
|
38
|
+
*/
|
|
39
|
+
export declare const runShortcut: (id: string, options?: {
|
|
40
|
+
readonly route?: string;
|
|
41
|
+
}) => void;
|
|
42
|
+
//# sourceMappingURL=shortcuts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcuts.d.ts","sourceRoot":"","sources":["../src/shortcuts.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GAAI,eAAe;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAUH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GACtB,IAAI,MAAM,EACV,UAAS;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,KACxC,IA8BF,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** What `LynxShortcuts` calls and hears, named as the shells name them. */
|
|
2
|
+
const MODULE = 'AngularLynxShortcuts';
|
|
3
|
+
const EVENT = 'angularLynxShortcut';
|
|
4
|
+
/**
|
|
5
|
+
* Gives the environment's background thread an `AngularLynxShortcuts` module,
|
|
6
|
+
* as the apps `ng build --platform` makes have: it keeps the shortcuts
|
|
7
|
+
* {@link runShortcut} runs until `LynxShortcuts` takes them. `LynxShortcuts`
|
|
8
|
+
* reaches it through the background thread, as it reaches the shells' module,
|
|
9
|
+
* 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 no shortcut is left
|
|
13
|
+
* waiting for the next test. Only `NativeModules.AngularLynxShortcuts` is
|
|
14
|
+
* added: every other module stays as it was.
|
|
15
|
+
*/
|
|
16
|
+
export const installShortcutsModule = (threadGlobals) => {
|
|
17
|
+
const waiting = [];
|
|
18
|
+
const module = {
|
|
19
|
+
waiting,
|
|
20
|
+
take: (done) => done({ shortcuts: waiting.splice(0) }),
|
|
21
|
+
};
|
|
22
|
+
threadGlobals.NativeModules = {
|
|
23
|
+
...threadGlobals.NativeModules,
|
|
24
|
+
[MODULE]: module,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Runs one of the app's shortcuts, as the person does by asking Siri or from
|
|
29
|
+
* the app icon's menu, so a spec can check what the app does with it.
|
|
30
|
+
*
|
|
31
|
+
* A spec doesn't read angular.json's `shortcuts`, so the `id` only has to be
|
|
32
|
+
* one the code under test handles with `LynxShortcuts.on()`, and a shortcut
|
|
33
|
+
* that has a `route` there gets it here. The shortcut reaches the app as it
|
|
34
|
+
* does on a phone, through the background thread: wait for it with
|
|
35
|
+
* `waitForUpdate()`. Run before the app has injected `LynxShortcuts`, it
|
|
36
|
+
* waits for it, as the shortcut that starts an app does.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* await render(Feed);
|
|
41
|
+
* runShortcut('refresh');
|
|
42
|
+
* await waitForUpdate();
|
|
43
|
+
* expect(screen.getByText('Refreshed')).toBeInTheDocument();
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param id - The shortcut's `id` in angular.json's `shortcuts`.
|
|
47
|
+
* @param options - `route`: the shortcut's `route` there, which the router
|
|
48
|
+
* navigates to.
|
|
49
|
+
*/
|
|
50
|
+
export const runShortcut = (id, options = {}) => {
|
|
51
|
+
// Read through the environment rather than kept here: under `ng test`, the
|
|
52
|
+
// setup file and the specs can load different copies of this module.
|
|
53
|
+
const env = globalThis.lynxTestingEnv;
|
|
54
|
+
const background = env?.backgroundThread.globalThis;
|
|
55
|
+
const module = background?.NativeModules?.[MODULE];
|
|
56
|
+
if (!env || !module) {
|
|
57
|
+
throw new Error("runShortcut() needs the testing library's environment, which its setup file installs.");
|
|
58
|
+
}
|
|
59
|
+
module.waiting.push({
|
|
60
|
+
id,
|
|
61
|
+
...(options.route !== undefined && { route: options.route }),
|
|
62
|
+
});
|
|
63
|
+
// What the shells send when a shortcut arrives: LynxShortcuts answers by
|
|
64
|
+
// taking the ones waiting. A global event arrives on the background
|
|
65
|
+
// thread, and the listener there calls the app's on the main thread
|
|
66
|
+
// through that thread's `lynx`, so the event is sent from it. Specs run on
|
|
67
|
+
// the main thread, which comes back afterwards.
|
|
68
|
+
env.switchToBackgroundThread();
|
|
69
|
+
try {
|
|
70
|
+
background?.lynx?.getJSModule?.('GlobalEventEmitter')?.emit(EVENT);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
env.switchToMainThread();
|
|
74
|
+
}
|
|
75
|
+
};
|
package/package.json
CHANGED