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

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

describe("Permissives", ()  => {
	it("should render a loading page if no tags", () => {
		const wrapper = shallow(<Permissives tags={undefined} />);
		expect(wrapper.find(".loading").text()).toMatch("Loading");
	});
	
	it("should render the permissives page", () => {
		const wrapper = shallow(<Permissives tags={[]} />);
		expect(wrapper.find(".permissives")).toHaveLength(1);
	});

	it("should render green button for permissive true", () => {
		const tags = {
			sp_ALL: { value: true },
			rp_ALL: { value: true },
			sp_Flowmeter: { value: true },
			rp_Flowmeter: { value: true },
			sp_IntakePressure: { value: true },
			rp_IntakePressure: { value: true },
			sp_IntakeTemperature: { value: true },
			rp_IntakeTemperature: { value: true }
		};
		const wrapper = shallow(<Permissives tags={tags} />);
		expect(wrapper.find(".btn-success")).toHaveLength(8);
	});

	it("should render red button for permissive false", () => {
		const tags = {
			sp_ALL: { value: false },
			rp_ALL: { value: false },
			sp_Flowmeter: { value: false },
			rp_Flowmeter: { value: false },
			sp_IntakePressure: { value: false },
			rp_IntakePressure: { value: false },
			sp_IntakeTemperature: { value: false },
			rp_IntakeTemperature: { value: false }
		};
		const wrapper = shallow(<Permissives tags={tags} />);
		expect(wrapper.find(".btn-danger")).toHaveLength(8);
	});

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