update tests, change naming

This commit is contained in:
Loewy 2024-01-10 18:09:47 -08:00
parent 6c7ceb3eb3
commit dee04269bd
4 changed files with 10 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { Path } from 'react-native-svg'; import { Path } from 'react-native-svg';
import { calculateBarProps, drawBarPath } from './custom-bar-utils'; import { calculateBarOrigin, drawBarPath } from './custom-bar-utils';
import { ScaleFunction } from './graph-types'; import { ScaleFunction } from './graph-types';
interface BarProps { interface BarProps {
@ -27,7 +27,7 @@ export const Bar: React.FC<BarProps> = ({
gap, gap,
roundedRadius roundedRadius
}) => { }) => {
const { xOrigin, yOrigin, height } = calculateBarProps({ const { xOrigin, yOrigin, height } = calculateBarOrigin({
scaleX, scaleX,
scaleY, scaleY,
index, index,

View File

@ -12,7 +12,7 @@ type BarCalculationProps = {
gap: number; gap: number;
}; };
export function calculateBarProps({ export function calculateBarOrigin({
scaleX, scaleX,
scaleY, scaleY,
barWidth, barWidth,

View File

@ -41,8 +41,8 @@ export const CustomBars: React.FC<CustomBarsProps> = ({
scaleX={scaleX} scaleX={scaleX}
scaleY={scaleY} scaleY={scaleY}
data={item.data[index]} data={item.data[index]}
barNumber={i} barNumber={i} // index of bar
index={index} index={index} // index of group
fill={barColors[i]} fill={barColors[i]}
barWidth={barWidth} barWidth={barWidth}
gap={gap} gap={gap}

View File

@ -4,7 +4,7 @@ import "@testing-library/jest-native/extend-expect";
import * as scale from 'd3-scale' import * as scale from 'd3-scale'
import { CustomBars } from '../../component/custom-bars'; import { CustomBars } from '../../component/custom-bars';
import { calculateBarProps, drawBarPath } from '../../component/custom-bar-utils'; import { calculateBarOrigin, drawBarPath } from '../../component/custom-bar-utils';
const mockYScaleFunction = scale.scaleLinear(); const mockYScaleFunction = scale.scaleLinear();
@ -47,7 +47,7 @@ describe('CustomBars Component Tests', () => {
}); });
describe('Bar utility functions', () => { describe('Bar utility functions', () => {
describe('calculateBarProps', () => { describe('calculateBarOrigin', () => {
it('calculates properties correctly', () => { it('calculates properties correctly', () => {
const mockData = { value: 10 }; const mockData = { value: 10 };
const mockIndex = 1; const mockIndex = 1;
@ -55,7 +55,7 @@ describe('Bar utility functions', () => {
const mockBarWidth = 20; const mockBarWidth = 20;
const mockGap = 5; const mockGap = 5;
const result = calculateBarProps({ const result = calculateBarOrigin({
scaleX: mockXScaleFunction, scaleX: mockXScaleFunction,
scaleY: mockYScaleFunction, scaleY: mockYScaleFunction,
data: mockData, data: mockData,
@ -81,10 +81,9 @@ describe('Bar utility functions', () => {
const roundedRadius = 10; const roundedRadius = 10;
const path = drawBarPath(xOrigin, yOrigin, barWidth, height, roundedRadius); const path = drawBarPath(xOrigin, yOrigin, barWidth, height, roundedRadius);
const expectedPath = 'M50,160L50,110A10,10,0,0,1,60,100L60,100A10,10,0,0,1,70,110L70,160L50,160Z'
expect(typeof path).toBe('string'); expect(path).toBe(expectedPath);
const regexPattern = /M.*,.*L.*,.*A.*,.*,.*,.*,.*,.*,.*L.*,.*A.*,.*,.*,.*,.*,.*,.*L.*,.*L.*,.*Z/;
expect(path).toMatch(regexPattern);
}); });
}); });
}); });