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

Building test networks

When testing your plugin code, you may want to test out your code with different scenarios to check that everything works as expected for different networks.

In the Qatium testing library we created some helper utilities to create your own networks. This section will guide you on how to build test networks, the available helpers and example networks ready to use.

A simple network

For Qatium’s testing library, a network is an array of assets connected with each other. Let’s say for example we want to create the following network:

Example network #1

In this network we have a Supply Source SS1, connected to a Junction J1 with a Valve V1 in between connected with two Pipes P1, P2.

So, in order to create this network we can do the following:

const network = [
aSupplySource({
id: "SS1",
}),
aPipe({
id: "P1",
connections: ["SS1", "V1"]
}),
aValve({
id: "V1",
connections: ["P1", "P2"]
}),
aPipe({
id: "P2",
connections: ["V1", "J1"]
}),
aJunction({
id: "J1",
})
]

As you can see we defined all the assets in our network with their connections between them.

Build helpers

Networks in Qatium may consist of these types of assets:

With the testing library you can create all of them using a conventional API. This common API makes it easy to create new network elements providing many default values that can be overridden. You can check all the properties that can be overriden in the assets page.

Netwoks that can not be simulated

When instantiating a mocked SDK using the mockSDK API we can pass a network and a simulation mode. If we choose to simulate mockSDK({ network, simulationMode: "simulate" }) we will run an actual simulation of the network. It may happen that we build a network that does not have a proper simulation result.

So, imagine we want to test out a network with just a Junction:

const network = [
aJunction({
id: "J1",
})
]
const sdk = mockSDK({ network, simulationMode: "simulate" })

We will get the following error: no tanks or reservoirs in network.

So, if you want to test out this network, you have two options:

  1. Fix the network for it to simulate correctly. For instance, adding a Supply Source and a pipe connected to the junction.
  2. Use a different simulation mode.

Example networks

In addition to building your own networks, you can use some of the example networks built in the SDK testing library. All example networks can be used in both simulation and non-simulation test modes, and let you test many use cases for your plugin.

To access them, import the ExampleNetworks object from your test as in this example:

import { mockSDK, ExampleNetworks } from "@qatium/sdk-testing-library";
describe("MyPlugin", () => {
it("uses an example network", () => {
const sdk = mockSDK({ network: ExampleNetworks.withMultipleTanks });
expect(sdk.network.getAsset("T1")).toBeDefined();
});
});

Here’s the list of example networks available in the SDK testing library:

ExampleNetwork.withAllAssets

Example network #1

ExampleNetwork.withValves

Example network #2

ExampleNetwork.withLoopingPipes

Example network #3

ExampleNetwork.withMultipleTanks

Example network #4