import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
configure({ adapter: new Adapter() });

import AlarmReducer from "../../app/src/reducers/reducer_alarm";
import { IPC_TAGUPDATE } from "../../app/src/actions/actions_tags";

describe("reducer_alarm", () => {
	it("should not change state on unused type", () => {
		expect(AlarmReducer(["test", "test"], "test")).toEqual(["test", "test"]);
	});

	it("should return a default empty object", () => {
		expect(AlarmReducer(undefined, "test")).toEqual([]);
	});

	describe("IPC_TAGUPDATE", () => {
		let action = {
			type: IPC_TAGUPDATE,
			payload: ""
		};

		it("should not change active alarms if tag not in alarm list", () => {
			action.payload = { name: "test", value: false };
			expect(AlarmReducer([], action)).toEqual([]);
		});

		it("should add the tag to active alarms if alarm tag value is true", () => {
			action.payload = { name: "alarm_ESTOP", value: true };
			expect(AlarmReducer([], action)).toEqual(["alarm_ESTOP"]);
		});

		it("should not change active alarms if alarm tag value is false", () => {
			action.payload = { name: "alarm_ESTOP", value: false };
			expect(AlarmReducer(["test"], action)).toEqual(["test"]);
		});

		it("should remove the event from the list if alarm tag value is false", () => {
			action.payload = { name: "alarm_ESTOP", value: false };
			expect(AlarmReducer(["alarm_ESTOP"], action)).toEqual([]);
		});

	});
});