# zidane-ui/extensions/testing

Import: `import { … } from 'zidane-ui/extensions/testing'`. Source: [ui/src/extensions/testing/index.ts](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/testing/index.ts).

## Functions

### `createFixtureExtensionsHost`

Function.

Creates an [`ExtensionsHost`](https://zidane.si/docs/reference/ui-extensions-headless.md#ExtensionsHost) held in memory.

```ts
function createFixtureExtensionsHost(
  options?: FixtureExtensionsOptions,
): FixtureExtensionsHost
```

**Parameters**

- `options?` (`FixtureExtensionsOptions`, default `{}`): What it holds and which members it offers.

**Returns** `FixtureExtensionsHost`

Source: [ui/src/extensions/headless/fixture-host.ts:138](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L138)

### `fixtureItem`

Function.

Builds an item for a fixture: `key` defaults to `<token>:<extension>:<n>`.

```ts
function fixtureItem<N extends keyof ExtensionWireMap>(
  token: N,
  extension: string,
  item: ExtensionWireMap[N],
  key?: string,
): ExtensionItem<N>
```

**Type parameters**

- `N` (`extends keyof ExtensionWireMap`)

**Parameters**

- `token` (`N`): The token.
- `extension` (`string`): The contributing extension.
- `item` (`ExtensionWireMap[N]`): The wire form.
- `key?` (`string`): The item's key.

**Returns** `ExtensionItem<N>`

Source: [ui/src/extensions/headless/fixture-host.ts:374](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L374)

### `storeKey`

Function.

The key of a store in `FixtureExtensionsOptions.stores`.

```ts
function storeKey(ref: ExtensionStoreRef): string
```

**Parameters**

- `ref` (`ExtensionStoreRef`): The store.

**Returns** `string`

Source: [ui/src/extensions/headless/fixture-host.ts:120](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L120)

## Interfaces

### `FixtureExtensionsControl`

Interface.

Drives a fixture host from outside, as the extensions behind it would.

```ts
interface FixtureExtensionsControl
```

**Properties**

- `dialog` (`(request: DialogRequest, ctx: DialogQueueShowContext) => Promise<unknown>`): Asks this client for a dialog; resolves with the answer.
- `effect` (`(effect: ExtensionUiEffect) => Promise<ExtensionUiEffectResult>`): Routes a `ctx.ui` / `ctx.composer` call to this client; resolves with what the app settled.
- `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 `subscribe` emitted): `panelChanged` listeners hear it.
- `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 `scope` given).
- `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.

Source: [ui/src/extensions/headless/fixture-host.ts:85](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L85)

### `FixtureExtensionsOptions`

Interface.

Options of [`createFixtureExtensionsHost`](https://zidane.si/docs/reference/ui-extensions-testing.md#createFixtureExtensionsHost).

```ts
interface FixtureExtensionsOptions
```

**Properties**

- `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 `unavailable`.
- `capabilities?` (`readonly FixtureExtensionsCapability[]`): Offer only these optional members. Default: all of them.
- `commands?` (`readonly ExtensionCommandWire[]`): The commands. Default: none.
- `goodKey?` (`string`): The API key `connect` accepts; any other is refused. Default `'good-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 `openLink` (links open the app's way).
- `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 `scope` (never limited).
- `settings?` (`ExtensionSettingsWire`): The settings. Default: none.
- `settingsReadOnly?` (`boolean`): Make settings read-only (no `settings.set`).
- `stores?` (`Readonly<Record<string, unknown>>`): Stored values, by [`storeKey`](https://zidane.si/docs/reference/ui-extensions-testing.md#storeKey).

Source: [ui/src/extensions/headless/fixture-host.ts:57](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L57)

### `FixtureRpcError`

Interface.

An RPC error a scripted method throws: answered as `{ code: 'rpc', … }`.

```ts
interface FixtureRpcError
```

**Properties**

- `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.

Source: [ui/src/extensions/headless/fixture-host.ts:40](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L40)

## Types

### `FixtureCallback`

Type.

A scripted callback: answers like the extension would, or throws.

```ts
type FixtureCallback<K extends ExtensionCallbackId> = (args: ExtensionCallbacks[K]['args']) => ExtensionCallbacks[K]['result'] | Promise<ExtensionCallbacks[K]['result']>
```

**Type parameters**

- `K` (`extends ExtensionCallbackId`)

Source: [ui/src/extensions/headless/fixture-host.ts:35](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L35)

### `FixtureExtensionsCapability`

Type.

The optional members a fixture host can leave out.

```ts
type FixtureExtensionsCapability =
  | 'invoke'
  | 'dialogs'
  | 'effects'
  | 'rpc'
  | 'storage'
  | 'settings'
  | 'integrations'
  | 'commands'
  | 'panelChanged'
```

Source: [ui/src/extensions/headless/fixture-host.ts:53](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L53)

### `FixtureExtensionsHost`

Type.

An in-memory [`ExtensionsHost`](https://zidane.si/docs/reference/ui-extensions-headless.md#ExtensionsHost) and its control.

```ts
type FixtureExtensionsHost = ExtensionsHost & { control: FixtureExtensionsControl }
```

Source: [ui/src/extensions/headless/fixture-host.ts:113](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L113)

### `FixtureRpcMethod`

Type.

A scripted RPC method. Throw a [`FixtureRpcError`](https://zidane.si/docs/reference/ui-extensions-testing.md#FixtureRpcError) to answer an error.

```ts
type FixtureRpcMethod = (input: unknown, ctx: { extensionId?: string }) => unknown
```

Source: [ui/src/extensions/headless/fixture-host.ts:50](https://github.com/Tahul/zidane/blob/main/ui/src/extensions/headless/fixture-host.ts#L50)
