# zidane-ui/channels/testing

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

## Functions

### `createFixtureChannelsHost`

Function.

`zidane-ui/channels/testing`: a `ChannelsHost` that runs in memory (`createFixtureChannelsHost`) over the
channels methods as zidane answers them (`createFixtureChannelsMethods`), for docs, demos, galleries and an app's
own tests. Not for production hosts.

```ts
function createFixtureChannelsHost(seed?: FixtureChannelsSeed): FixtureChannelsHost
```

**Parameters**

- `seed?` (`FixtureChannelsSeed`, default `{}`): What it starts with.

**Returns** `FixtureChannelsHost`

Source: [ui/src/channels/headless/fixture-host.ts:487](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L487)

### `createFixtureChannelsMethods`

Function.

`zidane-ui/channels/testing`: a `ChannelsHost` that runs in memory (`createFixtureChannelsHost`) over the
channels methods as zidane answers them (`createFixtureChannelsMethods`), for docs, demos, galleries and an app's
own tests. Not for production hosts.

```ts
function createFixtureChannelsMethods(
  seed?: FixtureChannelsSeed,
): FixtureChannelsMethods
```

**Parameters**

- `seed?` (`FixtureChannelsSeed`, default `{}`): What it starts with.

**Returns** `FixtureChannelsMethods`

Source: [ui/src/channels/headless/fixture-host.ts:162](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L162)

### `fixtureChannelAgent`

Function.

`zidane-ui/channels/testing`: a `ChannelsHost` that runs in memory (`createFixtureChannelsHost`) over the
channels methods as zidane answers them (`createFixtureChannelsMethods`), for docs, demos, galleries and an app's
own tests. Not for production hosts.

```ts
function fixtureChannelAgent(): ChannelAgent
```

**Returns** `ChannelAgent`

Source: [ui/src/channels/headless/fixture-host.ts:102](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L102)

### `fixtureChannelBindings`

Function.

`zidane-ui/channels/testing`: a `ChannelsHost` that runs in memory (`createFixtureChannelsHost`) over the
channels methods as zidane answers them (`createFixtureChannelsMethods`), for docs, demos, galleries and an app's
own tests. Not for production hosts.

```ts
function fixtureChannelBindings(): ChannelBinding[]
```

**Returns** `ChannelBinding[]`

Source: [ui/src/channels/headless/fixture-host.ts:94](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L94)

### `fixtureChannelConnections`

Function.

`zidane-ui/channels/testing`: a `ChannelsHost` that runs in memory (`createFixtureChannelsHost`) over the
channels methods as zidane answers them (`createFixtureChannelsMethods`), for docs, demos, galleries and an app's
own tests. Not for production hosts.

```ts
function fixtureChannelConnections(): ChannelConnection[]
```

**Returns** `ChannelConnection[]`

Source: [ui/src/channels/headless/fixture-host.ts:86](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L86)

## Interfaces

### `FixtureChannelsHost`

Interface.

The fixture's host, with its methods.

```ts
interface FixtureChannelsHost extends ChannelsHostState
```

**Properties**

- `agent?` (`ChannelsAgent`, from `ChannelsHostState`): The org's Agent. Absent: no Agent card and no Agent row.
- `alerts?` (`ChannelsAlerts`, from `ChannelsHostState`): The caller's open channel alerts. Absent: no alerts list.
- `apply` (`(signal: { kind: string }) => void`, from `ChannelsHostState`): A signal of the host: reads again what it touches. Other kinds are ignored.
- `bindings?` (`ChannelsBindings`, from `ChannelsHostState`): A project's bindings (Project settings › Channels). Absent: no Channels section.
- `connections?` (`ChannelsConnections`, from `ChannelsHostState`): The host's connections (Settings › Channels). Absent: no Channels page.
- `defaultProjects` (`Readable<Readonly<Record<string, string | null>>>`, from `ChannelsHostState`): The defaults set from this window, by connection id (`null`: cleared). The host has no read of them.
- `held?` (`ChannelsHeld`, from `ChannelsHostState`): A project's replies the outbound filter held, and their release. Absent: no Held replies list.
- `methods` (`FixtureChannelsMethods`): The methods under it: the provider's side, what it sent.
- `openProject?` (`(projectId: string) => void`, from `ChannelsHostState`): Opens a project of the host (its home): the Agent card's Open project. Absent: no Open project.
- `openSession?` (`(sessionId: string) => void`, from `ChannelsHostState`): Opens a session of the host (a test session). Absent: Test as opens it in the background.
- `openTarget?` (`(target: ReadinessOpenTarget, projectId?: string) => void`, from `ChannelsHostState`): Opens a screen of the app a readiness fix names (Settings › Channels, Linked accounts). The project's own screens
  open its settings in the kit. Absent: those fixes show without a button. `projectId`: the project the fix is
  about (absent for an alert about no project).
- `readiness?` (`ChannelsReadiness`, from `ChannelsHostState`): A project's readiness checklist. Absent: no checklist.
- `setDefaultProject?` (`(connectionId: string, projectId: string | null) => Promise<void>`, from `ChannelsHostState`): Sets (`null`: clears) the caller's default project for a connection's DMs and unbound mentions. Absent: no
  default project rows.
- `testAs?` (`(projectId: string, bindingId: string, as: TestAsKind, identity: { iconUrl?: string; name: string }) => Promise<TestSession>`, from `ChannelsHostState`): Opens a private session with a binding's exact rules for a member or a guest. Absent: no Test as.
  `identity`: how its replies post, kept for the session's Test badge.
- `testSessions` (`Readable<Readonly<Record<string, TestSession>>>`, from `ChannelsHostState`): The test sessions opened in this window, by session id.
- `wake` (`() => void`, from `ChannelsHostState`): Reads again everything read so far (a new connection).

Source: [ui/src/channels/headless/fixture-host.ts:477](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L477)

### `FixtureChannelsMethods`

Interface.

The fixture's methods, with the provider's side and what it sent.

```ts
interface FixtureChannelsMethods extends ChannelsBackend
```

**Properties**

- `call` (`<M extends 'projects.readiness' | 'channels.bindings.testAs' | 'channels.connections.list' | 'channels.connections.get' | 'channels.connections.create' | 'channels.connections.update' | 'channels.connections.remove' | 'channels.connections.status' | 'channels.connections.slackManifest' | 'channels.connections.slackCredentials' | 'channels.connections.slackInstall' | 'channels.connections.githubManifest' | 'channels.bindings.list' | 'channels.runsOn' | 'channels.bindings.put' | 'channels.bindings.remove' | 'channels.bindings.enable' | 'channels.conversations' | 'channels.defaultProject' | 'channels.held.list' | 'channels.held.release' | 'channels.alerts.list' | 'channels.agent.get' | 'channels.agent.set'>(method: M, params: ChannelsParams<M>) => Promise<ChannelsResult<M>>`, from `ChannelsBackend`): Calls a method. Rejects with the host's error (the adapter's own type; `classify` words it).
- `calls` (`{ method: string; params: unknown }[]`): Every call made, in order: method and params.
- `can` (`(method: 'projects.readiness' | 'channels.bindings.testAs' | 'channels.connections.list' | 'channels.connections.get' | 'channels.connections.create' | 'channels.connections.update' | 'channels.connections.remove' | 'channels.connections.status' | 'channels.connections.slackManifest' | 'channels.connections.slackCredentials' | 'channels.connections.slackInstall' | 'channels.connections.githubManifest' | 'channels.bindings.list' | 'channels.runsOn' | 'channels.bindings.put' | 'channels.bindings.remove' | 'channels.bindings.enable' | 'channels.conversations' | 'channels.defaultProject' | 'channels.held.list' | 'channels.held.release' | 'channels.alerts.list' | 'channels.agent.get' | 'channels.agent.set') => boolean`, from `ChannelsBackend`): Whether the host offers a method. A method it does not offer hides what needs it.
- `classify?` (`(err: unknown) => ChannelsError`, from `ChannelsBackend`): Words a rejection. Default: `failed` with its message.
- `clearAlert` (`(id: string) => void`): An alert clears on recovery (`channels:alert` with `cleared`).
- `completeGithubManifest` (`(connectionId: string, slug?: string) => void`): GitHub's manifest flow came back: the connection holds its App's key and runs.
- `completeSlackInstall` (`(connectionId: string, teamName?: string, teamId?: string) => void`): Slack's OAuth page came back: the connection holds a bot token and runs. One that replaces another takes its
  bindings: all of them in the same workspace (`teamId`, default `T1`, the default app's), else its direct messages
  and mentions, its channels becoming drafts; the old one goes.
- `defaults` (`Map<string, string | null>`): The defaults people set, by connection id.
- `onSignal` (`(listener: (signal: ChannelsSignal) => void) => () => void`): Calls `listener` with every signal a change sends. Returns the unsubscribe.
- `openAlert` (`(alert: ChannelAlert) => void`): An alert opens for the caller (`channels:alert`), or opens again with new words (same id).
- `publicUrl?` (`boolean`, from `ChannelsBackend`): The host serves https webhooks at a public URL, so a Slack app can use HTTP instead of Socket Mode. Default false.
- `runFix?` (`(method: string, params: Record<string, unknown>) => Promise<unknown>`, from `ChannelsBackend`): Calls the method a readiness fix names (`fix.kind === 'method'`): any method of the host, checked there like any
  other call. Absent: method fixes are not offered.
- `setReadiness` (`(projectId: string, items: readonly ReadinessItem[]) => void`): Replaces a project's extra readiness items, and says so (`projects:readiness`).
- `setState` (`(state: ConnectionLiveState) => void`): A connection's live state changes (`channels:status`).

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

### `FixtureChannelsProject`

Interface.

A project the fixture knows: its id and name.

```ts
interface FixtureChannelsProject
```

**Properties**

- `id` (`string`): Its id.
- `name` (`string`): Its name.

Source: [ui/src/channels/headless/fixture-host.ts:15](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L15)

### `FixtureChannelsSeed`

Interface.

What a fixture starts with.

```ts
interface FixtureChannelsSeed
```

**Properties**

- `agent?` (`ChannelAgent | null`): The org's Agent (`fixtureChannelAgent`); its project joins `projects` when they lack it. Default none (`null`).
- `alerts?` (`readonly ChannelAlert[]`): The caller's open alerts (`channels.alerts.list`). Default none.
- `bindings?` (`readonly ChannelBinding[]`): The bindings. Default: `p-app` on `#ops` through `acme`, and a draft of `p-app`'s from a published project; with an
  `agent`, its direct messages and mentions through `acme` too.
- `connections?` (`readonly ChannelConnection[]`): The connections. Default: `acme` (Slack, ready) and `acme-github` (GitHub, pending).
- `conversations?` (`Readonly<Record<string, readonly Omit<ChannelConversation, 'boundBy'>[]>>`): The Slack channels each connection's app is in. Default: `#ops`, `#general`, `#secret` (private) for `acme`.
- `held?` (`readonly HeldPost[]`): The replies the outbound filter held (`channels.held.list`). Default none.
- `projects?` (`readonly FixtureChannelsProject[]`): The projects. Default `p-app` (App) and `p-api` (API).
- `publicUrl?` (`boolean`): The host serves a public URL (Slack's HTTP transport). Default false.
- `readiness?` (`Readonly<Record<string, readonly ReadinessItem[]>>`): Items each project's checklist adds to the ones the fixture computes.
- `without?` (`readonly ('projects.readiness' | 'channels.bindings.testAs' | 'channels.connections.list' | 'channels.connections.get' | 'channels.connections.create' | 'channels.connections.update' | 'channels.connections.remove' | 'channels.connections.status' | 'channels.connections.slackManifest' | 'channels.connections.slackCredentials' | 'channels.connections.slackInstall' | 'channels.connections.githubManifest' | 'channels.bindings.list' | 'channels.runsOn' | 'channels.bindings.put' | 'channels.bindings.remove' | 'channels.bindings.enable' | 'channels.conversations' | 'channels.defaultProject' | 'channels.held.list' | 'channels.held.release' | 'channels.alerts.list' | 'channels.agent.get' | 'channels.agent.set')[]`): Methods to leave out, so a test can check what hides without them.

Source: [ui/src/channels/headless/fixture-host.ts:23](https://github.com/Tahul/zidane/blob/main/ui/src/channels/headless/fixture-host.ts#L23)
