Skip to content

Commit 6800e42

Browse files
committed
fix some tests
1 parent be77ef7 commit 6800e42

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

app/components/GroupUtils.test.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
import { checkIfAllBlocksInGroupAreHidden } from "./GroupUtils";
22

3-
import { IfcBlock, IfcGroup } from "@/app/types";
3+
import { tBlockMapping } from "@/app/types";
44

55
test("group with all hidden blocks returns true", () => {
6-
const aHiddenBlock: IfcBlock = { pvaddress: "", visible: false };
7-
let group: IfcGroup = { name: "testing", blocks: [aHiddenBlock] };
8-
const result = checkIfAllBlocksInGroupAreHidden(group);
6+
let blocks: tBlockMapping = new Map();
7+
blocks.set("testing", { pvaddress: "", visible: false });
8+
const result = checkIfAllBlocksInGroupAreHidden(blocks);
99
expect(result).toBe(true);
1010
});
1111

12-
test("group with all visible blocks returns true", () => {
13-
let group: IfcGroup = {
14-
name: "testing",
15-
blocks: [{ pvaddress: "", visible: true }],
16-
};
17-
const result = checkIfAllBlocksInGroupAreHidden(group);
12+
test("group with all visible blocks returns false", () => {
13+
let blocks: tBlockMapping = new Map();
14+
blocks.set("testing", { pvaddress: "testing", visible: true });
15+
const result = checkIfAllBlocksInGroupAreHidden(blocks);
1816
expect(result).toBe(false);
1917
});
2018

21-
test("group with mixed visible blocks returns true", () => {
22-
let group: IfcGroup = {
23-
name: "testing",
24-
blocks: [
25-
{ pvaddress: "", visible: false },
26-
{ pvaddress: "", visible: true },
27-
],
28-
};
29-
const result = checkIfAllBlocksInGroupAreHidden(group);
19+
test("group with mixed visible blocks returns false", () => {
20+
let blocks: tBlockMapping = new Map();
21+
blocks.set("block1", { pvaddress: "block1", visible: false });
22+
blocks.set("block2", { pvaddress: "block2", visible: true });
23+
const result = checkIfAllBlocksInGroupAreHidden(blocks);
3024
expect(result).toBe(false);
3125
});

app/components/GroupUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ import { tBlockMapping } from "@/app/types";
33
export function checkIfAllBlocksInGroupAreHidden(
44
blocks: tBlockMapping,
55
): boolean {
6-
return Array.from(blocks.values())
7-
.map((block) => block.visible)
8-
.every((v) => v === false);
6+
return Array.from(blocks.values()).every((block) => block.visible === false);
97
}

app/components/TopBar.test.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
import TopBar, {
2-
configName,
3-
getRunstate,
4-
runStateStr,
5-
} from "@/app/components/TopBar";
6-
import { IfcPV } from "@/app/types";
1+
import TopBar, { getRunstate, runStateStr } from "@/app/components/TopBar";
2+
import { tBlockMapping } from "@/app/types";
73
import { render } from "@testing-library/react";
84
import { Instrument } from "@/app/components/Instrument";
9-
import { findPVByHumanReadableName } from "@/app/components/PVutils";
105

116
test("GetRunstate returns the runstate when it exists and is of string type", () => {
7+
const prefix = "TESTING:";
8+
129
const expected = "SETUP";
13-
const PVToTest: IfcPV = {
14-
pvaddress: "",
10+
let blocks: tBlockMapping = new Map();
11+
blocks.set(prefix + "DAE:RUNSTATE_STR", {
12+
pvaddress: prefix + "DAE:RUNSTATE_STR",
1513
value: expected,
1614
human_readable_name: runStateStr,
17-
};
18-
const PVArr = [PVToTest];
19-
expect(getRunstate(PVArr)).toBe(expected);
15+
});
16+
expect(getRunstate(prefix, blocks)).toBe(expected);
2017
});
2118

2219
test("GetRunstate returns unknown when no runstate PV in array", () => {
23-
const PVArr: Array<IfcPV> = [];
24-
expect(getRunstate(PVArr)).toBe("UNREACHABLE");
20+
expect(getRunstate("", new Map())).toBe("UNREACHABLE");
2521
});
2622

2723
it("renders topbar unchanged", () => {
28-
let instrument = new Instrument("TESTING");
24+
const prefix = "TESTING:";
25+
26+
let instrument = new Instrument(prefix);
2927
const instName = "Instrument";
3028
const { container } = render(
3129
TopBar({
3230
dashboard: instrument.dashboard,
3331
instName: instName,
3432
runInfoPVs: instrument.runInfoPVs,
33+
prefix: prefix,
3534
}),
3635
);
3736
expect(container).toMatchSnapshot();
3837
});
3938

4039
it("draws instName expectedly", () => {
41-
let instrument = new Instrument("TESTING");
40+
const prefix = "TESTING:";
41+
42+
let instrument = new Instrument(prefix);
4243
const instName = "Instrument";
4344
const { container } = render(
4445
TopBar({
4546
dashboard: instrument.dashboard,
4647
instName: instName,
4748
runInfoPVs: instrument.runInfoPVs,
49+
prefix: prefix,
4850
}),
4951
);
5052
expect(container.querySelector("#instNameLabel")!.innerHTML).toContain(
@@ -53,18 +55,19 @@ it("draws instName expectedly", () => {
5355
});
5456

5557
it("draws configName expectedly", () => {
56-
let instrument = new Instrument("TESTING");
57-
let configNamePV = findPVByHumanReadableName(
58-
instrument.runInfoPVs,
59-
configName,
60-
)!;
58+
const prefix = "TESTING:";
59+
let instrument = new Instrument(prefix);
60+
let configNamePV = instrument.runInfoPVs.get(
61+
prefix + "CS:BLOCKSERVER:CURR_CONFIG_NAME",
62+
);
6163
const expectedConfigName = "Aconfig";
62-
configNamePV.value = expectedConfigName;
64+
configNamePV!.value = expectedConfigName;
6365
const { container } = render(
6466
TopBar({
6567
dashboard: instrument.dashboard,
6668
instName: "Instrument",
6769
runInfoPVs: instrument.runInfoPVs,
70+
prefix: prefix,
6871
}),
6972
);
7073
expect(container.querySelector("#configNameSpan")!.innerHTML).toBe(

app/components/__snapshots__/Block.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`renders topbar unchanged 1`] = `
3232
mm
3333
</span>
3434
<svg
35-
class="min-w-2 min-h-2 max-w-2 max-h-2 transition-all text-transparent"
35+
class="min-w-2 min-h-2 max-w-2 max-h-2 transition-opacity text-green-500 opacity-100"
3636
fill="currentColor"
3737
id="undefined_CIRCLE"
3838
viewBox="0 0 24 24"

0 commit comments

Comments
 (0)