# zidane-ui/files/testing

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

## Functions

### `createFixtureFilesHost`

Function.

An in-memory [`FilesHost`](https://zidane.si/docs/reference/ui-files-headless.md#FilesHost): list, read, write (version-guarded), search, git status, the working-tree diff,
watch and editor preferences. No diagnostics, language servers, system actions or media addresses.

```ts
function createFixtureFilesHost(options?: FixtureFilesHostOptions): FixtureFilesHost
```

**Parameters**

- `options?` (`FixtureFilesHostOptions`, default `{}`): The files, the git status and the patches it starts with.

**Returns** `FixtureFilesHost`

Source: [ui/src/files/headless/fixture-host.ts:164](https://github.com/Tahul/zidane/blob/main/ui/src/files/headless/fixture-host.ts#L164)

### `memoryEntryPort`

Function.

An `EntryPort` over the fixture's memory: files by path, made folders, a version clock. Also a fake backend's (tests).

```ts
function memoryEntryPort(
  files: Map<string, { text: string; version: number }>,
  dirs: Set<string>,
  tick: () => number,
): EntryPort
```

**Parameters**

- `files` (`Map<string, { text: string; version: number }>`): The files, by path, with their text and version.
- `dirs` (`Set<string>`): The folders made with no file in them yet.
- `tick` (`() => number`): The next version number.

**Returns** `EntryPort`

Source: [ui/src/files/headless/fixture-host.ts:82](https://github.com/Tahul/zidane/blob/main/ui/src/files/headless/fixture-host.ts#L82)

## Constants

### `DEMO_FILES`

Constant.

The demo folder's files, its git status and its working-tree patches.

```ts
const DEMO_FILES: Required<FixtureFilesHostOptions>
```

Source: [ui/src/files/testing/demo.ts:8](https://github.com/Tahul/zidane/blob/main/ui/src/files/testing/demo.ts#L8)

## Interfaces

### `FixtureFilesControl`

Interface.

Changes the fixture from outside.

```ts
interface FixtureFilesControl
```

**Properties**

- `edit` (`(path: string, text: string) => void`): Another writer changed (or created) a file: its version moves.
- `emptyDirs` (`() => string[]`): The empty folders now.
- `file` (`(path: string) => string | undefined`): A file's text now, or `undefined`.
- `setDiff` (`(diff: string) => void`): Sets the working-tree patch.
- `setStatus` (`(status: readonly GitStatusEntry[]) => void`): Sets the git status.
- `touch` (`(why?: FolderChange) => void`): The folder may have changed: every watcher hears `why`.

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

### `FixtureFilesHostOptions`

Interface.

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

```ts
interface FixtureFilesHostOptions
```

**Properties**

- `diff?` (`string`): Its working tree against HEAD, as a unified patch. Default: empty.
- `fileDiffs?` (`Readonly<Record<string, string>>`): Per-file patches for `workingTreeDiff({ path })`. Default: none (an empty patch).
- `files?` (`Readonly<Record<string, string>>`): The folder's text files, by path relative to it.
- `status?` (`readonly GitStatusEntry[]`): Its git status. Default: none.

Source: [ui/src/files/headless/fixture-host.ts:26](https://github.com/Tahul/zidane/blob/main/ui/src/files/headless/fixture-host.ts#L26)

## Types

### `FixtureFilesHost`

Type.

The fixture host, with its [`FixtureFilesControl`](https://zidane.si/docs/reference/ui-files-testing.md#FixtureFilesControl).

```ts
type FixtureFilesHost = FilesHost & { control: FixtureFilesControl }
```

Source: [ui/src/files/headless/fixture-host.ts:54](https://github.com/Tahul/zidane/blob/main/ui/src/files/headless/fixture-host.ts#L54)
