Adds ethernet-ip-scanlist features and database storage

This commit is contained in:
Patrick McDonagh
2018-04-25 16:57:04 -05:00
parent 75b0a49ce1
commit c53d7f87c1
18 changed files with 921 additions and 346 deletions

View File

@@ -0,0 +1,29 @@
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
configure({ adapter: new Adapter() });
import { IPC_TAGHISTORYUPDATE, ipcTagHistoryUpdate } from "../../app/src/actions/actions_taghistory";
describe("actions_taghistory", () => {
describe("ipcTagHistoryUpdate", () => {
let action;
const sampleTag = {
tagName: "test",
historyRows: []
};
beforeEach(() => {
action = ipcTagHistoryUpdate(undefined, sampleTag);
});
it("has the correct type", () => {
expect(action.type).toEqual(IPC_TAGHISTORYUPDATE);
});
it("has the correct payload", () => {
expect(action.payload).toEqual({ tagName: "test", historyRows: [] });
});
});
});

View File

@@ -8,12 +8,10 @@ describe("actions_tags", () => {
describe("ipcTagUpdate", () => {
let action;
const sampleTag = { state: {
tag: {
name: "test",
value: 100.0
}
}};
const sampleTag = {
tagName: "test",
value: 100.0
};
beforeEach(() => {
action = ipcTagUpdate(undefined, sampleTag);
@@ -24,7 +22,7 @@ describe("actions_tags", () => {
});
it("has the correct payload", () => {
expect(action.payload).toEqual({ name: "test", value: 100.0 });
expect(action.payload).toEqual({ tagName: "test", value: 100.0 });
});
});

View File

@@ -77,12 +77,12 @@ describe("Settings", () => {
describe("tag list", () => {
it("should have one row for each tag", () => {
expect(container.find(".tag-list li")).toHaveLength(2);
expect(container.find(".tag-list tbody tr")).toHaveLength(2);
});
it("should update state when new tag input changed", () => {
container.find(".tag-name-input").simulate("change", {target: {value: "testtag"}});
expect(container.state().newTag).toEqual("testtag");
expect(container.state().newTag.tagName).toEqual("testtag");
});
it("should run the storeNewTag function on submit button click", () => {

View File

@@ -19,11 +19,11 @@ describe("TagsIndex", () => {
describe("when tags are found", () => {
const testTagList = [
{
name: "test1",
tagName: "test1",
value: 100
},
{
name: "test2",
tagName: "test2",
value: 200
}
];

View File

@@ -5,6 +5,7 @@ configure({ adapter: new Adapter() });
import TagHistoryReducer from "../../app/src/reducers/reducer_taghistory";
import { IPC_TAGUPDATE } from "../../app/src/actions/actions_tags";
import { IPC_TAGHISTORYUPDATE } from "../../app/src/actions/actions_taghistory";
describe("TagHistory", () => {
it("should not change state on unused type", () => {
@@ -22,20 +23,33 @@ describe("TagHistory", () => {
};
it("should add a history tag to an empty state", () => {
action.payload = { name: "val_IntakePressure", value: 100 };
action.payload = { tagName: "val_IntakePressure", value: 100 };
expect(_.map(TagHistoryReducer({}, action), (x) => x)).toHaveLength(1);
});
it("should add another value to an existing history state", () => {
action.payload = { name: "val_IntakePressure", value: 100 };
action.payload = { tagName: "val_IntakePressure", value: 100 };
const stateAfterAdd = TagHistoryReducer({}, action);
expect(_.map(TagHistoryReducer(stateAfterAdd, action), (x) => x)[0]).toHaveLength(2);
});
it("should not add to the history if the tag is not a historical tag", () => {
action.payload = { name: "test", value: 100 };
action.payload = { tagName: "test", value: 100 };
expect(_.map(TagHistoryReducer({}, action), (x) => x)).toHaveLength(0);
});
});
describe("IPC_TAGHISTORYUPDATE", () => {
const action = {
type: IPC_TAGHISTORYUPDATE,
payload: ""
};
it("should add to the tagHistory state", () => {
action.payload = {tagName: "test", historyRows: [{value: 100, timestamp: new Date(0)}]};
const stateAfterAdd = TagHistoryReducer({}, action);
expect(stateAfterAdd).toEqual( {test : [{value: 100, timestamp: new Date(0)}]});
});
});
});

View File

@@ -17,18 +17,18 @@ describe("PlcReducer", () => {
describe("IPC_TAGUPDATE", () => {
const action = {
type: IPC_TAGUPDATE,
payload: { name: "test", value: 111.111 }
payload: { tagName: "test", value: 111.111 }
};
it("should store a new value for a new tag", () => {
const newState = TagsReducer({}, action);
expect(newState).toEqual({ test: { name: "test", value: 111.111 }});
expect(newState).toEqual({ test: { tagName: "test", value: 111.111 }});
});
it("should store a new value for an existing tag", () => {
const existingState = { test: { name: "test", value: 0.00 }};
const existingState = { test: { tagName: "test", value: 0.00 }};
const newState = TagsReducer(existingState, action);
expect(newState).toEqual({test: { name: "test", value: 111.111 }});
expect(newState).toEqual({test: { tagName: "test", value: 111.111 }});
});
});