import React from "react";
import { shallow } from "enzyme";
import LineChart from "./LineChart";
describe("LineChart", function () {
  var simpleData = [{
    x: 100,
    y: 10
  }, {
    x: 200,
    y: 20
  }];
  var updatedSimpleData = [{
    x: 100,
    y: 10
  }, {
    x: 200,
    y: 20
  }, {
    x: 300,
    y: 30
  }];
  var simpleCategoryData = [{
    x: 100,
    y: 10,
    category: "cat"
  }, {
    x: 200,
    y: 20,
    category: "cat"
  }, {
    x: 100,
    y: 20,
    category: "dog"
  }, {
    x: 200,
    y: 10,
    category: "dog"
  }];
  var updatedSimpleCategoryData = [{
    x: 200,
    y: 20,
    category: "cat"
  }, {
    x: 300,
    y: 30,
    category: "cat"
  }, {
    x: 100,
    y: 20,
    category: "dog"
  }, {
    x: 200,
    y: 10,
    category: "dog"
  }, {
    x: 100,
    y: 10,
    category: "fish"
  }, {
    x: 300,
    y: 25,
    category: "fish"
  }];
  var simpleColorData = [{
    x: 100,
    y: 10,
    category: "black"
  }, {
    x: 200,
    y: 20,
    category: "black"
  }, {
    x: 100,
    y: 20,
    category: "white"
  }, {
    x: 200,
    y: 10,
    category: "white"
  }];
  var updatedSimpleColorData = [{
    x: 200,
    y: 20,
    category: "black"
  }, {
    x: 300,
    y: 30,
    category: "black"
  }, {
    x: 100,
    y: 20,
    category: "white"
  }, {
    x: 200,
    y: 10,
    category: "white"
  }, {
    x: 100,
    y: 10,
    category: "fish"
  }, {
    x: 300,
    y: 25,
    category: "fish"
  }];
  it("should render a VictoryChart", function () {
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleData
    }));
    expect(wrapper.find("VictoryChart").length).to.eql(1);
  });
  it("renders a LineChart with sample data", function () {
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleData
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(1);
    expect(wrapper.find({
      title: "Line Chart"
    }).props().data).to.eql([{
      dataKey: 100,
      dataValue: 10,
      series: undefined
    }, {
      dataKey: 200,
      dataValue: 20,
      series: undefined
    }]);
  });
  it("renders an updated LineChart when passed new data", function () {
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleData
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(1);
    wrapper.setProps({
      data: updatedSimpleData
    });
    expect(wrapper.find({
      title: "Line Chart"
    }).props().data).to.eql([{
      dataKey: 100,
      dataValue: 10,
      series: undefined
    }, {
      dataKey: 200,
      dataValue: 20,
      series: undefined
    }, {
      dataKey: 300,
      dataValue: 30,
      series: undefined
    }]);
  });
  it("renders a LineChart with sample category data", function () {
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleCategoryData,
      dataSeries: "category"
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(2);
    expect(wrapper.find({
      title: "Line Chart"
    }).first().props().data).to.eql([{
      dataKey: 100,
      dataValue: 10,
      series: "cat"
    }, {
      dataKey: 200,
      dataValue: 20,
      series: "cat"
    }]);
  });
  it("renders an updated LineChart when passed new category data", function () {
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleCategoryData,
      dataSeries: "category"
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(2);
    wrapper.setProps({
      data: updatedSimpleCategoryData
    });
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(3);
    expect(wrapper.find({
      title: "Line Chart"
    }).first().props().data).to.eql([{
      dataKey: 200,
      dataValue: 20,
      series: "cat"
    }, {
      dataKey: 300,
      dataValue: 30,
      series: "cat"
    }]);
  });
  it("renders a LineChart with sample color category data", function () {
    var c = "‌‌​";
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleColorData,
      dataSeries: "category",
      protect: true
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(2);
    expect(wrapper.find({
      title: "Line Chart"
    }).first().props().data).to.eql([{
      dataKey: 100,
      dataValue: 10,
      series: "black".concat(c)
    }, {
      dataKey: 200,
      dataValue: 20,
      series: "black".concat(c)
    }]);
  });
  it("renders an updated LineChart when passed new color category data", function () {
    var c = "‌‌​";
    var wrapper = shallow(React.createElement(LineChart, {
      data: simpleColorData,
      dataSeries: "category",
      protect: true
    }));
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(2);
    wrapper.setProps({
      data: updatedSimpleColorData
    });
    expect(wrapper.find({
      title: "Line Chart"
    }).length).to.eql(3);
    expect(wrapper.find({
      title: "Line Chart"
    }).first().props().data).to.eql([{
      dataKey: 200,
      dataValue: 20,
      series: "black".concat(c)
    }, {
      dataKey: 300,
      dataValue: 30,
      series: "black".concat(c)
    }]);
  });
});