Skip to content

Commit

Permalink
dont show support machines in instruments page, add test for this, co…
Browse files Browse the repository at this point in the history
…unt coverage from InstrumentsDisplay
  • Loading branch information
rerpha committed Dec 6, 2024
1 parent 6ebad58 commit 609df6e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
22 changes: 22 additions & 0 deletions app/components/InstrumentsDisplay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ test("createInstrumentGroups ignores instrument without any groups", () => {
[instrument1].sort(),
);
});

test("createInstrumentGroups ignores instrument which is a support machine", () => {
const instrument1Name = "INST1";
const commonScienceGroup = "MOLSPEC";
const instrument1 = {
name: instrument1Name,
scienceGroups: [commonScienceGroup],
};
const instrument2 = {
name: "someinstrumentwithnogroups",
scienceGroups: ["SUPPORT"],
};
const targetStations: Array<targetStation> = [
{ targetStation: "TS0", instruments: [instrument1] },
{ targetStation: "TS3", instruments: [instrument2] },
];
const result = createInstrumentGroups(targetStations);

expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
[instrument1].sort(),
);
});
15 changes: 11 additions & 4 deletions app/components/InstrumentsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
import TargetStation from "@/app/components/TargetStation";
import ScienceGroup from "@/app/components/ScienceGroup";

// Ignore support machines for the instruments page.
const instrumentsExcludeList = ["SUPPORT"];

export function createInstrumentGroups(
targetStations: Array<targetStation>,
): Map<string, Array<IfcInstrumentStatus>> {
Expand All @@ -24,18 +27,21 @@ export function createInstrumentGroups(
for (const inst of targetStation.instruments) {
if (inst.scienceGroups) {
for (const group of inst.scienceGroups) {
if (!newInstrumentGroups.has(group)) {
// This is a new science group so create a new entry
newInstrumentGroups.set(group, []);
if (!instrumentsExcludeList.includes(group)) {
if (!newInstrumentGroups.has(group)) {
// This is a new science group so create a new entry
newInstrumentGroups.set(group, []);
}
newInstrumentGroups.get(group)!.push(inst);
}
newInstrumentGroups.get(group)!.push(inst);
}
}
}
}
return newInstrumentGroups;
}

/* c8 ignore start */
export default function InstrumentsDisplay({
sortByGroups = false,
}: {
Expand Down Expand Up @@ -198,3 +204,4 @@ export default function InstrumentsDisplay({
</div>
);
}
/* c8 ignore end */
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const config: Config = {
"!app/components/JenkinsJobsIframe.tsx", // relies on an external image
"!app/components/ShowHideBeamInfo.tsx", // relies on an external image
"!app/components/InstrumentData.tsx", // relies on websocket
"!app/components/InstrumentsDisplay.tsx", // relies on websocket
],
};

Expand Down

0 comments on commit 609df6e

Please sign in to comment.