@blotch/angular-lynx-testing-library 22.2.14 → 22.2.15

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 CHANGED
@@ -2,6 +2,8 @@ export { render, cleanup, waitForUpdate } from './render.js';
2
2
  export type { RenderInputs, RenderOptions, RenderResult } from './render.js';
3
3
  export type { ComponentRef } from '@angular/core';
4
4
  export { fireEvent, eventMap } from './fire-event.js';
5
+ export { openedURLs } from './linking.js';
6
+ export type { OpenedURL } from './linking.js';
5
7
  export { screen, within, getQueriesForElement, queries } from './queries.js';
6
8
  export type { BoundAccessibilityLabelQueries, BoundLynxQueries, LynxQueries, LynxScreen, } from './queries.js';
7
9
  export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
@@ -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,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC7E,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
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,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC7E,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { render, cleanup, waitForUpdate } from './render.js';
2
2
  export { fireEvent, eventMap } from './fire-event.js';
3
+ export { openedURLs } from './linking.js';
3
4
  export { screen, within, getQueriesForElement, queries } from './queries.js';
4
5
  export { queryAllByAccessibilityLabel, queryByAccessibilityLabel, getAllByAccessibilityLabel, getByAccessibilityLabel, findAllByAccessibilityLabel, findByAccessibilityLabel, } from './accessibility-label-queries.js';
5
6
  export { queryAllByRole, queryByRole, getAllByRole, getByRole, findAllByRole, findByRole, } from './role-queries.js';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A link the app opened with `LynxLinking`, as {@link openedURLs} lists it.
3
+ */
4
+ export type OpenedURL = {
5
+ /** The URL, as the app gave it. */
6
+ readonly url: string;
7
+ /**
8
+ * Whether it opened in the browser sheet over the app (`openInApp()`)
9
+ * rather than where the system opens it (`openURL()`).
10
+ */
11
+ readonly inApp: boolean;
12
+ };
13
+ /**
14
+ * Gives the environment's background thread an `AngularLynxLinking` module,
15
+ * as the apps `ng build --platform` makes have, which records each URL rather
16
+ * than opening it. `LynxLinking` reaches it through the background thread, as
17
+ * it reaches the shells' module, so specs see the runtime's own behavior:
18
+ * `openURL()` and `openInApp()` resolve, and `canOpenURL()` resolves `true`.
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 URLs recorded. Only `NativeModules.AngularLynxLinking` is added:
23
+ * every other module stays missing, as in Lynx Explorer.
24
+ */
25
+ export declare const installLinkingModule: (threadGlobals: {
26
+ NativeModules?: Record<string, unknown>;
27
+ }) => void;
28
+ /**
29
+ * The links the app has opened with `LynxLinking` in this test, oldest
30
+ * first, so a spec can check where a tap leads. Each test starts with none.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * fireEvent.tap(screen.getByText('Help'));
35
+ * await waitForUpdate();
36
+ * expect(openedURLs()).toEqual([
37
+ * { url: 'https://example.com/help', inApp: true },
38
+ * ]);
39
+ * ```
40
+ */
41
+ export declare const openedURLs: () => readonly OpenedURL[];
42
+ //# sourceMappingURL=linking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linking.d.ts","sourceRoot":"","sources":["../src/linking.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAcF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAAI,eAAe;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,KAAG,IAkBH,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,QAAO,SAAS,SAAS,EAM/C,CAAC"}
@@ -0,0 +1,53 @@
1
+ /** What `LynxLinking` calls, named as the shells name their module. */
2
+ const MODULE = 'AngularLynxLinking';
3
+ /**
4
+ * Gives the environment's background thread an `AngularLynxLinking` module,
5
+ * as the apps `ng build --platform` makes have, which records each URL rather
6
+ * than opening it. `LynxLinking` reaches it through the background thread, as
7
+ * it reaches the shells' module, so specs see the runtime's own behavior:
8
+ * `openURL()` and `openInApp()` resolve, and `canOpenURL()` resolves `true`.
9
+ *
10
+ * It runs each time the environment injects the background thread's globals:
11
+ * when it's created, and on the reset after each test, so each test starts
12
+ * with no URLs recorded. Only `NativeModules.AngularLynxLinking` is added:
13
+ * every other module stays missing, as in Lynx Explorer.
14
+ */
15
+ export const installLinkingModule = (threadGlobals) => {
16
+ const opened = [];
17
+ const module = {
18
+ opened,
19
+ openURL: (url, done) => {
20
+ opened.push({ url, inApp: false });
21
+ done({});
22
+ },
23
+ openInApp: (url, _request, done) => {
24
+ opened.push({ url, inApp: true });
25
+ done({});
26
+ },
27
+ canOpenURL: (_url, done) => done({ value: true }),
28
+ };
29
+ threadGlobals.NativeModules = {
30
+ ...threadGlobals.NativeModules,
31
+ [MODULE]: module,
32
+ };
33
+ };
34
+ /**
35
+ * The links the app has opened with `LynxLinking` in this test, oldest
36
+ * first, so a spec can check where a tap leads. Each test starts with none.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * fireEvent.tap(screen.getByText('Help'));
41
+ * await waitForUpdate();
42
+ * expect(openedURLs()).toEqual([
43
+ * { url: 'https://example.com/help', inApp: true },
44
+ * ]);
45
+ * ```
46
+ */
47
+ export const openedURLs = () => {
48
+ // Read through the environment rather than kept here: under `ng test`, the
49
+ // setup file and the specs can load different copies of this module.
50
+ const module = globalThis.lynxTestingEnv?.backgroundThread.globalThis
51
+ .NativeModules?.[MODULE];
52
+ return [...(module?.opened ?? [])];
53
+ };
package/dist/setup.js CHANGED
@@ -22,6 +22,7 @@
22
22
  import '@angular/compiler';
23
23
  import '@testing-library/jest-dom/vitest';
24
24
  import { LynxTestingEnv } from '@lynx-js/testing-environment';
25
+ import { installLinkingModule } from './linking.js';
25
26
  // ─── CSS fetch intercept ─────────────────────────────────────────────────────
26
27
  /**
27
28
  * Angular JIT calls fetch('./component.css') to load external styleUrls.
@@ -69,7 +70,11 @@ const returnOnWarnings = (threadGlobals) => {
69
70
  };
70
71
  };
71
72
  globalThis.onInjectMainThreadGlobals = returnOnWarnings;
72
- globalThis.onInjectBackgroundThreadGlobals = returnOnWarnings;
73
+ globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
74
+ returnOnWarnings(threadGlobals);
75
+ // LynxLinking records the URLs it opens (see linking.ts).
76
+ installLinkingModule(threadGlobals);
77
+ };
73
78
  // ─── Install LynxTestingEnv ──────────────────────────────────────────────────
74
79
  /**
75
80
  * Turns the globals the testing environment is about to write into plain data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/angular-lynx-testing-library",
3
- "version": "22.2.14",
3
+ "version": "22.2.15",
4
4
  "description": "Testing utilities for AngularLynx apps",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {