Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [#2597] Prevent Line Chart from crashing when having no data #2669

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/line/tests/Line.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ describe('mouse events on slices', () => {
})
})

describe('touch events with useMesh', () => {
describe('events with useMesh', () => {
const data = [
{
id: 'A',
Expand All @@ -457,13 +457,26 @@ describe('touch events with useMesh', () => {
enableTouchCrosshair: true,
}

it('should not throw onMouseEnter on empty data', () => {
const onMouseEnter = jest.fn()
const wrapper = mount(<Line {...baseProps} data={[]} onMouseEnter={onMouseEnter} />)
expect(() =>
wrapper.find(`[data-ref='mesh-interceptor']`).simulate('mouseenter', {
clientX: 50,
clientY: 50,
})
).not.toThrow()
wrapper.unmount()
})

it('should call onTouchStart', () => {
const onTouchStart = jest.fn()
const wrapper = mount(<Line {...baseProps} onTouchStart={onTouchStart} />)
wrapper.find(`[data-ref='mesh-interceptor']`).simulate('touchstart', {
touches: [{ clientX: 50, clientY: 50 }],
})
expect(onTouchStart).toHaveBeenCalledTimes(1)
wrapper.unmount()
})

it('should call onTouchMove', () => {
Expand All @@ -473,6 +486,7 @@ describe('touch events with useMesh', () => {
touches: [{ clientX: 50, clientY: 50 }],
})
expect(onTouchMove).toHaveBeenCalledTimes(1)
wrapper.unmount()
})

it('should call onTouchEnd', () => {
Expand All @@ -485,6 +499,7 @@ describe('touch events with useMesh', () => {
})
.simulate('touchend')
expect(onTouchEnd).toHaveBeenCalledTimes(1)
wrapper.unmount()
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/voronoi/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const useMeshEvents = <Node, ElementType extends Element>({

const findNode = useCallback(
(event: MouseEvent<ElementType> | TouchEvent<ElementType>): null | [number, Node] => {
if (!elementRef.current) return null
if (!elementRef.current || nodes.length === 0) return null

const [x, y] = getRelativeCursor(elementRef.current, event)

Expand Down
Loading