From d92ecd9cde37d744b5dd0925391f7c6fa0b21343 Mon Sep 17 00:00:00 2001 From: plouc Date: Sun, 9 Jan 2022 15:29:16 +0900 Subject: [PATCH] feat(heatmap): add tests for hoverTarget --- packages/heatmap/tests/HeatMap.test.tsx | 98 +++++++++++++++++++++++++ packages/network/tests/Network.test.tsx | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/packages/heatmap/tests/HeatMap.test.tsx b/packages/heatmap/tests/HeatMap.test.tsx index 3f5596bee3..943863b289 100644 --- a/packages/heatmap/tests/HeatMap.test.tsx +++ b/packages/heatmap/tests/HeatMap.test.tsx @@ -176,6 +176,104 @@ describe('interactivity', () => { expect(onClick).not.toHaveBeenCalled() }) }) + + describe('active/inactive', () => { + it('should support single cell hover target', () => { + const wrapper = mount( + + ) + + const hoveredCell = wrapper.find(`g[data-testid='cell.B.Y']`) + hoveredCell.simulate('mouseenter') + + const activeCellIds = ['B.Y'] + dataPoints.forEach(datum => { + const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`).parent() + if (activeCellIds.includes(datum.id)) { + expect(cell.prop('opacity').get()).toEqual(1) + } else { + expect(cell.prop('opacity').get()).toEqual(0) + } + }) + }) + + it('should support row hover target', () => { + const wrapper = mount( + + ) + + const hoveredCell = wrapper.find(`g[data-testid='cell.B.Y']`) + hoveredCell.simulate('mouseenter') + + const activeCellIds = ['B.X', 'B.Y', 'B.Z'] + dataPoints.forEach(datum => { + const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`).parent() + if (activeCellIds.includes(datum.id)) { + expect(cell.prop('opacity').get()).toEqual(1) + } else { + expect(cell.prop('opacity').get()).toEqual(0) + } + }) + }) + + it('should support column hover target', () => { + const wrapper = mount( + + ) + + const hoveredCell = wrapper.find(`g[data-testid='cell.B.Y']`) + hoveredCell.simulate('mouseenter') + + const activeCellIds = ['A.Y', 'B.Y', 'C.Y'] + dataPoints.forEach(datum => { + const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`).parent() + if (activeCellIds.includes(datum.id)) { + expect(cell.prop('opacity').get()).toEqual(1) + } else { + expect(cell.prop('opacity').get()).toEqual(0) + } + }) + }) + + it('should support rowColumn hover target', () => { + const wrapper = mount( + + ) + + const hoveredCell = wrapper.find(`g[data-testid='cell.B.Y']`) + hoveredCell.simulate('mouseenter') + + const activeCellIds = ['B.X', 'B.Y', 'B.Z', 'A.Y', 'C.Y'] + dataPoints.forEach(datum => { + const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`).parent() + if (activeCellIds.includes(datum.id)) { + expect(cell.prop('opacity').get()).toEqual(1) + } else { + expect(cell.prop('opacity').get()).toEqual(0) + } + }) + }) + }) }) }) }) diff --git a/packages/network/tests/Network.test.tsx b/packages/network/tests/Network.test.tsx index cd3ac96c31..e34cee3f54 100644 --- a/packages/network/tests/Network.test.tsx +++ b/packages/network/tests/Network.test.tsx @@ -496,7 +496,7 @@ describe('annotations', () => { const annotatedNode = wrapper.find(`circle[data-testid='node.${annotatedNodeId}']`) const [nodeX, nodeY] = Array.from( - annotatedNode.prop('transform').match(/translate\(([0-9.]+),([0-9.]+)\)/) + annotatedNode.prop('transform').match(/translate\(([0-9.]+),([0-9.]+)\)/)! ) .slice(1) .map(Number)