Mock SDK
Method signature
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 excepttype
. Defines the current network. For assets of type “Pipe”, “Pump”, or “Valve”, include a list of connected assets IDs withconnections: string[]
.zones: Zones
Optional. Array of objects with Zone properties.simulationMode: 'simulate' | 'fakeresults' | 'noresults'
Optional. Controls simulation calculation. Iffakeresults
, 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 forsimulation.isSupplied
, which is always updated). This is the default mode and suggested if it covers your test case. Ifsimulate
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. Ifnoresults
, 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 Qatiumsdk.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:
Controlling the state: