import React from "react";
import { configure, shallow } from "enzyme";
import Adapter from "enzyme-adapter-react-15";
import USAMap from "../index";
import data from "../data/usa-map-dimensions";

configure({ adapter: new Adapter() });

describe("Component: USAMap", () => {
  let element;
  let componentProps;
  let onClickMock;

  beforeEach(() => {
    onClickMock = jest.fn();
    componentProps = {
      width: 959,
      height: 593,
      defaultFill: "#D3D3D3",
      title: "Blank US states map",
      customize: {
        "AK": {
          fill: "dummy-fill"
        }
      },
      onClick: onClickMock
    };
    element = shallow(<USAMap {...componentProps} />);
  });

  afterEach(() => {
    onClickMock.mockReset();
  });

  it("should render all states based on `usa-map-dimensions` file", () => {
    expect(onClickMock.mock.calls.length).toEqual(0);
    const statesLength = element.find("USAState").length;
    expect(Object.keys(data).length).toEqual(statesLength);
  });

  it("should add customised data by state", () => {
    const statesLength = element.find(`USAState[fill="${componentProps.customize.AK.fill}"]`);
    expect(statesLength.length).toEqual(1);
  });

  it("should calls `onClick` when the component is clicked", () => {
    expect(onClickMock.mock.calls.length).toEqual(0);
    const state = element.find(".state .DC2");
    state.simulate("click");
    expect(onClickMock.mock.calls[0]).toEqual([undefined]);
  });
});

@@ -47,16 +47,23 @@
  shallow
+, mount
  %7D from 
@@ -72,16 +72,16 @@
 nzyme%22;%0A
-
 import A
@@ -331,16 +331,49 @@
 ickMock;
+%0A  let customisedClickHandleMock;
 %0A%0A  befo
@@ -416,16 +416,59 @@
 t.fn();%0A
+    customisedClickHandleMock = jest.fn();%0A
     comp
@@ -649,16 +649,118 @@
 y-fill%22%0A
+        %7D,%0A        %22NJ%22: %7B%0A          fill: %22navy%22,%0A          clickHandler: customisedClickHandleMock,%0A
         
@@ -1570,24 +1570,24 @@
 e(%22click%22);%0A
-
     expect(o
@@ -1634,16 +1634,655 @@
 ined%5D);%0A
+    expect(customisedClickHandleMock.mock.calls.length).toEqual(0);%0A  %7D);%0A%0A  it(%22should calls customise method is customise property has click handler%22, () =%3E %7B%0A    // You have to mount instead of shallow because of dom-child of USAState.%0A    // We can simulate click only on that child, not in parent.%0A    element = mount(%3CUSAMap %7B...componentProps%7D /%3E);%0A    const state = element.find(%60USAState%5Bfill=%22$%7BcomponentProps.customize.NJ.fill%7D%22%5D%60).last();%0A    expect(state.length).toEqual(1);%0A    state.simulate(%22click%22);%0A    expect(onClickMock.mock.calls.length).toEqual(0);%0A    expect(customisedClickHandleMock.mock.calls.length).toEqual(1);%0A
   %7D);%0A%7D)

Add test for customized clickHandler per state