# zidane-ui/views/testing

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

## Functions

### `createFixtureViewsHost`

Function.

`zidane-ui/views/testing`: a `ViewsHost` that runs in memory
(`createFixtureViewsHost`), for docs, demos, galleries and an app's own
tests. Not for production hosts.

```ts
function createFixtureViewsHost(options?: FixtureViewsOptions): FixtureViewsHost
```

**Parameters**

- `options?` (`FixtureViewsOptions`, default `{}`): The stored views, and whether refresh is offered.

**Returns** `FixtureViewsHost`

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

### `createMemorySavedViews`

Function.

Saved views in memory over a backend's stored views. The scope is always
`""`; the key is made from the view's title.

```ts
function createMemorySavedViews(
  viewOf: (sessionId: string, id: string) => StoredView | undefined,
): MemorySavedViews
```

**Parameters**

- `viewOf` (`(sessionId: string, id: string) => StoredView | undefined`): The stored view, or `undefined`.

**Returns** `MemorySavedViews`

Source: [ui/src/views/testing/saved-memory.ts:31](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/saved-memory.ts#L31)

## Interfaces

### `FixtureViewsControl`

Interface.

Changes the stored views from outside, as the host would.

```ts
interface FixtureViewsControl
```

**Properties**

- `add` (`(view: StoredView) => void`): Stores a view (new or replacing) and tells the readers, as `views:changed` does.
- `view` (`(sessionId: string, id: string) => StoredView | undefined`): The stored view, or `undefined`.

Source: [ui/src/views/testing/fixture-host.ts:21](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/fixture-host.ts#L21)

### `FixtureViewsOptions`

Interface.

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

```ts
interface FixtureViewsOptions
```

**Properties**

- `refresh?` (`boolean`): The host can refresh: a refresh marks the view and its sources refreshed now and keeps its tree. `false`: it answers unsupported. Default: true.
- `saved?` (`boolean`): The host saves views (docs/VIEWS-SAVED.md), in memory. Default: false.
- `views?` (`readonly StoredView[]`): The stored views, of any session. Default: none.

Source: [ui/src/views/testing/fixture-host.ts:11](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/fixture-host.ts#L11)

### `MemorySavedViews`

Interface.

The saved members of a views backend, held in memory.

```ts
interface MemorySavedViews
```

**Properties**

- `get` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => SavedViewRecord | null`): One version (no version: the latest), or `null`.
- `list` (`(scope?: string) => SavedViewMeta[]`): The saved views, newest first.
- `remove` (`(scope: string, key: string) => boolean`): Deletes a saved view. `false`: there was none.
- `save` (`(sessionId: string, id: string) => SavedViewMeta | null`): Saves view `(sessionId, id)`: a new version, unless the latest is that view unchanged. `null`: no such view.
- `unsave` (`(sessionId: string, id: string) => boolean`): Deletes the saved view that view saved. `false`: it saved none.
- `versions` (`(scope: string, key: string) => SavedViewVersion[]`): The versions of a saved view, oldest first.

Source: [ui/src/views/testing/saved-memory.ts:10](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/saved-memory.ts#L10)

## Types

### `FixtureViewsHost`

Type.

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

```ts
type FixtureViewsHost = ViewsHost & { control: FixtureViewsControl }
```

Source: [ui/src/views/testing/fixture-host.ts:29](https://github.com/Tahul/zidane/blob/main/ui/src/views/testing/fixture-host.ts#L29)
