Skip to content

Commit f908d2d

Browse files
Merge pull request #105 from ISISComputingGroup/ticket103
fix some wrong runinfo pvs
2 parents fc096dc + 77574d0 commit f908d2d

File tree

12 files changed

+498
-358
lines changed

12 files changed

+498
-358
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@ To build and start in prod mode, use:
6262
#### Container approach
6363

6464
To run dev mode in containerd instead, run `nerdctl compose -f compose.yaml up`. This will mount your current directory as a volume in the container which means any changes will make nextjs re-compile pages. This also means that anything in the `dotenv` files are picked up, including the PVWS URL.
65-
66-
### Building
67-
68-
For a production build, run `npm run build`. To start this build natively, use `npm run start`.

app/components/Instrument.test.ts

Lines changed: 167 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
import { findPVInDashboard } from "@/app/components/Instrument";
2-
import { DashboardArr, IfcPV } from "@/app/types";
1+
import {
2+
CSSB,
3+
findPVInDashboard,
4+
findPVInGroups,
5+
getGroupsWithBlocksFromConfigOutput,
6+
RC_ENABLE,
7+
RC_INRANGE,
8+
SP_RBV,
9+
storePrecision,
10+
subscribeToBlockPVs,
11+
toPrecision,
12+
yesToBoolean,
13+
} from "@/app/components/Instrument";
14+
import {
15+
ConfigOutput,
16+
DashboardArr,
17+
IfcBlock,
18+
IfcGroup,
19+
IfcPV,
20+
IfcPVWSMessage,
21+
IfcPVWSRequest,
22+
PVWSRequestType,
23+
} from "@/app/types";
324

425
test("findPVinDashboard finds a pv in the dashboard and returns it", () => {
526
const prefix = "UNITTESTING";
@@ -69,3 +90,147 @@ test("findPVinDashboard does not find a PV in the dashboard and returns undefine
6990
const result = findPVInDashboard(dashboard, pvToTestFor.pvaddress);
7091
expect(result).toBe(undefined);
7192
});
93+
94+
test("findPVInGroups returns a block when it finds one", () => {
95+
const blockName = "blockName";
96+
const prefix = "IN:INSTRUMENT";
97+
const groups: Array<IfcGroup> = [
98+
{
99+
name: "aGroup",
100+
blocks: [
101+
{
102+
human_readable_name: blockName,
103+
pvaddress: "some:underlying:pv:name",
104+
},
105+
],
106+
},
107+
];
108+
109+
findPVInGroups(groups, prefix, prefix + CSSB + blockName);
110+
});
111+
112+
test("subscribeToBlockPVs subscribes to all run control PVs", () => {
113+
const mockSendJsonMessage = jest.fn();
114+
const aBlock = "INST:CS:SB:SomeBlock";
115+
subscribeToBlockPVs(mockSendJsonMessage, aBlock);
116+
expect(mockSendJsonMessage.mock.calls.length).toBe(1);
117+
const expectedCall: IfcPVWSRequest = {
118+
type: PVWSRequestType.subscribe,
119+
pvs: [aBlock, aBlock + RC_ENABLE, aBlock + RC_INRANGE, aBlock + SP_RBV],
120+
};
121+
expect(JSON.stringify(mockSendJsonMessage.mock.calls[0][0])).toBe(
122+
JSON.stringify(expectedCall),
123+
);
124+
});
125+
126+
test("toPrecision does nothing to string value ", () => {
127+
const expectedValue = "untouched";
128+
const aBlock: IfcBlock = {
129+
pvaddress: "SOME:BLOCK:STR",
130+
value: expectedValue,
131+
};
132+
expect(toPrecision(aBlock, expectedValue)).toBe(expectedValue);
133+
});
134+
135+
test("toPrecision does nothing to block without pv ", () => {
136+
const expectedValue = 0.00123456;
137+
const aBlock: IfcBlock = {
138+
pvaddress: "SOME:BLOCK:STR",
139+
value: expectedValue,
140+
};
141+
expect(toPrecision(aBlock, expectedValue)).toBe(expectedValue);
142+
});
143+
144+
test("toPrecision truncates block if it has precision", () => {
145+
const originalValue = 0.00123456;
146+
const precision = 3;
147+
const aBlock: IfcBlock = {
148+
pvaddress: "SOME:BLOCK:STR",
149+
value: originalValue,
150+
precision: precision,
151+
};
152+
expect(toPrecision(aBlock, originalValue)).toBe(
153+
originalValue.toFixed(precision),
154+
);
155+
});
156+
157+
test("yesToBoolean works with YES as value", () => {
158+
expect(yesToBoolean("YES")).toBe(true);
159+
});
160+
161+
test("yesToBoolean works with NO as value", () => {
162+
expect(yesToBoolean("NO")).toBe(false);
163+
});
164+
165+
test("getGroupsWithBlocksFromConfigOutput gets blocks from blockserver groups", () => {
166+
const blockNameToTest = "aBlock";
167+
const groupNameToTest = "aGroup";
168+
const prefix = "TESTING";
169+
const mockSendJsonMessage = jest.fn();
170+
171+
const configOutput: ConfigOutput = {
172+
groups: [{ blocks: [blockNameToTest], name: groupNameToTest }],
173+
blocks: [
174+
{
175+
name: blockNameToTest,
176+
component: "",
177+
local: true,
178+
pv: "A:BLOCK",
179+
set_block: false,
180+
highlimit: 0,
181+
lowlimit: 0,
182+
log_rate: 0,
183+
log_deadband: 0,
184+
log_periodic: true,
185+
runcontrol: true,
186+
suspend_on_invalid: true,
187+
visible: true,
188+
},
189+
],
190+
components: [],
191+
description: "",
192+
name: "",
193+
configuresBlockGWAndArchiver: false,
194+
iocs: [],
195+
isDynamic: false,
196+
isProtected: false,
197+
synoptic: "",
198+
component_iocs: [],
199+
history: [],
200+
};
201+
const groups = getGroupsWithBlocksFromConfigOutput(
202+
configOutput,
203+
mockSendJsonMessage,
204+
prefix,
205+
);
206+
expect(groups[0].name).toBe(groupNameToTest);
207+
expect(groups[0].blocks[0].human_readable_name).toBe(blockNameToTest);
208+
});
209+
210+
test("subscribeToBlockPVs subscribes to blocks, their run control and their SP:RBV PVs", () => {
211+
const mockSendJsonMessage = jest.fn();
212+
const blockAddress = "IN:INST:CS:SB:Block1";
213+
subscribeToBlockPVs(mockSendJsonMessage, blockAddress);
214+
expect(mockSendJsonMessage).toBeCalledTimes(1);
215+
const call: Array<string> = mockSendJsonMessage.mock.calls[0][0].pvs;
216+
expect(call).toEqual(
217+
expect.arrayContaining([
218+
blockAddress,
219+
blockAddress + RC_ENABLE,
220+
blockAddress + RC_INRANGE,
221+
blockAddress + SP_RBV,
222+
]),
223+
);
224+
});
225+
226+
test("storePrecision adds precision to a block if it is the first update", () => {
227+
const precision = 3;
228+
const message: IfcPVWSMessage = {
229+
type: "update",
230+
pv: "",
231+
precision: precision,
232+
};
233+
let blockWithoutPrecision: IfcBlock = { pvaddress: "" };
234+
storePrecision(message, blockWithoutPrecision);
235+
expect(blockWithoutPrecision.precision).toEqual(precision);
236+
});

0 commit comments

Comments
 (0)