@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
50 lines (49 loc) • 2.05 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from "react";
import { shallow } from "enzyme";
import PieChart from "./PieChart";
describe("PieChart", function () {
var data = [{
x: "slice1",
y: 3000
}, {
x: "slice2",
y: 20
}, {
x: "slice3",
y: 6500
}];
var defaultProps = {
data: data
};
it("should render a VictoryPie inside a ChartContainer", function () {
var wrapper = shallow(React.createElement(PieChart, defaultProps));
expect(wrapper.find("ChartContainer")).to.have.length(1);
expect(wrapper.find("ChartContainer").children().find("VictoryPie")).to.have.length(1);
});
it("should show lapels in a legend if useLegend is true", function () {
var wrapper = shallow(React.createElement(PieChart, defaultProps));
expect(wrapper.find("SimpleLegend").length).to.eql(0);
wrapper.setProps({
useLegend: true
});
expect(wrapper.find("SimpleLegend").length).to.eql(1);
});
describe("nullable props handling", function () {
var nullProps = {};
var valueProps = {
dataLabel: "x",
dataValue: "y"
};
var nulledWrapper = shallow(React.createElement(PieChart, _extends({}, defaultProps, nullProps)));
var valuedWrapper = shallow(React.createElement(PieChart, _extends({}, defaultProps, valueProps)));
it("should handle nullable dataKey", function () {
expect(nulledWrapper.find("VictoryPie").prop("x")).to.eql("x");
expect(valuedWrapper.find("VictoryPie").prop("x")).to.eql(valueProps.dataLabel);
});
it("should handle nullable labelKey", function () {
expect(nulledWrapper.find("VictoryPie").prop("y")).to.eql("y");
expect(valuedWrapper.find("VictoryPie").prop("y")).to.eql(valueProps.dataValue);
});
});
});