/
HeatMap.test.js
62 lines (55 loc) · 1.5 KB
/
HeatMap.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'
import HeatMapCellRect from '../src/HeatMapCellRect'
import HeatMap from '../src/HeatMap'
const sampleProps = {
indexBy: 'age',
keys: ['rent', 'loan', 'income'],
data: [
{
age: 20,
rent: 30,
loan: 24,
income: 60,
},
{
age: 30,
rent: 40,
loan: 50,
income: 90,
},
{
age: 40,
rent: 20,
loan: 13,
income: 40,
},
],
width: 500,
height: 300,
animate: false,
}
it('should render a basic heat map chart', () => {
const component = renderer.create(<HeatMap {...sampleProps} />)
let tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
it('should allow to disable labels', () => {
const wrapper = mount(<HeatMap {...sampleProps} enableLabels={false} />)
const cells = wrapper.find(HeatMapCellRect)
expect(cells).toHaveLength(9)
cells.forEach(cell => {
expect(cell.find('text').exists()).toBe(false)
})
})
it('should allow to format labels', () => {
const wrapper = mount(
<HeatMap {...sampleProps} label={(datum, key) => datum[key].toFixed(2)} />
)
const cells = wrapper.find(HeatMapCellRect)
expect(cells).toHaveLength(9)
cells.forEach(cell => {
expect(cell.find('text').exists()).toBe(true)
expect(cell.find('text').text().length).toEqual(5)
})
})