import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import { ipcRenderer } from "electron";
import { ipcTagUpdate, IPC_TAGSYNC, IPC_TAGUPDATE, ipcTagSync, storeNewTag, STORE_NEW_TAG, deleteTag, DELETE_TAG, writeTag, WRITE_TAG } from "../../app/src/actions/actions_tags";
configure({ adapter: new Adapter() });

describe("actions_tags", () => {
	describe("ipcTagUpdate", () => {
		let action;

		const sampleTag = {
			tagName: "test",
			value: 100.0
		};

		beforeEach(() => {
			action = ipcTagUpdate(undefined, sampleTag);
		});

		it("has the correct type", () => {
			expect(action.type).toEqual(IPC_TAGUPDATE);
		});

		it("has the correct payload", () => {
			expect(action.payload).toEqual({ tagName: "test", value: 100.0 });
		});
	});

	describe("ipcTagSync", () => {
		let action;

		const sampleTag = { test: {
			name: "test",
			value: 100.0
		}};

		beforeEach(() => {
			action = ipcTagSync("192.168.1.10", sampleTag);
		});

		it("has the correct type", () => {
			expect(action.type).toEqual(IPC_TAGSYNC);
		});

		it("has the correct payload", () => {
			expect(action.payload).toBeTruthy();
		});

		it("should execute the ipcRenderer.send function", () => {
			expect(ipcRenderer.send).toHaveBeenCalled();
		});
	});

	describe("storeNewTag", () => {
		let action;

		const sampleTag = {
			name: "test",
			value: 100.0
		};

		beforeEach(() => {
			action = storeNewTag(sampleTag);
		});

		it("has the correct type", () => {
			expect(action.type).toEqual(STORE_NEW_TAG);
		});

		it("has the correct payload", () => {
			expect(action.payload).toEqual({ name: "test", value: 100.0 });
		});
	});

	describe("deleteTag", () => {
		let action;

		beforeEach(() => {
			action = deleteTag("test");
		});

		it("has the correct type", () => {
			expect(action.type).toEqual(DELETE_TAG);
		});

		it("has the correct payload", () => {
			expect(action.payload).toEqual("test");
		});
	});

	describe("writeTag", () => {
		let action;

		beforeEach(() => {
			action = writeTag("test", 100.0);
		});

		it("has the correct type", () => {
			expect(action.type).toEqual(WRITE_TAG);
		});

		it("has the correct payload", () => {
			expect(action.payload).toBeTruthy();
		});

		it("should execute the ipcRenderer.send function", () => {
			expect(ipcRenderer.send).toHaveBeenCalled();
		});
	});
});