<commit_before>/**
 * Client tests
 */
/*eslint-disable max-nested-callbacks */
/* global sinon */
/* eslint no-unused-expressions: 0 */
import React from "react";
import { shallow, mount, render } from "enzyme";
import { omit, range } from "lodash";
import * as d3Scale from "d3-scale";
import VictoryErrorBar from "src/components/victory-errorbar/victory-errorbar";
import { ErrorBar } from "victory-core";

class MyErrorBar extends React.Component {

  render() { }
}

describe("components/victory-errorbar", () => {
  describe("default component rendering", () => {
    it("renders an svg with the correct width and height", () => {
      const wrapper = mount(
        <VictoryErrorBar/>
      );
      const svg = wrapper.find("svg");
      expect(svg.prop("style").width).to.equal("100%");
      expect(svg.prop("style").height).to.equal("auto");
    });

    it("renders an svg with the correct viewBox", () => {
      const wrapper = mount(
        <VictoryErrorBar/>
      );
      const svg = wrapper.find("svg");
      const viewBoxValue =
        `0 0 ${450} ${300}`;
      expect(svg.prop("viewBox")).to.equal(viewBoxValue);
    });

    it("renders 4 errors", () => {
      const wrapper = shallow(
        <VictoryErrorBar/>
      );
      const errorbars = wrapper.find(ErrorBar);
      expect(errorbars.length).to.equal(4);
    });
  });

  describe("symmetric error, rendering data", () => {
    it("renders injected errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: 0.1, errorY: 0.2}));
      const wrapper = shallow(
        <VictoryErrorBar data={data} dataComponent={<MyErrorBar />} />
      );

      const errors = wrapper.find(MyErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: 0.1, errorY: 0.2}));
      const wrapper = shallow(
        <VictoryErrorBar data={data}/>
      );
      const errors = wrapper.find(ErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors with error bars, check total svg lines", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const wrapper = render(
        <VictoryErrorBar
          data={[
            {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
            {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
            {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
          ]}
          {...svgDimensions}
        />
      );
      expect(wrapper.find("line")).to.have.length(24);
    });

    it("should check right border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        // right border
        expect(node.find("line").at(0).props().x1)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(0).props().x2)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(0).props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.find("line").at(0).props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check left border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        // left border
        expect(node.find("line").at(1).props().x1)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(1).props().x2)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(1).props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.find("line").at(1).props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check bottom border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        // bottom border
        expect(node.find("line").at(2).props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.find("line").at(2).props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.find("line").at(2).props().y1)
          .to.equal(negativeErrorY);
        expect(node.find("line").at(2).props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check top border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        // top border
        expect(node.find("line").at(3).props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.find("line").at(3).props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.find("line").at(3).props().y1)
          .to.equal(positiveErrorY);
        expect(node.find("line").at(3).props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check top cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        expect(node.find("line").at(7).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(7).props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(7).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(7).props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check bottom cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        expect(node.find("line").at(6).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(6).props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(6).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(6).props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check left cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        expect(node.find("line").at(5).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(5).props().x2)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(5).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(5).props().y2)
          .to.equal(yScale(data[i].y));
      });
    });

    it("should check right cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].errorX + data[i].x);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        expect(node.find("line").at(4).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(4).props().x2)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(4).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(4).props().y2)
          .to.equal(yScale(data[i].y));
      });
    });
  });

  describe("asymmetric error, rendering data", () => {
    it("renders injected errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: [0.1, 0.2], errorY: [0.2, 0.5]}));
      const wrapper = shallow(
        <VictoryErrorBar data={data} dataComponent={<MyErrorBar />} />
      );

      const errors = wrapper.find(MyErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: [0.1, 0.2], errorY: [0.2, 1]}));
      const wrapper = shallow(
        <VictoryErrorBar data={data}/>
      );
      const errors = wrapper.find(ErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors with error bars, check total svg lines", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const wrapper = render(
        <VictoryErrorBar
          data={[
            {x: 0, y: 0, errorX: [0.1, 0.5], errorY: [0.2, 0.3]},
            {x: 2, y: 3, errorX: [0.1, 0.5], errorY: [0.2, 0.4]},
            {x: 5, y: 5, errorX: [0.1, 0.5], errorY: [0.2, 0.1]}
          ]}
          {...svgDimensions}
        />
      );
      expect(wrapper.find("line")).to.have.length(24);
    });

    it("should check right border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX[0]);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        // right border
        expect(node.find("line").at(0).props().x1)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(0).props().x2)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(0).props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.find("line").at(0).props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check left border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX[1]);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        // left border
        expect(node.find("line").at(1).props().x1)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(1).props().x2)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(1).props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.find("line").at(1).props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check bottom border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY[0]);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        // bottom border
        expect(node.find("line").at(2).props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.find("line").at(2).props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.find("line").at(2).props().y1)
          .to.equal(negativeErrorY);
        expect(node.find("line").at(2).props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check top border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY[1]);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        // top border
        expect(node.find("line").at(3).props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.find("line").at(3).props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.find("line").at(3).props().y1)
          .to.equal(positiveErrorY);
        expect(node.find("line").at(3).props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check top cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY[1]);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        expect(node.find("line").at(7).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(7).props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(7).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(7).props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check bottom cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY[0]);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        expect(node.find("line").at(6).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(6).props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(6).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(6).props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check left cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX[1]);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        expect(node.find("line").at(5).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(5).props().x2)
          .to.equal(negativeErrorX);
        expect(node.find("line").at(5).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(5).props().y2)
          .to.equal(yScale(data[i].y));
      });
    });

    it("should check right cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX[0]);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        expect(node.find("line").at(4).props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.find("line").at(4).props().x2)
          .to.equal(positiveErrorX);
        expect(node.find("line").at(4).props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.find("line").at(4).props().y2)
          .to.equal(yScale(data[i].y));
      });
    });<commit_msg>less brittle tests<commit_after>/**
 * Client tests
 */
/*eslint-disable max-nested-callbacks */
/* global sinon */
/* eslint no-unused-expressions: 0 */
import React from "react";
import { shallow, mount, render } from "enzyme";
import { omit, range } from "lodash";
import * as d3Scale from "d3-scale";
import VictoryErrorBar from "src/components/victory-errorbar/victory-errorbar";
import { ErrorBar } from "victory-core";

class MyErrorBar extends React.Component {

  render() { }
}

describe("components/victory-errorbar", () => {
  describe("default component rendering", () => {
    it("renders an svg with the correct width and height", () => {
      const wrapper = mount(
        <VictoryErrorBar/>
      );
      const svg = wrapper.find("svg");
      expect(svg.prop("style").width).to.equal("100%");
      expect(svg.prop("style").height).to.equal("auto");
    });

    it("renders an svg with the correct viewBox", () => {
      const wrapper = mount(
        <VictoryErrorBar/>
      );
      const svg = wrapper.find("svg");
      const viewBoxValue =
        `0 0 ${450} ${300}`;
      expect(svg.prop("viewBox")).to.equal(viewBoxValue);
    });

    it("renders 4 errors", () => {
      const wrapper = shallow(
        <VictoryErrorBar/>
      );
      const errorbars = wrapper.find(ErrorBar);
      expect(errorbars.length).to.equal(4);
    });
  });

  describe("symmetric error, rendering data", () => {
    it("renders injected errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: 0.1, errorY: 0.2}));
      const wrapper = shallow(
        <VictoryErrorBar data={data} dataComponent={<MyErrorBar />} />
      );

      const errors = wrapper.find(MyErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: 0.1, errorY: 0.2}));
      const wrapper = shallow(
        <VictoryErrorBar data={data}/>
      );
      const errors = wrapper.find(ErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors with error bars, check total svg lines", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const wrapper = render(
        <VictoryErrorBar
          data={[
            {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
            {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
            {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
          ]}
          {...svgDimensions}
        />
      );
      expect(wrapper.find("line")).to.have.length(24);
    });

    it("should check right border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        // right border
        expect(node.findWhere((n) => n.key() === "borderRight").props().x1)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "borderRight").props().x2)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "borderRight").props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderRight").props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check left border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        // left border
        expect(node.findWhere((n) => n.key() === "borderLeft").props().x1)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().x2)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check bottom border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        // bottom border
        expect(node.findWhere((n) => n.key() === "borderBottom").props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().y1)
          .to.equal(negativeErrorY);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check top border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        // top border
        expect(node.findWhere((n) => n.key() === "borderTop").props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderTop").props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.findWhere((n) => n.key() === "borderTop").props().y1)
          .to.equal(positiveErrorY);
        expect(node.findWhere((n) => n.key() === "borderTop").props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check top cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        expect(node.findWhere((n) => n.key() === "crossTop").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossTop").props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossTop").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossTop").props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check bottom cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        expect(node.findWhere((n) => n.key() === "crossBottom").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check left cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        expect(node.findWhere((n) => n.key() === "crossLeft").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossLeft").props().x2)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "crossLeft").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossLeft").props().y2)
          .to.equal(yScale(data[i].y));
      });
    });

    it("should check right cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: 0.1, errorY: 0.2},
        {x: 2, y: 3, errorX: 0.1, errorY: 0.2},
        {x: 5, y: 5, errorX: 0.1, errorY: 0.2}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.1, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.2, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].errorX + data[i].x);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        expect(node.findWhere((n) => n.key() === "crossRight").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossRight").props().x2)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "crossRight").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossRight").props().y2)
          .to.equal(yScale(data[i].y));
      });
    });
  });

  describe("asymmetric error, rendering data", () => {
    it("renders injected errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: [0.1, 0.2], errorY: [0.2, 0.5]}));
      const wrapper = shallow(
        <VictoryErrorBar data={data} dataComponent={<MyErrorBar />} />
      );

      const errors = wrapper.find(MyErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors for {x, y}", () => {
      const data = range(10).map((i) => ({x: i, y: i, errorX: [0.1, 0.2], errorY: [0.2, 1]}));
      const wrapper = shallow(
        <VictoryErrorBar data={data}/>
      );
      const errors = wrapper.find(ErrorBar);
      expect(errors.length).to.equal(10);
    });

    it("renders errors with error bars, check total svg lines", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const wrapper = render(
        <VictoryErrorBar
          data={[
            {x: 0, y: 0, errorX: [0.1, 0.5], errorY: [0.2, 0.3]},
            {x: 2, y: 3, errorX: [0.1, 0.5], errorY: [0.2, 0.4]},
            {x: 5, y: 5, errorX: [0.1, 0.5], errorY: [0.2, 0.1]}
          ]}
          {...svgDimensions}
        />
      );
      expect(wrapper.find("line")).to.have.length(24);
    });

    it("should check right border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX[0]);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        // right border
        expect(node.findWhere((n) => n.key() === "borderRight").props().x1)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "borderRight").props().x2)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "borderRight").props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderRight").props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check left border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX[1]);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        // left border
        expect(node.findWhere((n) => n.key() === "borderLeft").props().x1)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().x2)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().y1)
          .to.equal(yScale(data[i].y) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderLeft").props().y2)
          .to.equal(yScale(data[i].y) + borderWidth);
      });
    });

    it("should check bottom border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY[0]);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        // bottom border
        expect(node.findWhere((n) => n.key() === "borderBottom").props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().y1)
          .to.equal(negativeErrorY);
        expect(node.findWhere((n) => n.key() === "borderBottom").props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check top border of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const borderWidth = 10;
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY[1]);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        // top border
        expect(node.findWhere((n) => n.key() === "borderTop").props().x1)
          .to.equal(xScale(data[i].x) - borderWidth);
        expect(node.findWhere((n) => n.key() === "borderTop").props().x2)
          .to.equal(xScale(data[i].x) + borderWidth);
        expect(node.findWhere((n) => n.key() === "borderTop").props().y1)
          .to.equal(positiveErrorY);
        expect(node.findWhere((n) => n.key() === "borderTop").props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check top cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y - data[i].errorY[1]);
        const yScaleMax = yScale.range()[0];
        const positiveErrorY = errorY >= yScaleMax
          ? yScaleMax : errorY;

        expect(node.findWhere((n) => n.key() === "crossTop").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossTop").props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossTop").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossTop").props().y2)
          .to.equal(positiveErrorY);
      });
    });

    it("should check bottom cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorY = yScale(data[i].y + data[i].errorY[0]);
        const yScaleMin = yScale.range()[1];
        const negativeErrorY = errorY <= yScaleMin
          ? yScaleMin : errorY;

        expect(node.findWhere((n) => n.key() === "crossBottom").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().x2)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossBottom").props().y2)
          .to.equal(negativeErrorY);
      });
    });

    it("should check left cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x - data[i].errorX[1]);
        const xScaleMin = xScale.range()[0];
        const negativeErrorX = errorX <= xScaleMin
          ? xScaleMin : errorX;

        expect(node.findWhere((n) => n.key() === "crossLeft").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossLeft").props().x2)
          .to.equal(negativeErrorX);
        expect(node.findWhere((n) => n.key() === "crossLeft").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossLeft").props().y2)
          .to.equal(yScale(data[i].y));
      });
    });

    it("should check right cross line of error bars positions", () => {
      const svgDimensions = {width: 350, height: 200, padding: 75};
      const data = [
        {x: 0, y: 0, errorX: [0.1, 0.3], errorY: [0.2, 0.5]},
        {x: 2, y: 3, errorX: [0.1, 0.2], errorY: [0.2, 0.3]},
        {x: 5, y: 5, errorX: [0.1, 0.6], errorY: [0.2, 0.1]}
      ];
      const wrapper = mount(
        <VictoryErrorBar
          data={data}
          {...svgDimensions}
        />
      );

      const xScale = d3Scale.scaleLinear()
        .domain([-0.3, 5.1])
        .range([svgDimensions.padding, svgDimensions.width - svgDimensions.padding]);

      const yScale = d3Scale.scaleLinear()
        .domain([-0.5, 5.2])
        .range([svgDimensions.height - svgDimensions.padding, svgDimensions.padding]);

      const Data = wrapper.find(ErrorBar);
      Data.forEach((node, i) => {
        const errorX = xScale(data[i].x + data[i].errorX[0]);
        const xScaleMax = xScale.range()[1];
        const positiveErrorX = errorX >= xScaleMax
          ? xScaleMax : errorX;

        expect(node.findWhere((n) => n.key() === "crossRight").props().x1)
          .to.equal(xScale(data[i].x));
        expect(node.findWhere((n) => n.key() === "crossRight").props().x2)
          .to.equal(positiveErrorX);
        expect(node.findWhere((n) => n.key() === "crossRight").props().y1)
          .to.equal(yScale(data[i].y));
        expect(node.findWhere((n) => n.key() === "crossRight").props().y2)
          .to.equal(yScale(data[i].y));
      });
    });
{'fraction_non_alphanumeric': 0.18674666523812075, 'fraction_numerical': 0.033249406260602486, 'mean_word_length': 2.19627875121283, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 235, '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': '4825384', 'n_tokens_mistral': 20454, 'n_tokens_neox': 19355, 'n_words': 3864}