# FakeSearchProvider

A scripted [`SearchProvider`](https://docs.mapcairn.com/api/core/SearchProvider.md) with no network and no timers.

This is a class exported by `@mapcairn/core`, checked against version 0.2.0.

## Signature

```ts
import { FakeSearchProvider } from "@mapcairn/core";
 
class FakeSearchProvider implements SearchProvider
```

## Description

How to script it:
- `setResults(query, results)` answers one query; `setDefaultResults`
 answers every other query (empty by default). Queries are matched after
 trimming.
- `setReverseResult(result | null)` answers every `reverse` call.
- `failWith(kind)` makes every call reject with a `SearchError` until
 `clearFailure()`.
- `holdNext()` keeps the next `search` or `reverse` call pending until the
 returned handle resolves or rejects it. Holds queue in order.
- A blank query resolves to an empty array without using any script.
- Every call honours its `AbortSignal` by rejecting with `PortAbortError`.
- `searchCalls` and `reverseCalls` record what the ui asked.

## Properties

### reverseCalls

```ts
readonly reverseCalls: RecordedReverseCall[];
```

Every `reverse` call, in order, with its position and options.

### searchCalls

```ts
readonly searchCalls: RecordedSearchCall[];
```

Every `search` call, in order, with its query and options.

## Methods

### clearFailure

```ts
clearFailure(): void;
```

Stops [`FakeSearchProvider`](https://docs.mapcairn.com/api/core/FakeSearchProvider.md) failing calls.

### failWith

```ts
failWith(kind: SearchErrorKind): void;
```

Makes every later call reject with a `SearchError` of this kind.

- `kind` (`SearchErrorKind`)

### holdNext

```ts
holdNext(): HeldSearchCall;
```

Holds the next call (search or reverse) until the handle settles it.

### reverse

```ts
reverse(position: LatLng, options?: Pick<SearchOptions, "signal">): Promise<SearchResult | null>;
```

Answers with the scripted reverse result, or `null`.

- `position` (`LatLng`)
- `options?` (`Pick<SearchOptions, "signal">`)

### search

```ts
search(query: string, options?: SearchOptions): Promise<readonly SearchResult[]>;
```

Answers with the results scripted for the trimmed query, or the default results. A blank query resolves to an empty list without using any script.

- `query` (`string`)
- `options?` (`SearchOptions`)

### setDefaultResults

```ts
setDefaultResults(results: readonly SearchResult[]): void;
```

Answers every query that has no specific script.

- `results` (`readonly SearchResult[]`)

### setResults

```ts
setResults(query: string, results: readonly SearchResult[]): void;
```

Answers searches for `query` (trimmed) with `results`.

- `query` (`string`)
- `results` (`readonly SearchResult[]`)

### setReverseResult

```ts
setReverseResult(result: SearchResult | null): void;
```

Sets what `reverse` finds. `null` means there is no place there.

- `result` (`SearchResult | null`)

## See also

- [`SearchProvider`](https://docs.mapcairn.com/api/core/SearchProvider.md)
- [`SearchErrorKind`](https://docs.mapcairn.com/api/core/SearchErrorKind.md)
- [`HeldSearchCall`](https://docs.mapcairn.com/api/core/HeldSearchCall.md)
- [`LatLng`](https://docs.mapcairn.com/api/core/LatLng.md)
- [`SearchOptions`](https://docs.mapcairn.com/api/core/SearchOptions.md)
- [`SearchResult`](https://docs.mapcairn.com/api/core/SearchResult.md)
- [`RecordedReverseCall`](https://docs.mapcairn.com/api/core/RecordedReverseCall.md)
- [`RecordedSearchCall`](https://docs.mapcairn.com/api/core/RecordedSearchCall.md)

Source: [packages/core/src/fakes/FakeSearchProvider.ts:56](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeSearchProvider.ts#L56)
