Skip to content

Commit 35111f7

Browse files
committedJan 12, 2022
feat(heatmap): add tests for layers and annotations
1 parent 8f9ca82 commit 35111f7

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed
 

‎packages/heatmap/tests/HeatMap.test.tsx

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { mount } from 'enzyme'
22
import { Globals } from '@react-spring/web'
3+
import { Axes, Grid } from '@nivo/axes'
4+
import { Annotation } from '@nivo/annotations'
35
// @ts-ignore
46
import { HeatMap, HeatMapSvgProps, DefaultHeatMapDatum } from '../src'
57

@@ -180,45 +182,39 @@ describe('interactivity', () => {
180182

181183
describe('layers', () => {
182184
it('custom order', () => {
183-
/*
184-
const wrapper = mount(<Network {...baseProps} layers={['nodes', 'links']} />)
185+
const wrapper = mount(<HeatMap {...baseProps} layers={['cells', 'axes', 'grid']} />)
185186

186187
const layers = wrapper.find('svg > g').children()
187-
expect(layers.at(0).is('NetworkNodes')).toBeTruthy()
188-
expect(layers.at(1).is('NetworkLinks')).toBeTruthy()
189-
*/
188+
expect(layers).toHaveLength(3)
189+
expect(layers.at(0).is('HeatMapCells')).toBeTruthy()
190+
expect(layers.at(1).is(Axes)).toBeTruthy()
191+
expect(layers.at(2).is(Grid)).toBeTruthy()
190192
})
191193

192194
it('custom layer', () => {
193-
/*
194195
const CustomLayer = () => null
195-
const wrapper = mount(<Network {...baseProps} layers={[CustomLayer]} />)
196+
const wrapper = mount(<HeatMap {...baseProps} layers={[CustomLayer]} />)
196197

197198
const customLayer = wrapper.find(CustomLayer)
198199
expect(customLayer.exists()).toBeTruthy()
199200

200201
const customLayerProps = customLayer.props()
201-
expect(customLayerProps).toHaveProperty('nodes')
202-
expect(customLayerProps).toHaveProperty('links')
203-
expect(customLayerProps).toHaveProperty('activeNodeIds')
204-
expect(customLayerProps).toHaveProperty('setActiveNodeIds')
205-
*/
202+
expect(customLayerProps).toHaveProperty('cells')
203+
expect(customLayerProps).toHaveProperty('activeCell')
204+
expect(customLayerProps).toHaveProperty('setActiveCell')
206205
})
207206
})
208207

209208
describe('annotations', () => {
210-
it('rect annotation using id', () => {
211-
/*
212-
const annotatedNodeId = 'C'
209+
it('annotation using id', () => {
210+
const annotatedCellId = 'B.Y'
213211
const wrapper = mount(
214-
<Network
212+
<HeatMap
215213
{...baseProps}
216214
annotations={[
217215
{
218216
type: 'circle',
219-
match: {
220-
id: annotatedNodeId,
221-
},
217+
match: { id: annotatedCellId },
222218
note: 'Note',
223219
noteX: 160,
224220
noteY: 36,
@@ -230,16 +226,15 @@ describe('annotations', () => {
230226
const annotation = wrapper.find(Annotation)
231227
expect(annotation.exists()).toBeTruthy()
232228

233-
const annotatedNode = wrapper.find(`circle[data-testid='node.${annotatedNodeId}']`)
234-
const [nodeX, nodeY] = Array.from(
235-
annotatedNode.prop('transform').match(/translate\(([0-9.]+),([0-9.]+)\)/)
229+
const annotatedCell = wrapper.find(`g[data-testid='cell.${annotatedCellId}']`)
230+
const [cellX, cellY] = Array.from(
231+
annotatedCell.prop<string>('transform').match(/translate\(([0-9.]+), ([0-9.]+)\)/)!
236232
)
237233
.slice(1)
238234
.map(Number)
239235

240-
expect(annotation.find('circle').first().prop('cx')).toEqual(nodeX)
241-
expect(annotation.find('circle').first().prop('cy')).toEqual(nodeY)
242-
*/
236+
expect(annotation.find('circle').first().prop('cx')).toEqual(cellX)
237+
expect(annotation.find('circle').first().prop('cy')).toEqual(cellY)
243238
})
244239
})
245240

@@ -255,7 +250,6 @@ describe('accessibility', () => {
255250
)
256251

257252
const svg = wrapper.find('svg')
258-
259253
expect(svg.prop('aria-label')).toBe('AriaLabel')
260254
expect(svg.prop('aria-labelledby')).toBe('AriaLabelledBy')
261255
expect(svg.prop('aria-describedby')).toBe('AriaDescribedBy')

0 commit comments

Comments
 (0)
Please sign in to comment.