Skip to content

Commit

Permalink
feat(bump): add tests for the Bump chart
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 29, 2021
1 parent 4be280b commit 90006b6
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 217 deletions.
201 changes: 0 additions & 201 deletions packages/bump/_old_index.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/bump/src/bump/Line.tsx
Expand Up @@ -60,6 +60,7 @@ export const Line = <D extends BumpDatum>({
return (
<>
<animated.path
data-testid={`line.${serie.id}`}
fill="none"
d={animatedPath}
stroke={animatedProps.color}
Expand All @@ -70,6 +71,7 @@ export const Line = <D extends BumpDatum>({
/>
{isInteractive && (
<path
data-testid={`line.${serie.id}.interactive`}
fill="none"
stroke="red"
strokeOpacity={0}
Expand Down
11 changes: 8 additions & 3 deletions packages/bump/src/bump/LineTooltip.tsx
Expand Up @@ -5,6 +5,11 @@ interface LineTooltipProps<D extends BumpDatum> {
serie: BumpComputedSerie<D>
}

export const LineTooltip = <D extends BumpDatum>({ serie }: LineTooltipProps<D>) => {
return <BasicTooltip id={serie.id} enableChip={true} color={serie.color} />
}
export const LineTooltip = <D extends BumpDatum>({ serie }: LineTooltipProps<D>) => (
<BasicTooltip
data-testid={`tooltip.${serie.id}`}
id={serie.id}
enableChip={true}
color={serie.color}
/>
)
3 changes: 2 additions & 1 deletion packages/bump/src/bump/LinesLabels.tsx
Expand Up @@ -6,7 +6,7 @@ import { useBumpSeriesLabels } from './hooks'

interface LineLabelsProps<D extends BumpDatum> {
series: BumpComputedSerie<D>[]
getLabel: BumpLabel
getLabel: BumpLabel<D>
position: 'start' | 'end'
padding: number
color: InheritedColorConfig<BumpComputedSerie<D>>
Expand Down Expand Up @@ -52,6 +52,7 @@ export const LinesLabels = <D extends BumpDatum>({

return (
<animated.text
data-testid={`label.${position}.${label.serie.id}`}
key={label.id}
x={animatedProps.x}
y={animatedProps.y}
Expand Down
1 change: 1 addition & 0 deletions packages/bump/src/bump/Point.tsx
Expand Up @@ -30,6 +30,7 @@ export const Point = <D extends BumpDatum>({ point }: PointProps<D>) => {

return (
<animated.circle
data-testid={`point.${point.serie.id}.${point.data.x}`}
cx={animatedProps.x}
cy={animatedProps.y}
r={to(animatedProps.radius, v => Math.max(v, 0))}
Expand Down
6 changes: 3 additions & 3 deletions packages/bump/src/bump/defaults.ts
@@ -1,7 +1,7 @@
import { ModernMotionProps } from '@nivo/core'
import { LineTooltip } from './LineTooltip'
import { Point } from './Point'
import { BumpCommonProps, BumpSvgProps } from './types'
import { BumpCommonProps, BumpPointComponent } from './types'

const commonDefaultProps: Omit<
BumpCommonProps<any>,
Expand Down Expand Up @@ -32,7 +32,7 @@ const commonDefaultProps: Omit<
startLabel: false,
startLabelPadding: 16,
startLabelTextColor: { from: 'color' },
endLabel: 'id',
endLabel: true,
endLabelPadding: 16,
endLabelTextColor: { from: 'color' },

Expand All @@ -59,7 +59,7 @@ const commonDefaultProps: Omit<
}

export const bumpSvgDefaultProps: typeof commonDefaultProps & {
pointComponent: BumpSvgProps<any>['pointComponent']
pointComponent: BumpPointComponent<any>
animate: boolean
motionConfig: ModernMotionProps['motionConfig']
} = {
Expand Down
2 changes: 1 addition & 1 deletion packages/bump/src/bump/hooks.ts
Expand Up @@ -375,7 +375,7 @@ export const useBumpSeriesLabels = <D extends BumpDatum>({
position: 'start' | 'end'
padding: number
color: InheritedColorConfig<BumpComputedSerie<D>>
getLabel: BumpLabel
getLabel: BumpLabel<D>
}) => {
const theme = useTheme()
const getColor = useInheritedColor(color, theme)
Expand Down
10 changes: 5 additions & 5 deletions packages/bump/src/bump/types.ts
@@ -1,5 +1,5 @@
import { FunctionComponent, MouseEvent } from 'react'
import { Theme, Box, Dimensions, ModernMotionProps, PropertyAccessor } from '@nivo/core'
import { Theme, Box, Dimensions, ModernMotionProps } from '@nivo/core'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'
import { AxisProps } from '@nivo/axes'

Expand Down Expand Up @@ -56,7 +56,7 @@ export type BumpDataProps<D extends BumpDatum> = {

export type BumpInterpolation = 'smooth' | 'linear'

export type BumpLabel = PropertyAccessor<any, string> | false
export type BumpLabel<D extends BumpDatum> = ((serie: BumpComputedSerie<D>) => string) | boolean
export interface BumpLabelData<D extends BumpDatum> {
serie: BumpComputedSerie<D>
id: BumpSerie<D>['id']
Expand Down Expand Up @@ -94,10 +94,10 @@ export type BumpCommonProps<D extends BumpDatum> = {
activeOpacity: number
inactiveOpacity: number

startLabel: BumpLabel
startLabel: BumpLabel<D>
startLabelPadding: number
startLabelTextColor: InheritedColorConfig<BumpComputedSerie<D>>
endLabel: BumpLabel
endLabel: BumpLabel<D>
endLabelPadding: number
endLabelTextColor: InheritedColorConfig<BumpComputedSerie<D>>

Expand Down Expand Up @@ -133,6 +133,6 @@ export type BumpCommonProps<D extends BumpDatum> = {

export type BumpSvgProps<D extends BumpDatum> = Partial<BumpCommonProps<D>> &
BumpDataProps<D> & {
pointComponent: BumpPointComponent<D>
pointComponent?: BumpPointComponent<D>
} & Dimensions &
ModernMotionProps
2 changes: 2 additions & 0 deletions packages/bump/tests/.eslintrc.yml
@@ -0,0 +1,2 @@
env:
jest: true

0 comments on commit 90006b6

Please sign in to comment.