Skip to content
We're currently creating a lot of content. Sign up to get notified when it's ready.

Mock SDK

Method signature

mockSDK({
network?: Network,
zones?: Zones,
simulationMode?: 'simulate' | 'fakeresults' | 'noresults',
}): SDK

Constructs a mock that mimics the behavior of the Qatium SDK. A network state is maintained for using network queries and is updated when using functions that manipulate the network.

Parameters

Object that accepts:

  • network: Network Optional. Array of assets with all properties being optional except type. Defines the current network. For assets of type “Pipe”, “Pump”, or “Valve”, include a list of connected assets IDs with connections: string[].
  • zones: Zones Optional. Array of objects with Zone properties.
  • simulationMode: 'simulate' | 'fakeresults' | 'noresults' Optional. Controls simulation calculation. If fakeresults, simulation results specified on network asset will be used, using network actions that update the simulation of one asset won’t reflect side effects on the rest (except for simulation.isSupplied, which is always updated). This is the default mode and suggested if it covers your test case. If simulate the mock will run a real simulation, this is more accurate and reflects changes on all assets, however, it is slower and defining the situation you need is more difficult. If noresults, all assets simulation results will be undefined, this is useful for testing cases where no simulation has completed yet or simulation has errors.

Returns

An object implementing the SDK interface, all of it’s functions are jest Mock Functions, which means you can change how they work or test when and how they’re were used.

Queries and actions in the network that rely on assets will use an internal state to provide a realistic result. For other queries, here are the default behaviors:

Network Queries
  • sdk.network.isScenarioActive() => false
  • sdk.network.isSimulationLoading() => false
  • sdk.network.isSimulationPeriodCompleted() => true
  • sdk.network.isSimulationError() => false
  • sdk.network.getMetadata() => { id: "12345678-1234-1234-1234-123456789abc", name: "Test network", secret: { sessionToken: "abcd" } }
  • sdk.network.getUnits() => International default units of Qatium
  • sdk.network.getBounds() => { sw: { lat: -180, lng: -180 }, ne: { lat: 180, lng: 180 } }
  • sdk.network.getTime() => { time: new Date("2024-01-01T08:00:00"), timezone: "UTC" }
  • sdk.network.getStartTime() => { time: new Date("2024-01-01T00:00:00.000Z"), timezone: "UTC" }
Map Queries
  • sdk.map.getCamera() => { zoom: 10, pitch: 0, bearing: 0, center: { lat: 0, lng: 0 } }
  • sdk.map.getSelectedElement() => undefined
UI Queries
  • sdk.ui.isMapView() => true
  • sdk.ui.isSynopticView() => false
  • sdk.ui.isPanelOpen() => true
  • sdk.ui.isPluginVisible() => true
  • sdk.ui.isNetworkLevelVisible() => true
  • sdk.ui.isMapLayerVisible() => true
  • sdk.ui.getLanguage() => 'en'

Examples

Working with a network:

import { aSupplySource, aJunction, aPipe, mockSDK } from "@qatium/sdk-testing-library";
const network = [
{
id: "S1",
type: "SupplySource"
},
{
id: "P1",
type: "Pipe",
connections: ["S1", "J1"],
simulation: {
status: "OPEN"
}
},
{
id: "J1",
type: "Junction",
simulation: {
demand: 10,
pressure: 20
}
}
]
const sdk = mockSDK({ network })
sdk.network.getAsset("J1").simulation // { isSupplied: true, demand: 10, pressure: 20, waterAge: undefined }
sdk.network.setStatus("P1", "CLOSED")
sdk.network.getPipes()[0].simulation.status // "CLOSED"
sdk.network.getAsset("J1").simulation.isSupplied // false

Controlling the state:

import { mockSDK } from "@qatium/sdk-testing-library";
const sdk = mockSDK({})
sdk.network.isSimulationLoading() // false by default
sdk.network.isSimulationLoading.mockReturnValue(true)
sdk.network.isSimulationLoading() // true