Skip to main content

FakeRoutingProvider

A scripted RoutingProvider with no network and no timers.

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

Signature​

import { FakeRoutingProvider } from "@mapcairn/core";

class FakeRoutingProvider implements RoutingProvider

Description​

How to script it:

  • With no script, route joins the stops with a straight line for each leg, measured in metres, and works out the time from a speed for the mode (50, 15 and 5 kilometres an hour). reachableArea draws a ring around the origin as far as that speed goes in the minutes given.
  • setRoute(result) and setReachableArea(result) answer every later request with that result; null goes back to the default.
  • setSupportedModes(modes) makes any other mode reject as unsupported.
  • failWith(kind) makes every request reject with a RoutingError until clearFailure().
  • holdNextRoute() and holdNextReachableArea() keep the next request of that kind pending until the returned handle resolves or rejects it. Holds queue in order.
  • A request is checked first: fewer than two stops, a position off the globe or minutes that are not greater than zero reject as invalid, and a mode the fake does not offer rejects as unsupported. The check comes before any hold or failure, so a bad request never uses a script.
  • Every request honours its AbortSignal by rejecting with a RoutingError of kind aborted.
  • routeCalls and reachableAreaCalls record what the ui asked.

Properties​

reachableAreaCalls​

readonly reachableAreaCalls: ReachableAreaRequest[];

Every reachableArea request, in order, including ones that were refused.

routeCalls​

readonly routeCalls: RouteRequest[];

Every route request, in order, including ones that were refused.

Methods​

clearFailure​

clearFailure(): void;

Stops FakeRoutingProvider failing requests.

failWith​

failWith(kind: FakeRoutingFailure): void;

Makes every later request reject with a RoutingError of this kind.

  • kind (FakeRoutingFailure)

holdNextReachableArea​

holdNextReachableArea(): HeldReachableAreaCall;

Holds the next reachableArea request until the handle settles it.

holdNextRoute​

holdNextRoute(): HeldRouteCall;

Holds the next route request until the handle settles it.

reachableArea​

reachableArea(request: ReachableAreaRequest): Promise<ReachableAreaResult>;

Checks the request, then answers with the scripted result, a ring around the origin, a held or failed request, or an aborted error.

  • request (ReachableAreaRequest)

route​

route(request: RouteRequest): Promise<RouteResult>;

Checks the request, then answers with the scripted result, a straight-line route with a time from a speed for the mode, a held or failed request, or an aborted error.

  • request (RouteRequest)

setReachableArea​

setReachableArea(result: ReachableAreaResult | null): void;

Answers every later reachableArea with result. null restores the default.

  • result (ReachableAreaResult | null)

setRoute​

setRoute(result: RouteResult | null): void;

Answers every later route with result. null restores the default.

  • result (RouteResult | null)

setSupportedModes​

setSupportedModes(modes: readonly TravelMode[]): void;

Limits the modes the fake offers. Any other mode rejects as unsupported.

  • modes (readonly TravelMode[])

See also​

Source: packages/core/src/fakes/FakeRoutingProvider.ts:74