zidane-ui/ extensions/ testing
import { … } from 'zidane-ui/extensions/testing'ui/src/extensions/testing/index.ts
Functions#
createFixtureExtensionsHostFunction#
Creates an ExtensionsHost held in memory.
function createFixtureExtensionsHost(
options?: FixtureExtensionsOptions,
): FixtureExtensionsHostParameters
| Name | Type | Default | Description |
|---|---|---|---|
| options? | FixtureExtensionsOptions | {} | What it holds and which members it offers. |
Returns
fixtureItemFunction#
Builds an item for a fixture: key defaults to <token>:<extension>:<n>.
function fixtureItem<N extends keyof ExtensionWireMap>(
token: N,
extension: string,
item: ExtensionWireMap[N],
key?: string,
): ExtensionItem<N>Type parameters
| Name | Type | Description |
|---|---|---|
| N | extends keyof ExtensionWireMap |
Parameters
| Name | Type | Description |
|---|---|---|
| token | N | The token. |
| extension | string | The contributing extension. |
| item | ExtensionWireMap[N] | The wire form. |
| key? | string | The item's key. |
Returns
storeKeyFunction#
The key of a store in FixtureExtensionsOptions.stores.
function storeKey(ref: ExtensionStoreRef): stringParameters
| Name | Type | Description |
|---|---|---|
| ref | ExtensionStoreRef | The store. |
Returns
stringInterfaces#
FixtureExtensionsControlInterface#
Drives a fixture host from outside, as the extensions behind it would.
interface FixtureExtensionsControlProperties
| Name | Type | Description |
|---|---|---|
| dialog | (request: DialogRequest, ctx: DialogQueueShowContext) => Promise<unknown> | Asks this client for a dialog; resolves with the answer. |
| effect | (effect: ExtensionUiEffect) => Promise<ExtensionUiEffectResult> | Routes a |
| invoked | () => readonly { args: unknown; id: keyof ExtensionCallbacks }[] | The callbacks invoked so far. |
| links | () => readonly ExtensionLinkRequest[] | The links offered to the link handlers so far. |
| panelChanged | (change: ExtensionPanelChange) => void | A live panel would load something new (its |
| ran | () => readonly { args?: string; id: string; sessionId?: string }[] | The commands run so far. |
| readStore | (ref: ExtensionStoreRef) => unknown | A store's value now. |
| remove | (key: string) => void | Withdraws an item. |
| setScope | (next: ExtensionAccessScope | null) => void | Changes the token's scope (with |
| setSettings | (next: ExtensionSettingsWire) => void | Replaces the settings. |
| upsert | (entry: ExtensionItem) => void | Adds or replaces an item (by key). |
| writeStore | (ref: ExtensionStoreRef, value: unknown) => void | Another client wrote a store. |
FixtureExtensionsOptionsInterface#
Options of createFixtureExtensionsHost.
interface FixtureExtensionsOptionsProperties
| Name | Type | Description |
|---|---|---|
| callbacks? | { 'badge.menu'?: FixtureCallback<'badge.menu'>; 'badge.run'?: FixtureCallback<'badge.run'>; 'panel.action'?: FixtureCallback<'panel.action'>; 'panel.load'?: FixtureCallback<'panel.load'>; 'reference.resolve'?: FixtureCallback<'reference.resolve'>; 'setting.action'?: FixtureCallback<'setting.action'>; 'setting.status'?: FixtureCallback<'setting.status'> } | Scripted callbacks. One left out answers |
| capabilities? | readonly FixtureExtensionsCapability[] | Offer only these optional members. Default: all of them. |
| commands? | readonly ExtensionCommandWire[] | The commands. Default: none. |
| goodKey? | string | The API key |
| integrations? | readonly ExtensionIntegrationWire[] | The integrations. Default: none. |
| items? | readonly ExtensionItem<keyof ExtensionWireMap>[] | The items there at the start. |
| openLink? | (request: ExtensionLinkRequest) => boolean | Promise<boolean> | The link handlers: whether one opens a link. Absent: no |
| rpc? | Readonly<Record<string, Readonly<Record<string, FixtureRpcMethod>>>> | Scripted RPC methods, by contract then method. |
| scope? | ExtensionAccessScope | null | The scope the client's token grants. Absent: no |
| settings? | ExtensionSettingsWire | The settings. Default: none. |
| settingsReadOnly? | boolean | Make settings read-only (no |
| stores? | Readonly<Record<string, unknown>> | Stored values, by |
FixtureRpcErrorInterface#
An RPC error a scripted method throws: answered as { code: 'rpc', … }.
interface FixtureRpcErrorProperties
| Name | Type | Description |
|---|---|---|
| data? | unknown | Extra detail for the caller. |
| message | string | What went wrong, for a person. |
| type | string | The error's type, as the caller reads it. |
Types#
FixtureCallbackType#
A scripted callback: answers like the extension would, or throws.
type FixtureCallback<K extends ExtensionCallbackId> = (args: ExtensionCallbacks[K]['args']) => ExtensionCallbacks[K]['result'] | Promise<ExtensionCallbacks[K]['result']>Type parameters
| Name | Type | Description |
|---|---|---|
| K | extends ExtensionCallbackId |
FixtureExtensionsCapabilityType#
The optional members a fixture host can leave out.
type FixtureExtensionsCapability =
| 'invoke'
| 'dialogs'
| 'effects'
| 'rpc'
| 'storage'
| 'settings'
| 'integrations'
| 'commands'
| 'panelChanged'FixtureExtensionsHostType#
An in-memory ExtensionsHost and its control.
type FixtureExtensionsHost = ExtensionsHost & { control: FixtureExtensionsControl }FixtureRpcMethodType#
A scripted RPC method. Throw a FixtureRpcError to answer an error.
type FixtureRpcMethod = (input: unknown, ctx: { extensionId?: string }) => unknown