1
1
import { mount } from 'enzyme'
2
2
import { Globals } from '@react-spring/web'
3
+ import { Axes , Grid } from '@nivo/axes'
4
+ import { Annotation } from '@nivo/annotations'
3
5
// @ts -ignore
4
6
import { HeatMap , HeatMapSvgProps , DefaultHeatMapDatum } from '../src'
5
7
@@ -180,45 +182,39 @@ describe('interactivity', () => {
180
182
181
183
describe ( 'layers' , ( ) => {
182
184
it ( 'custom order' , ( ) => {
183
- /*
184
- const wrapper = mount(<Network {...baseProps} layers={['nodes', 'links']} />)
185
+ const wrapper = mount ( < HeatMap { ...baseProps } layers = { [ 'cells' , 'axes' , 'grid' ] } /> )
185
186
186
187
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 ( )
190
192
} )
191
193
192
194
it ( 'custom layer' , ( ) => {
193
- /*
194
195
const CustomLayer = ( ) => null
195
- const wrapper = mount(<Network {...baseProps} layers={[CustomLayer]} />)
196
+ const wrapper = mount ( < HeatMap { ...baseProps } layers = { [ CustomLayer ] } /> )
196
197
197
198
const customLayer = wrapper . find ( CustomLayer )
198
199
expect ( customLayer . exists ( ) ) . toBeTruthy ( )
199
200
200
201
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' )
206
205
} )
207
206
} )
208
207
209
208
describe ( 'annotations' , ( ) => {
210
- it ( 'rect annotation using id' , ( ) => {
211
- /*
212
- const annotatedNodeId = 'C'
209
+ it ( 'annotation using id' , ( ) => {
210
+ const annotatedCellId = 'B.Y'
213
211
const wrapper = mount (
214
- <Network
212
+ < HeatMap
215
213
{ ...baseProps }
216
214
annotations = { [
217
215
{
218
216
type : 'circle' ,
219
- match: {
220
- id: annotatedNodeId,
221
- },
217
+ match : { id : annotatedCellId } ,
222
218
note : 'Note' ,
223
219
noteX : 160 ,
224
220
noteY : 36 ,
@@ -230,16 +226,15 @@ describe('annotations', () => {
230
226
const annotation = wrapper . find ( Annotation )
231
227
expect ( annotation . exists ( ) ) . toBeTruthy ( )
232
228
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 ( / t r a n s l a t e \( ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) \) / ) !
236
232
)
237
233
. slice ( 1 )
238
234
. map ( Number )
239
235
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 )
243
238
} )
244
239
} )
245
240
@@ -255,7 +250,6 @@ describe('accessibility', () => {
255
250
)
256
251
257
252
const svg = wrapper . find ( 'svg' )
258
-
259
253
expect ( svg . prop ( 'aria-label' ) ) . toBe ( 'AriaLabel' )
260
254
expect ( svg . prop ( 'aria-labelledby' ) ) . toBe ( 'AriaLabelledBy' )
261
255
expect ( svg . prop ( 'aria-describedby' ) ) . toBe ( 'AriaDescribedBy' )
0 commit comments