From 2cbda7692d7b6978bdf46a07ec373883c7004505 Mon Sep 17 00:00:00 2001 From: plouc Date: Wed, 12 Jan 2022 09:56:37 +0900 Subject: [PATCH] feat(heatmap): add tests for forceSquare --- packages/heatmap/tests/HeatMap.test.tsx | 69 ++++++++++++++++++------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/packages/heatmap/tests/HeatMap.test.tsx b/packages/heatmap/tests/HeatMap.test.tsx index 6afad57b62..08aa0604a5 100644 --- a/packages/heatmap/tests/HeatMap.test.tsx +++ b/packages/heatmap/tests/HeatMap.test.tsx @@ -59,7 +59,7 @@ afterAll(() => { Globals.assign({ skipAnimation: false }) }) -it('should render a basic heamap chart', () => { +it('should render a basic heatmap chart', () => { const wrapper = mount() dataPoints.forEach(datum => { @@ -72,26 +72,59 @@ it('should render a basic heamap chart', () => { }) }) +describe('force square cells', () => { + const expectedSquareSize = 100 + + CELL_SHAPES.forEach(shape => { + describe(shape, () => { + it('cells should have square dimensions', () => { + const wrapper = mount( + + ) + + dataPoints.forEach(datum => { + const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`) + const cellShape = cell.find(shape).parent() + + if (shape === 'rect') { + expect(cellShape.prop>('width').get()).toEqual( + expectedSquareSize + ) + expect(cellShape.prop>('height').get()).toEqual( + expectedSquareSize + ) + } else { + expect(cellShape.prop>('r').get() * 2).toEqual( + expectedSquareSize + ) + } + }) + }) + }) + }) +}) + describe('size variation', () => { + // use simpler data for easier assertions + const sizeVariationData = [ + { + id: 'A', + data: [ + { x: 'X', y: 5 }, + { x: 'Y', y: 10 }, + ], + }, + { + id: 'B', + data: [ + { x: 'X', y: 7.5 }, + { x: 'Y', y: 10 }, + ], + }, + ] + CELL_SHAPES.forEach(shape => { describe(shape, () => { - // use simpler data for easier assertions - const sizeVariationData = [ - { - id: 'A', - data: [ - { x: 'X', y: 5 }, - { x: 'Y', y: 10 }, - ], - }, - { - id: 'B', - data: [ - { x: 'X', y: 7.5 }, - { x: 'Y', y: 10 }, - ], - }, - ] const cellIdAndValues: { id: string; value: number }[] = [] sizeVariationData.forEach(serie => { serie.data.forEach(datum => {