-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function localPoint() { | ||
return { | ||
x: 5, | ||
y: 3, | ||
value: () => ({ x: 5, y: 3 }), | ||
toArray: () => [5, 3], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useEffect } from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { BarGroup, BarSeries, DataProvider, useEventEmitter } from '../../src'; | ||
import setupTooltipTest from '../mocks/setupTooltipTest.test'; | ||
|
||
const providerProps = { | ||
initialDimensions: { width: 100, height: 100 }, | ||
xScale: { type: 'linear' }, | ||
yScale: { type: 'linear' }, | ||
} as const; | ||
|
||
const accessors = { | ||
xAccessor: (d: { x: number }) => d.x, | ||
yAccessor: (d: { y: number }) => d.y, | ||
}; | ||
|
||
const series1 = { | ||
key: 'bar1', | ||
data: [ | ||
{ x: 10, y: 5 }, | ||
{ x: 7, y: 5 }, | ||
], | ||
...accessors, | ||
}; | ||
|
||
const series2 = { | ||
key: 'bar2', | ||
data: [ | ||
{ x: 10, y: 5 }, | ||
{ x: 7, y: 20 }, | ||
], | ||
...accessors, | ||
}; | ||
|
||
describe('<BarGroup />', () => { | ||
it('should be defined', () => { | ||
expect(BarSeries).toBeDefined(); | ||
}); | ||
|
||
it('should render rects', () => { | ||
const wrapper = mount( | ||
<DataProvider {...providerProps}> | ||
<svg> | ||
<BarGroup horizontal> | ||
<BarSeries dataKey={series1.key} {...series1} /> | ||
<BarSeries dataKey={series2.key} {...series2} /> | ||
</BarGroup> | ||
</svg> | ||
</DataProvider>, | ||
); | ||
expect(wrapper.find('rect')).toHaveLength(4); | ||
}); | ||
|
||
it('should invoke showTooltip/hideTooltip on mousemove/mouseout', () => { | ||
expect.assertions(2); | ||
|
||
const showTooltip = jest.fn(); | ||
const hideTooltip = jest.fn(); | ||
|
||
const EventEmitter = () => { | ||
const emit = useEventEmitter(); | ||
|
||
useEffect(() => { | ||
if (emit) { | ||
// @ts-ignore not a React.MouseEvent | ||
emit('mousemove', new MouseEvent('mousemove')); | ||
expect(showTooltip).toHaveBeenCalledTimes(2); // one per key | ||
|
||
// @ts-ignore not a React.MouseEvent | ||
emit('mouseout', new MouseEvent('mouseout')); | ||
expect(showTooltip).toHaveBeenCalled(); | ||
} | ||
}); | ||
|
||
return null; | ||
}; | ||
|
||
setupTooltipTest( | ||
<> | ||
<BarGroup horizontal> | ||
<BarSeries dataKey={series1.key} {...series1} /> | ||
<BarSeries dataKey={series2.key} {...series2} /> | ||
</BarGroup> | ||
<EventEmitter /> | ||
</>, | ||
{ showTooltip, hideTooltip }, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/visx-xychart/test/mocks/setupTooltipTest.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { DataProvider, EventEmitterProvider, TooltipContext, TooltipContextType } from '../../src'; | ||
|
||
const providerProps = { | ||
initialDimensions: { width: 100, height: 100 }, | ||
xScale: { type: 'linear' }, | ||
yScale: { type: 'linear' }, | ||
} as const; | ||
|
||
const defaultTooltipContext = { | ||
tooltipOpen: false, | ||
showTooltip: jest.fn(), | ||
updateTooltip: jest.fn(), | ||
hideTooltip: jest.fn(), | ||
}; | ||
|
||
// sets up boilerplate context for testing tooltips | ||
export default function setupTooltipTest( | ||
children: React.ReactNode, | ||
tooltipContext?: Partial<TooltipContextType<object>>, | ||
) { | ||
return mount( | ||
<DataProvider {...providerProps}> | ||
<EventEmitterProvider> | ||
<TooltipContext.Provider value={{ ...defaultTooltipContext, ...tooltipContext }}> | ||
<svg>{children}</svg> | ||
</TooltipContext.Provider> | ||
</EventEmitterProvider> | ||
</DataProvider>, | ||
); | ||
} |