kat/refactor-use-graph-data (#121)
Reviewed-on: railbird/railbird-mobile#121 Reviewed-by: Ivan Malison <ivanmalison@gmail.com>
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { renderHook } from "@testing-library/react-native";
|
||||
import { GraphData, GraphProps } from "../../src/component/charts/graph-types";
|
||||
import { useGraphData } from "../../src/component/charts/use-graph-data";
|
||||
import { GraphProps, XYValues } from "../../src/component/charts/graph-types";
|
||||
import {
|
||||
computeYAxisConfig,
|
||||
useGraphData,
|
||||
} from "../../src/component/charts/use-graph-data";
|
||||
|
||||
describe("useGraphData", () => {
|
||||
it("should return correctly processed data from convertToGraphData", () => {
|
||||
// mock values
|
||||
const mockGraphData: GraphData = {
|
||||
const mockGraphData: XYValues = {
|
||||
xValues: ["full hit", "3/4 ball ball", "1/2 ball"],
|
||||
yValues: [
|
||||
{ key: "left", values: [10, 20, 30] },
|
||||
@@ -23,8 +26,14 @@ describe("useGraphData", () => {
|
||||
formatLeftYAxisLabel: (value) => `${value}%`,
|
||||
},
|
||||
};
|
||||
const yAxisProps = computeYAxisConfig(
|
||||
mockGraphData,
|
||||
mockProps.yAxisProps || {},
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useGraphData(mockGraphData, mockProps));
|
||||
const { result } = renderHook(() =>
|
||||
useGraphData(mockGraphData, yAxisProps, mockProps),
|
||||
);
|
||||
// values expected
|
||||
const expectedYData = [
|
||||
{
|
||||
@@ -55,12 +64,5 @@ describe("useGraphData", () => {
|
||||
});
|
||||
expect(result.current.yAxisLeftLabels).toEqual(expectedLeftLabels);
|
||||
expect(result.current.yAxisRightLabels).toEqual(expectedRightLabels);
|
||||
expect(
|
||||
result.current.defaultProps.yAxisProps.selectedLeftYAxisLabel,
|
||||
).toEqual("left");
|
||||
expect(
|
||||
result.current.defaultProps.yAxisProps.selectedRightYAxisLabel,
|
||||
).toEqual("right");
|
||||
expect(result.current.defaultProps).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user