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?: AssetWithConnections[],
zones?: ZoneDescriptor[],
simulationMode?: string,
}): 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: AssetWithConnections[] Optional. Array of assets defining the current network. For assets of type “Pipe”, “Pump”, or “Valve”, include a list of connected assets IDs with connections: string[]. Helpers are recommended to build network assets.
  • zones: ZoneDescriptor[] Optional. Array of objects with Zone properties. Zone descriptors can be build using a helper.
  • simulationMode: 'simulate' | 'fakeresults' | 'noresults' Optional. Controls simulation calculation. If fakeresults, simulation results specified on network assets 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 its functions are jest Mock Functions, which means you can easily change how they work or test how they’re 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.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.isMapView() => true
  • sdk.isSynopticView() => false
  • sdk.isPanelOpen() => true
  • sdk.isPluginVisible() => true

Examples

Working with a network:

import { aSupplySource, aJunction, aPipe, mockSDK } from "@qatium/sdk-testing-library";
const network = [
aSupplySource({
id: "S1"
}),
aPipe({
id: "P1",
connections: ["S1", "J1"],
simulation: {
status: "OPEN"
}
}),
aJunction({
id: "J1",
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