Files
MaxWaterSystem-Electron/__tests__/actions/actions_plc.test.js
2018-04-12 18:33:35 -05:00

89 lines
2.0 KiB
JavaScript

import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import { setPlcIpAddress, SET_PLC_IPADDRESS, ipcPlcInitializeSend, INITIALIZE_PLC, ipcPlcDetailsReceived, PLC_DATA_RECEIVED, ipcPlcErrorReceived, PLC_ERROR_RECEIVED } from "../../app/src/actions/actions_plc";
import { ipcRenderer } from "electron";
configure({ adapter: new Adapter() });
describe("actions_plc", () => {
describe("setPlcIpAddress", () => {
let action;
beforeEach(() => {
action = setPlcIpAddress("192.168.1.10");
});
it("has the correct type", () => {
expect(action.type).toEqual(SET_PLC_IPADDRESS);
});
it("has the correct payload", () => {
expect(action.payload).toEqual("192.168.1.10");
});
});
describe("ipcPlcInitializeSend", () => {
let action;
const tagList = {
test: { name: "test", value: 100.0 }
};
beforeEach(() => {
action = ipcPlcInitializeSend("192.168.1.10", tagList);
});
it("has the correct type", () => {
expect(action.type).toEqual(INITIALIZE_PLC);
});
it("has the correct payload", () => {
expect(action.payload).toBeTruthy();
});
it("triggers the ipcRenderer.send function", () => {
expect(ipcRenderer.send).toHaveBeenCalled();
});
});
describe("ipcPlcDetailsReceived", () => {
let action;
const plcData = {
ipAddress: "192.168.1.10",
details: {
name: "CLX"
}
};
beforeEach(() => {
action = ipcPlcDetailsReceived(undefined, plcData);
});
it("has the correct type", () => {
expect(action.type).toEqual(PLC_DATA_RECEIVED);
});
it("has the correct payload", () => {
expect(action.payload).toEqual({
ipAddress: "192.168.1.10",
details: {
name: "CLX"
}
});
});
});
describe("ipcPlcErrorReceived", () => {
let action;
beforeEach(() => {
action = ipcPlcErrorReceived(undefined, "ERROR MESSAGE!");
});
it("has the correct type", () => {
expect(action.type).toEqual(PLC_ERROR_RECEIVED);
});
it("has the correct payload", () => {
expect(action.payload).toEqual("ERROR MESSAGE!");
});
});
});