Adds ethernet-ip-scanlist features and database storage
This commit is contained in:
29
__tests__/actions/actions_taghistory.test.js
Normal file
29
__tests__/actions/actions_taghistory.test.js
Normal 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: [] });
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
];
|
||||
|
||||
@@ -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)}]});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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 }});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user