streetui 1.7.0 → 1.9.0

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.
@@ -1,6 +1,6 @@
1
- import { S as StreetApp } from './compile-Cte0nf06.cjs';
2
- export { V as VERSION } from './compile-Cte0nf06.cjs';
3
- import { R as RenderHandle, H as HydrationDiagnostic } from './hydration-diagnostics-zK-fihvd.cjs';
1
+ import { S as StreetApp, a as ComponentDefinition, b as ContainerBuilder } from './compile-DqsMQVJk.cjs';
2
+ export { V as VERSION } from './compile-DqsMQVJk.cjs';
3
+ import { R as RenderHandle, H as HydrationDiagnostic } from './hydration-diagnostics-4pwt6v7b.cjs';
4
4
  export * from 'streetui/diagnostics';
5
5
 
6
6
  /**
@@ -71,6 +71,44 @@ interface WaitForOptions {
71
71
  * deadline. Use for assertions that become true only after async work settles.
72
72
  */
73
73
  declare function waitFor<T>(check: () => T, options?: WaitForOptions): Promise<T>;
74
+ /** A minimal writable-boolean seam (an overlay `open` signal, typically). */
75
+ interface BooleanControl {
76
+ set(value: boolean): void;
77
+ }
78
+ /** Focus `el` (no-op if it exposes no `focus`). Intentful wrapper for tests. */
79
+ declare function focus(el: Element): void;
80
+ /** Blur `el` (no-op if it exposes no `blur`). */
81
+ declare function blur(el: Element): void;
82
+ /**
83
+ * Dispatch a bubbling, cancelable `keydown` for `key` on `el` (defaulting to the
84
+ * currently-focused element). Extra `init` fields (e.g. `{ shiftKey: true }`)
85
+ * are forwarded. Use for keyboard-interaction assertions (Escape, Tab, arrows).
86
+ */
87
+ declare function pressKey(key: string, el?: Element | null, init?: KeyboardEventInit): void;
88
+ /**
89
+ * Simulate a pointer interaction OUTSIDE `container` — a `mousedown` + `click`
90
+ * on `document.body` (or `target` if given). Drives "click-away to dismiss"
91
+ * behaviour without the test constructing events by hand. If `target` is inside
92
+ * `container` this throws, so a mistake is loud rather than a silent no-op.
93
+ */
94
+ declare function clickOutside(container: Element, target?: Element): void;
95
+ /**
96
+ * Open an overlay by flipping its `open` control to `true`, then flush so the
97
+ * panel mounts and its enter/focus wiring runs. Overlay visibility is app-owned
98
+ * state (§18) — a plain signal — so this is a thin, intentful wrapper over
99
+ * `set(true)` + {@link flushUpdates}.
100
+ */
101
+ declare function openOverlay(open: BooleanControl): Promise<void>;
102
+ /** Close an overlay by flipping its `open` control to `false`, then flush. */
103
+ declare function closeOverlay(open: BooleanControl): Promise<void>;
104
+ /**
105
+ * Settle a CSS transition on `el` deterministically: dispatch the
106
+ * `transitionend` the controller listens for (happy-dom fires none of its own),
107
+ * then flush pending work so any deferred leave-teardown (DOM removal, dispose,
108
+ * detach) completes. Await this after toggling a transitioned element to assert
109
+ * its post-animation state without depending on the fallback timeout.
110
+ */
111
+ declare function waitForTransition(el: Element): Promise<void>;
74
112
  /** Find the first leaf element whose text content includes `text`. */
75
113
  declare function findByText(container: Element, text: string): Element;
76
114
  interface ByRoleOptions {
@@ -111,4 +149,63 @@ interface HydrateTestResult {
111
149
  */
112
150
  declare function renderServerThenHydrate(build: () => StreetApp, options?: HydrateTestOptions): HydrateTestResult;
113
151
 
114
- export { type ByRoleOptions, type HydrateTestOptions, type HydrateTestResult, type RenderResult, type WaitForOptions, findAllByRole, findByRole, findByText, flushUpdates, render, renderOnce, renderServerThenHydrate, waitFor };
152
+ /**
153
+ * Component-focused testing helpers (§22).
154
+ *
155
+ * These extend `streetui/testing` for the component model. Following the spec's
156
+ * "add only the ones that are actually useful" directive, this module ships the
157
+ * helpers that remove real boilerplate and OMITS the ones that would be
158
+ * misleading in this architecture:
159
+ *
160
+ * • renderComponent — mount a single component in a throwaway host app.
161
+ * • hydrateComponent — SSR-then-hydrate that same host (the §11/§12 seam).
162
+ * • findComponent / findAllComponents / getComponentName — locate component
163
+ * instances by their inspectable `data-streetui-component` name.
164
+ * • trigger — dispatch a bubbling DOM event (click/input/keydown…).
165
+ *
166
+ * Deliberately NOT provided:
167
+ * • getComponentProps — props are passed to `setup` and captured by closure;
168
+ * they are not reified on the node (only the definition *name* is), so a
169
+ * prop-reading helper would either lie or require a private-graph backdoor.
170
+ * Assert on rendered output (or a signal you own) instead.
171
+ * • awaitResource — `waitFor(...)` and `flushUpdates()` already settle
172
+ * async resource state; a resource-specific alias would be redundant.
173
+ */
174
+
175
+ interface RenderComponentResult extends RenderResult {
176
+ /** The component's root `<div>` wrapper element. */
177
+ readonly component: HTMLElement;
178
+ }
179
+ /**
180
+ * Build a throwaway single-page host app whose only content is `def` rendered
181
+ * with `props` (and optional `children`), mount it, and return the usual
182
+ * `RenderResult` plus the component's root element. Use for unit-testing one
183
+ * component without hand-writing an app+page wrapper each time.
184
+ */
185
+ declare function renderComponent<P>(def: ComponentDefinition<P>, props: P, children?: ContainerBuilder): RenderComponentResult;
186
+ /**
187
+ * SSR-render then hydrate a single component in a host app — the production
188
+ * server→client seam (§11/§12). `build` must return `{ def, props, children? }`;
189
+ * it is invoked twice (server then client) with id-counter reset between, so a
190
+ * component that owns per-instance signals lines up positionally on hydration.
191
+ */
192
+ declare function hydrateComponent<P>(build: () => {
193
+ def: ComponentDefinition<P>;
194
+ props: P;
195
+ children?: ContainerBuilder;
196
+ }, options?: HydrateTestOptions): HydrateTestResult;
197
+ /** All component instances under `container`, optionally filtered by name. */
198
+ declare function findAllComponents(container: Element, name?: string): HTMLElement[];
199
+ /** The single component instance under `container` (throws if none/ambiguous). */
200
+ declare function findComponent(container: Element, name?: string): HTMLElement;
201
+ /** Read a component element's definition name, or `null` if `el` is not one. */
202
+ declare function getComponentName(el: Element): string | null;
203
+ /**
204
+ * Dispatch a bubbling, cancelable DOM event of `type` on `el`. Thin wrapper over
205
+ * `dispatchEvent` so tests read intentfully (`trigger(btn, 'click')`) without
206
+ * constructing `Event`/`KeyboardEvent` objects by hand. Extra `init` fields
207
+ * (e.g. `{ key: 'Escape' }`) are forwarded to the appropriate event ctor.
208
+ */
209
+ declare function trigger(el: Element, type: string, init?: Record<string, unknown>): void;
210
+
211
+ export { type BooleanControl, type ByRoleOptions, type HydrateTestOptions, type HydrateTestResult, type RenderComponentResult, type RenderResult, type WaitForOptions, blur, clickOutside, closeOverlay, findAllByRole, findAllComponents, findByRole, findByText, findComponent, flushUpdates, focus, getComponentName, hydrateComponent, openOverlay, pressKey, render, renderComponent, renderOnce, renderServerThenHydrate, trigger, waitFor, waitForTransition };
package/dist/testing.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as StreetApp } from './compile-Cte0nf06.js';
2
- export { V as VERSION } from './compile-Cte0nf06.js';
3
- import { R as RenderHandle, H as HydrationDiagnostic } from './hydration-diagnostics-Ddgs3Puu.js';
1
+ import { S as StreetApp, a as ComponentDefinition, b as ContainerBuilder } from './compile-DqsMQVJk.js';
2
+ export { V as VERSION } from './compile-DqsMQVJk.js';
3
+ import { R as RenderHandle, H as HydrationDiagnostic } from './hydration-diagnostics-B2FmY05M.js';
4
4
  export * from 'streetui/diagnostics';
5
5
 
6
6
  /**
@@ -71,6 +71,44 @@ interface WaitForOptions {
71
71
  * deadline. Use for assertions that become true only after async work settles.
72
72
  */
73
73
  declare function waitFor<T>(check: () => T, options?: WaitForOptions): Promise<T>;
74
+ /** A minimal writable-boolean seam (an overlay `open` signal, typically). */
75
+ interface BooleanControl {
76
+ set(value: boolean): void;
77
+ }
78
+ /** Focus `el` (no-op if it exposes no `focus`). Intentful wrapper for tests. */
79
+ declare function focus(el: Element): void;
80
+ /** Blur `el` (no-op if it exposes no `blur`). */
81
+ declare function blur(el: Element): void;
82
+ /**
83
+ * Dispatch a bubbling, cancelable `keydown` for `key` on `el` (defaulting to the
84
+ * currently-focused element). Extra `init` fields (e.g. `{ shiftKey: true }`)
85
+ * are forwarded. Use for keyboard-interaction assertions (Escape, Tab, arrows).
86
+ */
87
+ declare function pressKey(key: string, el?: Element | null, init?: KeyboardEventInit): void;
88
+ /**
89
+ * Simulate a pointer interaction OUTSIDE `container` — a `mousedown` + `click`
90
+ * on `document.body` (or `target` if given). Drives "click-away to dismiss"
91
+ * behaviour without the test constructing events by hand. If `target` is inside
92
+ * `container` this throws, so a mistake is loud rather than a silent no-op.
93
+ */
94
+ declare function clickOutside(container: Element, target?: Element): void;
95
+ /**
96
+ * Open an overlay by flipping its `open` control to `true`, then flush so the
97
+ * panel mounts and its enter/focus wiring runs. Overlay visibility is app-owned
98
+ * state (§18) — a plain signal — so this is a thin, intentful wrapper over
99
+ * `set(true)` + {@link flushUpdates}.
100
+ */
101
+ declare function openOverlay(open: BooleanControl): Promise<void>;
102
+ /** Close an overlay by flipping its `open` control to `false`, then flush. */
103
+ declare function closeOverlay(open: BooleanControl): Promise<void>;
104
+ /**
105
+ * Settle a CSS transition on `el` deterministically: dispatch the
106
+ * `transitionend` the controller listens for (happy-dom fires none of its own),
107
+ * then flush pending work so any deferred leave-teardown (DOM removal, dispose,
108
+ * detach) completes. Await this after toggling a transitioned element to assert
109
+ * its post-animation state without depending on the fallback timeout.
110
+ */
111
+ declare function waitForTransition(el: Element): Promise<void>;
74
112
  /** Find the first leaf element whose text content includes `text`. */
75
113
  declare function findByText(container: Element, text: string): Element;
76
114
  interface ByRoleOptions {
@@ -111,4 +149,63 @@ interface HydrateTestResult {
111
149
  */
112
150
  declare function renderServerThenHydrate(build: () => StreetApp, options?: HydrateTestOptions): HydrateTestResult;
113
151
 
114
- export { type ByRoleOptions, type HydrateTestOptions, type HydrateTestResult, type RenderResult, type WaitForOptions, findAllByRole, findByRole, findByText, flushUpdates, render, renderOnce, renderServerThenHydrate, waitFor };
152
+ /**
153
+ * Component-focused testing helpers (§22).
154
+ *
155
+ * These extend `streetui/testing` for the component model. Following the spec's
156
+ * "add only the ones that are actually useful" directive, this module ships the
157
+ * helpers that remove real boilerplate and OMITS the ones that would be
158
+ * misleading in this architecture:
159
+ *
160
+ * • renderComponent — mount a single component in a throwaway host app.
161
+ * • hydrateComponent — SSR-then-hydrate that same host (the §11/§12 seam).
162
+ * • findComponent / findAllComponents / getComponentName — locate component
163
+ * instances by their inspectable `data-streetui-component` name.
164
+ * • trigger — dispatch a bubbling DOM event (click/input/keydown…).
165
+ *
166
+ * Deliberately NOT provided:
167
+ * • getComponentProps — props are passed to `setup` and captured by closure;
168
+ * they are not reified on the node (only the definition *name* is), so a
169
+ * prop-reading helper would either lie or require a private-graph backdoor.
170
+ * Assert on rendered output (or a signal you own) instead.
171
+ * • awaitResource — `waitFor(...)` and `flushUpdates()` already settle
172
+ * async resource state; a resource-specific alias would be redundant.
173
+ */
174
+
175
+ interface RenderComponentResult extends RenderResult {
176
+ /** The component's root `<div>` wrapper element. */
177
+ readonly component: HTMLElement;
178
+ }
179
+ /**
180
+ * Build a throwaway single-page host app whose only content is `def` rendered
181
+ * with `props` (and optional `children`), mount it, and return the usual
182
+ * `RenderResult` plus the component's root element. Use for unit-testing one
183
+ * component without hand-writing an app+page wrapper each time.
184
+ */
185
+ declare function renderComponent<P>(def: ComponentDefinition<P>, props: P, children?: ContainerBuilder): RenderComponentResult;
186
+ /**
187
+ * SSR-render then hydrate a single component in a host app — the production
188
+ * server→client seam (§11/§12). `build` must return `{ def, props, children? }`;
189
+ * it is invoked twice (server then client) with id-counter reset between, so a
190
+ * component that owns per-instance signals lines up positionally on hydration.
191
+ */
192
+ declare function hydrateComponent<P>(build: () => {
193
+ def: ComponentDefinition<P>;
194
+ props: P;
195
+ children?: ContainerBuilder;
196
+ }, options?: HydrateTestOptions): HydrateTestResult;
197
+ /** All component instances under `container`, optionally filtered by name. */
198
+ declare function findAllComponents(container: Element, name?: string): HTMLElement[];
199
+ /** The single component instance under `container` (throws if none/ambiguous). */
200
+ declare function findComponent(container: Element, name?: string): HTMLElement;
201
+ /** Read a component element's definition name, or `null` if `el` is not one. */
202
+ declare function getComponentName(el: Element): string | null;
203
+ /**
204
+ * Dispatch a bubbling, cancelable DOM event of `type` on `el`. Thin wrapper over
205
+ * `dispatchEvent` so tests read intentfully (`trigger(btn, 'click')`) without
206
+ * constructing `Event`/`KeyboardEvent` objects by hand. Extra `init` fields
207
+ * (e.g. `{ key: 'Escape' }`) are forwarded to the appropriate event ctor.
208
+ */
209
+ declare function trigger(el: Element, type: string, init?: Record<string, unknown>): void;
210
+
211
+ export { type BooleanControl, type ByRoleOptions, type HydrateTestOptions, type HydrateTestResult, type RenderComponentResult, type RenderResult, type WaitForOptions, blur, clickOutside, closeOverlay, findAllByRole, findAllComponents, findByRole, findByText, findComponent, flushUpdates, focus, getComponentName, hydrateComponent, openOverlay, pressKey, render, renderComponent, renderOnce, renderServerThenHydrate, trigger, waitFor, waitForTransition };