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

import EventsReducer from "../../app/src/reducers/reducer_events";
import { IPC_TAGUPDATE } from "../../app/src/actions/actions_tags";

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

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

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

		it("should add an event to the event log for an event tag true", () => {
			action.payload = { name: "cmd_Start", value: true };
			const newState = EventsReducer([], action);
			expect(newState[0].tag).toEqual("cmd_Start");
		});

		it("should return unaltered event log if not in event log", () => {
			action.payload = { name: "test", value: true };
			expect(EventsReducer([], action)).toEqual([]);
		});

		it("should return unaltered event log if event tag value false", () => {
			action.payload = { name: "cmd_Start", value: false };
			expect(EventsReducer([], action)).toEqual([]);
		});
	});
});