Skip to content

Commit

Permalink
feat(bubble): trigger onClick when isZoomable is false (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
fozcodes authored and Raphaël Benitte committed Oct 23, 2018
1 parent 1b1b6d9 commit 787341a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/circle-packing/src/interactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const getNodeHandlers = (
onClick(node, event)
zoomToNode(node.path)
}
} else {
clickHandler = event => {
onClick(node, event)
}
}

return {
Expand Down
25 changes: 24 additions & 1 deletion packages/circle-packing/tests/Bubble.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { render } from 'enzyme'
import { render, mount } from 'enzyme'
import Bubble from '../src/Bubble'

const sampleData = {
Expand Down Expand Up @@ -63,3 +63,26 @@ it(`should allow to skip labels using 'labelSkipRadius' if radius is lower than

expect(wrapper.find('text').length).toBe(6)
})

it(`should send node data to onClick when 'isZoomable' is false`, () => {
const onClickHandler = jest.fn(node => node.data)
const wrapper = mount(
<Bubble
width={600}
height={600}
root={sampleData}
enableLabel={true}
labelSkipRadius={24}
isZoomable={false}
onClick={onClickHandler}
/>
)

wrapper
.find('circle')
.at(0) //click the first <circle> (the root)
.simulate('click')

expect(onClickHandler.mock.calls.length).toBe(1)
expect(onClickHandler.mock.results[0].value).toEqual(sampleData)
})

0 comments on commit 787341a

Please sign in to comment.