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

import { Header, mapStateToProps } from "../../app/src/components/Header";


describe("Header", () => {
	it("should display a nav item", () => {
		const wrapper = shallow(<Header />);
		expect(wrapper.find("nav")).toHaveLength(1);
	});

	describe("alarm button", () => {

		it("does not display anything if props haven't been set", () => {
			const wrapper = shallow(<Header alarms={undefined} />);
			expect(wrapper.find(".no-alarm")).toHaveLength(1);
		});

		it("renders button for no alarms", () => {
			const wrapper = shallow(<Header alarms={[]} />);
			expect(wrapper.find(".alarm-button")).toHaveLength(1);
		});

		it("renders button for alarms", () => {
			const wrapper = shallow(<Header alarms={["alarm_Test"]} />);
			expect(wrapper.find(".alarm-button")).toHaveLength(1);
		});
	});

	describe("running state indicator", () => {
		const tags = {
			Device_Status_INT: { name: "Device_Status_INT", value: 0 }
		};

		it("renders an empty span for no tags", () => {
			const wrapper = shallow(<Header alarms={[]} tags={undefined} />);
			expect(wrapper.find(".no-tags").text()).toEqual("");
		});

		it("renders and empty span for tags, but no Device_Status_INT", () => {
			const wrapper = shallow(<Header alarms={[]} tags={[]} />);
			expect(wrapper.find(".no-device-status").text()).toEqual("");
		});

		it("renders Running for value 0", () => {
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Running");
		});

		it("renders Pumped Off for value 1", () => {
			tags.Device_Status_INT.value = 1;
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Pumped Off");
		});

		it("renders Alarmed for value 2", () => {
			tags.Device_Status_INT.value = 2;
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Alarmed");
		});

		it("renders Locked Out for value 3", () => {
			tags.Device_Status_INT.value = 3;
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Locked Out");
		});

		it("renders Stopped for value 4", () => {
			tags.Device_Status_INT.value = 4;
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Stopped");
		});

		it("renders Unknown for value 5", () => {
			tags.Device_Status_INT.value = 5;
			const wrapper = shallow(<Header alarms={[]} tags={tags} />);
			expect(wrapper.find(".status-indicator").text()).toMatch("Unknown");
		});
	});

	it("should map state to props", () => {
		const state = { tags: "tags", alarms: "alarms", extra: "extra"};
		expect(mapStateToProps(state)).toEqual({ tags: "tags", alarms: "alarms" });
	});

});