Files
Patrick McDonagh 75b0a49ce1 Completes main page
2018-04-17 16:05:48 -05:00

95 lines
3.5 KiB
JavaScript

import React from "react";
import { shallow, configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
configure({ adapter: new Adapter() });
import { Main, mapStateToProps } from "../../app/src/components/Main";
describe("Main", () => {
const tags = {
val_FluidLevel: { name: "val_FluidLevel", value: 100.0 },
val_Flowmeter_BarrelsPerDay: { name: "val_Flowmeter_BarrelsPerDay", value: 200.0 },
val_TubingPressure: { name: "val_TubingPressure", value: 150.0 },
val_Flowmeter: { name: "val_Flowmeter", value: 150.0 },
val_IntakePressure: { name: "val_IntakePressure", value: 150.0 },
val_IntakeTemperature: { name: "val_IntakeTemperature", value: 150.0 },
VFD_OutCurrent: { name: "VFD_OutCurrent", value: 30.0 },
VFD_SpeedFdbk: { name: "VFD_SpeedFdbk", value: 60.0 },
VFD_OutPower: { name: "VFD_OutPower", value: 60.0 },
VFD_Temp: { name: "VFD_Temp", value: 60.0 },
};
const tagHistory = {
val_FluidLevel: [{ timestamp: 0, value: 100.0 }],
val_Flowmeter_BarrelsPerDay: [{ timestamp: 0, value: 200.0 }],
val_TubingPressure: [{ timestamp: 0, value: 150.0 }],
val_Flowmeter: [{ timestamp: 0, value: 150.0 }],
val_IntakePressure: [{ timestamp: 0, value: 150.0 }],
val_IntakeTemperature: [{ timestamp: 0, value: 150.0 }],
VFD_OutCurrent: [{ timestamp: 0, value: 30.0 }],
VFD_SpeedFdbk: [{ timestamp: 0, value: 60.0 }],
VFD_OutPower: [{ timestamp: 0, value: 60.0 }],
VFD_Temp: [{ timestamp: 0, value: 60.0 }]
};
it("should render loading div if no tag history", () =>{
const wrapper = shallow(<Main tagHistory={undefined} />);
expect(wrapper.find(".loading").text()).toMatch("Loading");
});
it("should render plc error class if PLC error", () => {
const wrapper = shallow(<Main tagHistory={{a:1, b:2}} plc={{ error: true }} />);
expect(wrapper.find(".plc-error").text()).toMatch("PLC Error");
});
it("should render waiting if no tags yet", () => {
const wrapper = shallow(<Main tagHistory={{a:1, b:2}} plc={{}} tags={{}} />);
expect(wrapper.find(".waiting").text()).toMatch("Waiting for data");
});
it("should render the main container if everything ready", () => {
const wrapper = shallow(<Main tagHistory={tagHistory} plc={{}} tags={tags} />);
expect(wrapper.find(".main")).toHaveLength(1);
});
// describe("tag current values", () => {
// let wrapper;
// beforeEach(() => {
// wrapper = shallow(<Main tagHistory={tagHistory} plc={{}} tags={tags} />);
// });
// it("should render a liquid fill gauge for all gauges", () => {
// expect(wrapper.find(".liquidfill")).toHaveLength(5);
// });
// it("should render a liquidfill gauge for val_FluidLevel", () => {
// expect(wrapper.find(".lqdfill-val_FluidLevel")).toHaveLength(1);
// });
// it("should render a liquidfill gauge for val_Flowmeter_BarrelsPerDay", () => {
// expect(wrapper.find(".lqdfill-val_Flowmeter_BarrelsPerDay")).toHaveLength(1);
// });
// it("should render a liquidfill gauge for val_TubingPressure", () => {
// expect(wrapper.find(".lqdfill-val_TubingPressure")).toHaveLength(1);
// });
// it("should render a liquidfill gauge for VFD_OutCurrent", () => {
// expect(wrapper.find(".lqdfill-VFD_OutCurrent")).toHaveLength(1);
// });
// it("should render a liquidfill gauge for VFD_SpeedFdbk", () => {
// expect(wrapper.find(".lqdfill-VFD_SpeedFdbk")).toHaveLength(1);
// });
// });
it("should map state to props", () => {
expect(mapStateToProps({ tags: "tags", plc: "plc", tagHistory: "tagHistory", extra: "extra" })).toEqual({ tags: "tags", plc: "plc", tagHistory: "tagHistory" });
});
});