# zidane-ui/keybindings/testing/contract

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

## Functions

### `describeKeybindingsHostContract`

Function.

Declares the shared `KeybindingsHost` suite for one implementation.

```ts
function describeKeybindingsHostContract(
  name: string,
  makeHarness: KeybindingsHostHarnessFactory,
  capabilities: readonly KeybindingsHostCapability[],
): void
```

**Parameters**

- `name` (`string`): The implementation's name, shown in the suite title.
- `makeHarness` (`KeybindingsHostHarnessFactory`): Builds a fresh host over a backend that holds what it is given, once per test.
- `capabilities` (`readonly KeybindingsHostCapability[]`): The optional members the host offers. Every other optional member must be undefined.

Source: [ui/src/keybindings/testing/contract.ts:65](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L65)

## Interfaces

### `KeybindingsHostContractBackend`

Interface.

What the backend behind the host holds.

```ts
interface KeybindingsHostContractBackend
```

**Properties**

- `stored` (`Readonly<Record<string, string>> | null`): The stored overrides (action → spec, unknown actions and empty specs included), or `null`: none stored.

Source: [ui/src/keybindings/testing/contract.ts:28](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L28)

### `KeybindingsHostContractControl`

Interface.

Reads the backend and changes it from outside.

```ts
interface KeybindingsHostContractControl
```

**Properties**

- `store` (`(overrides: Readonly<Record<string, string>> | null) => void`): The user edited the stored overrides (`null` removes them). The host reads them on its next `refresh`.
- `stored` (`() => Readonly<Record<string, string>> | null`): The overrides stored now, or `null`.

Source: [ui/src/keybindings/testing/contract.ts:34](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L34)

### `KeybindingsHostHarness`

Interface.

A host built over a backend, the backend's control, and how to tear them down.

```ts
interface KeybindingsHostHarness
```

**Properties**

- `control` (`KeybindingsHostContractControl`): Reads and changes the backend.
- `host` (`KeybindingsHost`): The host under test.
- `dispose?` (`() => void`): Closes listeners after each test.

Source: [ui/src/keybindings/testing/contract.ts:42](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L42)

## Types

### `KeybindingsHostCapability`

Type.

An optional `KeybindingsHost` member.

```ts
type KeybindingsHostCapability = 'save' | 'openInEditor' | 'location'
```

Source: [ui/src/keybindings/testing/contract.ts:23](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L23)

### `KeybindingsHostHarnessFactory`

Type.

Builds a fresh host (and its backend) for one test.

```ts
type KeybindingsHostHarnessFactory = (backend: KeybindingsHostContractBackend) => KeybindingsHostHarness | Promise<KeybindingsHostHarness>
```

Source: [ui/src/keybindings/testing/contract.ts:52](https://github.com/Tahul/zidane/blob/main/ui/src/keybindings/testing/contract.ts#L52)
