Skip to content

Commit

Permalink
Merge pull request #111 from ISISComputingGroup/use_instlist_target_s…
Browse files Browse the repository at this point in the history
…tations

Use instlist target stations
  • Loading branch information
Tom-Willemsen authored Feb 25, 2025
2 parents 11f7368 + e243711 commit c32d09d
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 398 deletions.
23 changes: 19 additions & 4 deletions app/components/InstrumentWallCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import { IfcInstrumentStatus } from "@/app/types";
import { instListEntryWithRunstatePVandValue } from "@/app/types";
import { render } from "@testing-library/react";
import InstrumentWallCard from "@/app/components/InstrumentWallCard";

it("renders instrumentwallcard unchanged", () => {
const instrument: IfcInstrumentStatus = {
const instrument: instListEntryWithRunstatePVandValue = {
name: "Instrument",
runstate: "RUNNING",
runStateValue: "RUNNING",
pvPrefix: "",
runStatePV: "",
groups: ["EXCITATIONS"],
isScheduled: true,
seci: false,
hostName: "",
targetStation: "TS5",
};
const { container } = render(<InstrumentWallCard instrument={instrument} />);
expect(container).toMatchSnapshot();
});

it("renders instrumentwallcard unchanged when runstate is unknown", () => {
const instrument: IfcInstrumentStatus = {
const instrument: instListEntryWithRunstatePVandValue = {
name: "Instrument1",
runStateValue: "",
pvPrefix: "",
runStatePV: "",
groups: ["EXCITATIONS"],
isScheduled: true,
seci: false,
hostName: "",
targetStation: "TS5",
};
const { container } = render(<InstrumentWallCard instrument={instrument} />);
expect(container).toMatchSnapshot();
Expand Down
13 changes: 7 additions & 6 deletions app/components/InstrumentWallCard.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import Link from "next/link";
import { getForegroundColour, getStatusColour } from "./getRunstateColours";

import { IfcInstrumentStatus } from "@/app/types";
import { instListEntryWithRunstatePVandValue } from "@/app/types";

export default function InstrumentWallCard({
instrument,
}: {
instrument: IfcInstrumentStatus;
instrument: instListEntryWithRunstatePVandValue;
}) {
return (
<div className={"flex"}>
<Link
href={"/instrument?name=" + instrument.name}
target="_blank"
className={`flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
${getStatusColour(instrument.runstate || "UNKNOWN")} ${getForegroundColour(
instrument.runstate || "UNKNOWN",
${getStatusColour(instrument.runStateValue || "UNKNOWN")} ${getForegroundColour(
instrument.runStateValue || "UNKNOWN",
)}`}
>
<div className="flex flex-col">
<span className="text-sm font-bold line-clamp-1 w-full">
{instrument.name}
</span>
<span className="text-xs ">{instrument.runstate || "UNKNOWN"}</span>
<span className="text-xs ">
{instrument.runStateValue || "UNKNOWN"}
</span>
</div>
</Link>
</div>
Expand Down
74 changes: 55 additions & 19 deletions app/components/InstrumentsDisplay.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { createInstrumentGroups } from "@/app/components/InstrumentsDisplay";
import { targetStation } from "@/app/types";
import { instList } from "@/app/types";

test("createInstrumentGroups adds two instruments from different target stations to the same science group", () => {
const instrument1Name = "INST1";
const instrument2Name = "INST2";
const commonScienceGroup = "MOLSPEC";
const instrument1 = {
name: instrument1Name,
scienceGroups: [commonScienceGroup],
groups: [commonScienceGroup],
targetStation: "TS0",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
};
const instrument2 = {
name: instrument2Name,
scienceGroups: [commonScienceGroup],
groups: [commonScienceGroup],
targetStation: "TS0",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
};
const targetStations: Array<targetStation> = [
{ targetStation: "TS0", instruments: [instrument1] },
{ targetStation: "TS3", instruments: [instrument2] },
];
const targetStations: instList = [instrument1, instrument2];
const result = createInstrumentGroups(targetStations);

expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
Expand All @@ -29,13 +40,27 @@ test("createInstrumentGroups ignores instrument without any groups", () => {
const commonScienceGroup = "MOLSPEC";
const instrument1 = {
name: instrument1Name,
scienceGroups: [commonScienceGroup],
groups: [commonScienceGroup],
targetStation: "TS0",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
};
const instrument2 = { name: "someinstrumentwithnogroups", scienceGroups: [] };
const targetStations: Array<targetStation> = [
{ targetStation: "TS0", instruments: [instrument1] },
{ targetStation: "TS3", instruments: [instrument2] },
];
const instrument2 = {
name: "someinstrumentwithnogroups",
targetStation: "TS0",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
groups: [],
};
const targetStations: instList = [instrument1, instrument2];
const result = createInstrumentGroups(targetStations);

expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
Expand All @@ -48,16 +73,27 @@ test("createInstrumentGroups ignores instrument which is a support machine", ()
const commonScienceGroup = "MOLSPEC";
const instrument1 = {
name: instrument1Name,
scienceGroups: [commonScienceGroup],
groups: [commonScienceGroup],
targetStation: "TS0",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
};
const instrument2 = {
name: "someinstrumentwithnogroups",
scienceGroups: ["SUPPORT"],
groups: ["SUPPORT"],
targetStation: "TS3",
hostName: "",
pvPrefix: "",
isScheduled: true,
seci: false,
runStatePV: "",
runStateValue: "",
};
const targetStations: Array<targetStation> = [
{ targetStation: "TS0", instruments: [instrument1] },
{ targetStation: "TS3", instruments: [instrument2] },
];
const targetStations: instList = [instrument1, instrument2];
const result = createInstrumentGroups(targetStations);

expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
Expand Down
Loading

0 comments on commit c32d09d

Please sign in to comment.