# zidane-ui/views/testing/contract

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

## Functions

### `contractView`

Function.

A stored view of the suite's backends.

```ts
function contractView(sessionId: string, id: string, createdAt: number): StoredView
```

**Parameters**

- `sessionId` (`string`): The view's session.
- `id` (`string`): The view's id.
- `createdAt` (`number`): When the view was made, in milliseconds.

**Returns** `StoredView`

Source: [ui/src/views/testing/contract.ts:97](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L97)

### `describeViewsHostContract`

Function.

Declares the shared `ViewsHost` suite for one implementation.

```ts
function describeViewsHostContract(
  name: string,
  makeHarness: ViewsHostHarnessFactory,
  capabilities: readonly ViewsHostCapability[],
): void
```

**Parameters**

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

Source: [ui/src/views/testing/contract.ts:132](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L132)

## Interfaces

### `ViewsHostContractBackend`

Interface.

What the backend behind the host holds.

```ts
interface ViewsHostContractBackend
```

**Properties**

- `refresh` (`boolean`): The host can refresh views.
- `views` (`readonly StoredView[]`): The stored views, of any session.

Source: [ui/src/views/testing/contract.ts:58](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L58)

### `ViewsHostContractControl`

Interface.

Reads the backend and changes it from outside.

```ts
interface ViewsHostContractControl
```

**Properties**

- `add` (`(view: StoredView) => void`): The host stored a view (a turn ended) and sent `views:changed`.
- `problems?` (`(sessionId: string, id: string) => readonly ViewProblem[]`): The problems the backend got for a view, in order. Needed with `reportProblem`.
- `view` (`(sessionId: string, id: string) => StoredView | undefined`): The view stored now, or `undefined`.

Source: [ui/src/views/testing/contract.ts:66](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L66)

### `ViewsHostHarness`

Interface.

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

```ts
interface ViewsHostHarness
```

**Properties**

- `control` (`ViewsHostContractControl`): Reads and changes the backend from outside.
- `dispose?` (`() => void`): Tears down the host and its backend.
- `host` (`ViewsHost`): The host under test.

Source: [ui/src/views/testing/contract.ts:76](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L76)

## Types

### `ViewsHostCapability`

Type.

An optional `ViewsHost` member.

```ts
type ViewsHostCapability =
  | 'meta'
  | 'get'
  | 'setHeights'
  | 'refresh'
  | 'subscribe'
  | 'customFrame'
  | 'reportProblem'
  | 'saved'
```

Source: [ui/src/views/testing/contract.ts:38](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L38)

### `ViewsHostHarnessFactory`

Type.

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

```ts
type ViewsHostHarnessFactory = (backend: ViewsHostContractBackend) => ViewsHostHarness | Promise<ViewsHostHarness>
```

Source: [ui/src/views/testing/contract.ts:86](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/contract.ts#L86)
