<commit_before>/**
 * Client tests
 */
/*eslint-disable max-nested-callbacks,no-unused-expressions,max-len */
/* global sinon */
import { range, omit } from "lodash";
import React from "react";
import { shallow, mount } from "enzyme";
import { Style, VictoryLabel, Slice } from "victory-core";
import SvgTestHelper from "../../../svg-test-helper";
import VictoryPie from "src/components/victory-pie";

class PizzaSlice extends React.Component {
  render() {}
}

describe("components/victory-pie", () => {
  describe("default component rendering", () => {
    it("renders an svg with the correct width and height", () => {
      const wrapper = mount(
        <VictoryPie/>
      );
      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(
        <VictoryPie/>
      );
      const svg = wrapper.find("svg");
      expect(svg.prop("viewBox")).to.equal("0 0 400 400");
    });

    it("renders 5 slices", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );

      const slices = wrapper.find(Slice);
      expect(slices).to.have.lengthOf(5);
    });

    it("renders each slice as a circular sector", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );
      const slices = wrapper.find(Slice);
      slices.forEach(SvgTestHelper.expectIsCircularSection);
    });

    it("renders 5 slice labels", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(5);
    });

    it("renders 0 slice labels for empty label array", () => {
      const wrapper = shallow(
        <VictoryPie
          labels={[]}
        />
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(0);
    });

    it("renders 0 slice labels for label function returning undefined", () => {
      const wrapper = shallow(
        <VictoryPie
          labels={() => {}}
        />
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(0);
    });
  });

  describe("rendering data", () => {
    it("renders dataComponents for {x, y} shaped data (default)", () => {
      const data = range(5).map((i) => ({x: i, y: i}));
      const wrapper = shallow(
        <VictoryPie
          data={data}
          dataComponent={<PizzaSlice />}
        />
      );
      const slices = wrapper.find(PizzaSlice);
      expect(slices.length).to.equal(5);
    });

    it("renders points for {x, y} shaped data (default)", () => {
      const data = range(5).map((i) => ({x: i, y: i}));
      const wrapper = shallow(<VictoryPie data={data}/>);
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(5);
    });

    it("renders points for array-shaped data", () => {
      const data = range(6).map((i) => [i, i]);
      const wrapper = shallow(<VictoryPie data={data} x={0} y={1}/>);
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(6);
    });

    it("renders points for deeply-nested data", () => {
      const data = range(7).map((i) => ({a: {b: [{x: i, y: i}]}}));
      const wrapper = shallow(
        <VictoryPie data={data} x="a.b[0].x" y="a.b[0].y"/>
      );
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(7);
    });

    it("renders data values with null accessor", () => {
      const data = range(8);
      const wrapper = shallow(
        <VictoryPie data={data} x={null} y={null}/>
      );
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(8);
    });

    it("renders data values in their given order", () => {
      const data = range(9).map((i) => ({x: i, y: i}));

      const wrapper = shallow(
        <VictoryPie data={data}/>
      );
      const xValues = wrapper.find(Slice).map((slice) => {
        return slice.prop('datum')._x;
      });

      expect(xValues).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8]);
    });

    it("renders data values sorted by dataSort prop", () => {
      const data = range(9).map((i) => ({x: i, y: i}));
      // reverse numerical sort
      const comparator = (a, b) => { return -(a._x - b._x); };

      const wrapper = shallow(
        <VictoryPie data={data} dataSort={comparator}/>
      );
      const xValues = wrapper.find(Slice).map((slice) => {
        return slice.prop('datum')._x;
      });

      expect(xValues).to.eql([8, 7, 6, 5, 4, 3, 2, 1, 0]);
    });
  });

  describe("the `startAngle` prop", () => {
    it("determines the counter clockwise angle relative to a cartesian Y axis of a vector extending from the origin to the _first drawn coordinate_ of the first slice ", () => {
      [0, 90, 180, 270].map((angle) => {
        const wrapper = shallow(
          <VictoryPie startAngle={angle}/>
        );

        const firstSlice = wrapper.find(Slice).first();
        const coordinates = SvgTestHelper.getSliceArcStart(firstSlice);
        const renderedAngle = SvgTestHelper.getSvgCoordinatesAngleFromCartesianYAxis(coordinates);

        // There is a small degree of inprecision due to how D3 renders the paths
        expect(renderedAngle).to.be.closeTo(angle, 0.0001);
      });
    });
  });

  describe("the `innerRadius` prop", () => {
    it("renders the slices as annular sections", () => {
      const wrapper = shallow(
        <VictoryPie innerRadius={70}/>
      );<commit_msg>eslint errors<commit_after>/**
 * Client tests
 */
/*eslint-disable max-nested-callbacks,no-unused-expressions,max-len */
/* global sinon */
import { range, omit } from "lodash";
import React from "react";
import { shallow, mount } from "enzyme";
import { Style, VictoryLabel, Slice } from "victory-core";
import SvgTestHelper from "../../../svg-test-helper";
import VictoryPie from "src/components/victory-pie";

class PizzaSlice extends React.Component {
  render() {}
}

describe("components/victory-pie", () => {
  describe("default component rendering", () => {
    it("renders an svg with the correct width and height", () => {
      const wrapper = mount(
        <VictoryPie/>
      );
      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(
        <VictoryPie/>
      );
      const svg = wrapper.find("svg");
      expect(svg.prop("viewBox")).to.equal("0 0 400 400");
    });

    it("renders 5 slices", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );

      const slices = wrapper.find(Slice);
      expect(slices).to.have.lengthOf(5);
    });

    it("renders each slice as a circular sector", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );
      const slices = wrapper.find(Slice);
      slices.forEach(SvgTestHelper.expectIsCircularSection);
    });

    it("renders 5 slice labels", () => {
      const wrapper = shallow(
        <VictoryPie/>
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(5);
    });

    it("renders 0 slice labels for empty label array", () => {
      const wrapper = shallow(
        <VictoryPie
          labels={[]}
        />
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(0);
    });

    it("renders 0 slice labels for label function returning undefined", () => {
      const wrapper = shallow(
        <VictoryPie
          labels={() => {}}
        />
      );

      const labels = wrapper.find(VictoryLabel);
      expect(labels).to.have.lengthOf(0);
    });
  });

  describe("rendering data", () => {
    it("renders dataComponents for {x, y} shaped data (default)", () => {
      const data = range(5).map((i) => ({x: i, y: i}));
      const wrapper = shallow(
        <VictoryPie
          data={data}
          dataComponent={<PizzaSlice />}
        />
      );
      const slices = wrapper.find(PizzaSlice);
      expect(slices.length).to.equal(5);
    });

    it("renders points for {x, y} shaped data (default)", () => {
      const data = range(5).map((i) => ({x: i, y: i}));
      const wrapper = shallow(<VictoryPie data={data}/>);
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(5);
    });

    it("renders points for array-shaped data", () => {
      const data = range(6).map((i) => [i, i]);
      const wrapper = shallow(<VictoryPie data={data} x={0} y={1}/>);
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(6);
    });

    it("renders points for deeply-nested data", () => {
      const data = range(7).map((i) => ({a: {b: [{x: i, y: i}]}}));
      const wrapper = shallow(
        <VictoryPie data={data} x="a.b[0].x" y="a.b[0].y"/>
      );
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(7);
    });

    it("renders data values with null accessor", () => {
      const data = range(8);
      const wrapper = shallow(
        <VictoryPie data={data} x={null} y={null}/>
      );
      const slices = wrapper.find(Slice);
      expect(slices.length).to.equal(8);
    });

    it("renders data values in their given order", () => {
      const data = range(9).map((i) => ({x: i, y: i}));

      const wrapper = shallow(
        <VictoryPie data={data}/>
      );
      const xValues = wrapper.find(Slice).map((slice) => {
        return slice.prop("datum")._x;
      });

      expect(xValues).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8]);
    });

    it("renders data values sorted by dataSort prop", () => {
      const data = range(9).map((i) => ({x: i, y: i}));
      // reverse numerical sort
      const comparator = (a, b) => { return -(a._x - b._x); };

      const wrapper = shallow(
        <VictoryPie data={data} dataSort={comparator}/>
      );
      const xValues = wrapper.find(Slice).map((slice) => {
        return slice.prop("datum")._x;
      });

      expect(xValues).to.eql([8, 7, 6, 5, 4, 3, 2, 1, 0]);
    });
  });

  describe("the `startAngle` prop", () => {
    it("determines the counter clockwise angle relative to a cartesian Y axis of a vector extending from the origin to the _first drawn coordinate_ of the first slice ", () => {
      [0, 90, 180, 270].map((angle) => {
        const wrapper = shallow(
          <VictoryPie startAngle={angle}/>
        );

        const firstSlice = wrapper.find(Slice).first();
        const coordinates = SvgTestHelper.getSliceArcStart(firstSlice);
        const renderedAngle = SvgTestHelper.getSvgCoordinatesAngleFromCartesianYAxis(coordinates);

        // There is a small degree of inprecision due to how D3 renders the paths
        expect(renderedAngle).to.be.closeTo(angle, 0.0001);
      });
    });
  });

  describe("the `innerRadius` prop", () => {
    it("renders the slices as annular sections", () => {
      const wrapper = shallow(
        <VictoryPie innerRadius={70}/>
      );
{'fraction_non_alphanumeric': 0.17365484973906783, 'fraction_numerical': 0.0125967248515386, 'mean_word_length': 2.517405063291139, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 101, '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': '363651', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3508, 'n_words': 847}