<commit_before>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]);
  });
});<commit_msg>Add test for customized clickHandler per state<commit_after>import React from "react";
import { configure, shallow, mount } 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;
  let customisedClickHandleMock;

  beforeEach(() => {
    onClickMock = jest.fn();
    customisedClickHandleMock = jest.fn();
    componentProps = {
      width: 959,
      height: 593,
      defaultFill: "#D3D3D3",
      title: "Blank US states map",
      customize: {
        "AK": {
          fill: "dummy-fill"
        },
        "NJ": {
          fill: "navy",
          clickHandler: customisedClickHandleMock,
        }
      },
      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]);
    expect(customisedClickHandleMock.mock.calls.length).toEqual(0);
  });

  it("should calls customise method is customise property has click handler", () => {
    // You have to mount instead of shallow because of dom-child of USAState.
    // We can simulate click only on that child, not in parent.
    element = mount(<USAMap {...componentProps} />);
    const state = element.find(`USAState[fill="${componentProps.customize.NJ.fill}"]`).last();
    expect(state.length).toEqual(1);
    state.simulate("click");
    expect(onClickMock.mock.calls.length).toEqual(0);
    expect(customisedClickHandleMock.mock.calls.length).toEqual(1);
  });
});
{'fraction_non_alphanumeric': 0.16297839104399897, 'fraction_numerical': 0.009372559229367352, 'mean_word_length': 3.446759259259259, 'pattern_counts': {'":': 3, '<': 6, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869967', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1179, 'n_words': 254}