|
1 | 1 | import { mount } from 'enzyme'
|
2 |
| -import { Stream, StreamLayerDatum, StreamSvgProps } from '../src' |
| 2 | +import { Stream, StreamLayerData, StreamLayerDatum, StreamSliceData, StreamSvgProps } from '../src' |
3 | 3 |
|
4 | 4 | type TestDatum = {
|
5 | 5 | A: number
|
@@ -31,10 +31,7 @@ describe('layers', () => {
|
31 | 31 |
|
32 | 32 | it('should support custom layers', () => {
|
33 | 33 | const wrapper = mount(
|
34 |
| - <Stream<TestDatum> |
35 |
| - {...commonProps} |
36 |
| - layers={['grid', 'axes', 'layers', CustomLayer]} |
37 |
| - /> |
| 34 | + <Stream<TestDatum> {...commonProps} layers={['grid', 'axes', 'layers', CustomLayer]} /> |
38 | 35 | )
|
39 | 36 |
|
40 | 37 | const customLayer = wrapper.find(CustomLayer)
|
@@ -92,6 +89,64 @@ describe('dots', () => {
|
92 | 89 | })
|
93 | 90 | })
|
94 | 91 |
|
| 92 | +describe('tooltip', () => { |
| 93 | + it('should show a tooltip when hovering a layer', () => { |
| 94 | + const wrapper = mount(<Stream<TestDatum> {...commonProps} />) |
| 95 | + |
| 96 | + expect(wrapper.find('LayerTooltip').exists()).toBe(false) |
| 97 | + |
| 98 | + wrapper.find('StreamLayer').at(0).find('path').simulate('mouseEnter') |
| 99 | + const tooltip = wrapper.find('LayerTooltip') |
| 100 | + expect(tooltip.exists()).toBe(true) |
| 101 | + |
| 102 | + const layerData = tooltip.prop<StreamLayerData>('layer') |
| 103 | + expect(layerData.id).toBe(commonProps.keys[0]) |
| 104 | + }) |
| 105 | + |
| 106 | + it('should have stack tooltip enabled by default', () => { |
| 107 | + const wrapper = mount(<Stream<TestDatum> {...commonProps} />) |
| 108 | + |
| 109 | + const slices = wrapper.find('StreamSlices') |
| 110 | + expect(slices.exists()).toBe(true) |
| 111 | + |
| 112 | + const sliceRect = slices.find('StreamSlicesItem').at(0).find('rect') |
| 113 | + expect(sliceRect.exists()).toBe(true) |
| 114 | + |
| 115 | + sliceRect.simulate('mouseEnter') |
| 116 | + const tooltip = wrapper.find('StackTooltip') |
| 117 | + expect(tooltip.exists()).toBe(true) |
| 118 | + |
| 119 | + const sliceData = tooltip.prop<StreamSliceData>('slice') |
| 120 | + expect(sliceData.index).toBe(0) |
| 121 | + expect(sliceData.x).toBe(0) |
| 122 | + |
| 123 | + const expectedData = [ |
| 124 | + { layerId: 'C', value: 30 }, |
| 125 | + { layerId: 'B', value: 20 }, |
| 126 | + { layerId: 'A', value: 10 }, |
| 127 | + ] |
| 128 | + expectedData.forEach((expectedDatum, index) => { |
| 129 | + expect(sliceData.stack[index].layerId).toBe(expectedDatum.layerId) |
| 130 | + expect(sliceData.stack[index].value).toBe(expectedDatum.value) |
| 131 | + }) |
| 132 | + }) |
| 133 | + |
| 134 | + it('should allow to disable stack tooltip', () => { |
| 135 | + const wrapper = mount(<Stream<TestDatum> {...commonProps} enableStackTooltip={false} />) |
| 136 | + |
| 137 | + expect(wrapper.find('StreamSlices').exists()).toBe(false) |
| 138 | + }) |
| 139 | + |
| 140 | + it('should disable tooltip and stack tooltip when `isInteractive` is false', () => { |
| 141 | + const wrapper = mount(<Stream<TestDatum> {...commonProps} isInteractive={false} />) |
| 142 | + |
| 143 | + wrapper.find('StreamLayer').at(0).find('path').simulate('mouseEnter') |
| 144 | + expect(wrapper.find('LayerTooltip').exists()).toBe(false) |
| 145 | + |
| 146 | + expect(wrapper.find('StreamSlices').exists()).toBe(false) |
| 147 | + }) |
| 148 | +}) |
| 149 | + |
95 | 150 | describe('accessibility', () => {
|
96 | 151 | it('should forward root aria properties to the SVG element', () => {
|
97 | 152 | const wrapper = mount(
|
|
0 commit comments