/
ScatterPlot.test.js
133 lines (119 loc) · 3.63 KB
/
ScatterPlot.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'
import ScatterPlot from '../src/ScatterPlot'
const sampleData = [
{ id: 0, x: 0, y: 9 },
{ id: 1, x: 7, y: 13 },
{ id: 2, x: 22, y: 18 },
{ id: 3, x: 33, y: 23 },
{ id: 4, x: 45, y: 31 },
]
it('should render a basic scatterplot chart', () => {
const component = renderer.create(
<ScatterPlot width={500} height={300} data={[{ id: 'default', data: sampleData }]} />
)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
it('should allow to render several series', () => {
const component = renderer.create(
<ScatterPlot
width={500}
height={300}
data={[
{ id: 'default', data: sampleData },
{ id: 'extra', data: sampleData },
]}
/>
)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
it('should allow to customize node size', () => {
const wrapper = mount(
<ScatterPlot
width={500}
height={300}
nodeSize={12}
data={[{ id: 'default', data: sampleData }]}
/>
)
const nodes = wrapper.find('Memo(Node)')
expect(nodes).toHaveLength(5)
nodes.forEach(node => {
expect(node.prop('size')).toBe(12)
})
})
it('should allow to use a varying node size', () => {
const wrapper = mount(
<ScatterPlot
width={500}
height={300}
useMesh={false}
data={[
{
id: 'default',
data: [
{ x: 0, y: 0, z: 3 },
{ x: 1, y: 1, z: 5 },
{ x: 2, y: 2, z: 8 },
],
},
]}
nodeSize={{
key: 'z',
values: [0, 10],
sizes: [0, 20],
}}
/>
)
const nodes = wrapper.find('Memo(Node)')
expect(nodes).toHaveLength(3)
expect(nodes.at(0).prop('size')).toBe(6)
expect(nodes.at(1).prop('size')).toBe(10)
expect(nodes.at(2).prop('size')).toBe(16)
})
const CustomNode = () => <g />
it('should allow to use a custom node', () => {
const wrapper = mount(
<ScatterPlot
width={500}
height={300}
data={[{ id: 'default', data: sampleData }]}
renderNode={CustomNode}
/>
)
const nodes = wrapper.find(CustomNode)
expect(nodes).toHaveLength(5)
nodes.forEach(node => {
expect(node.prop('node')).toBeDefined()
expect(node.prop('x')).toBeDefined()
expect(node.prop('y')).toBeDefined()
expect(node.prop('size')).toBe(9)
expect(node.prop('color')).toBeDefined()
expect(node.prop('blendMode')).toBe('normal')
expect(node.prop('onMouseEnter')).toBeDefined()
expect(node.prop('onMouseMove')).toBeDefined()
expect(node.prop('onMouseLeave')).toBeDefined()
})
})
it('should allow to disable interactivity', () => {
const wrapper = mount(
<ScatterPlot
width={500}
height={300}
data={[{ id: 'default', data: sampleData }]}
isInteractive={false}
onClick={() => {}}
/>
)
const nodes = wrapper.find('Memo(Node)')
expect(nodes).toHaveLength(5)
nodes.forEach(node => {
expect(node.prop('onMouseEnter')).toBeUndefined()
expect(node.prop('onMouseMove')).toBeUndefined()
expect(node.prop('onMouseLeave')).toBeUndefined()
expect(node.prop('onClick')).toBeUndefined()
})
})