diff --git a/__tests__/bugs/issue-2096-spec.ts b/__tests__/bugs/issue-2096-spec.ts new file mode 100644 index 0000000000..082ca2e7a9 --- /dev/null +++ b/__tests__/bugs/issue-2096-spec.ts @@ -0,0 +1,37 @@ +import { Pie } from '../../src'; +import { createDiv } from '../utils/dom'; + +describe('#2096', () => { + const pie = new Pie(createDiv(), { + data: [ + { type: '1', value: 10 }, + { type: '13', value: 10 }, + { type: '55', value: 10 }, + ], + angleField: 'value', + colorField: 'type', + radius: 0.8, + }); + + it('normal', () => { + pie.render(); + expect(pie.chart.interactions.tooltip).toBeDefined(); + }); + + it('开启中心文本交互时,默认关闭 tooltip', () => { + pie.update({ + innerRadius: 0.64, + statistic: {}, + interactions: [{ type: 'pie-statistic-active' }], + }); + + expect(pie.chart.interactions.tooltip).not.toBeDefined(); + }); + + it('开启中心文本交互时,需要显式注册 tooltip 交互来开启 tooltip', () => { + pie.update({ + interactions: [{ type: 'pie-statistic-active' }, { type: 'tooltip' }], + }); + expect(pie.chart.interactions.tooltip).toBeDefined(); + }); +}); diff --git a/__tests__/unit/plots/chord/index-spec.ts b/__tests__/unit/plots/chord/index-spec.ts index 49ddfabecc..ac05567f80 100644 --- a/__tests__/unit/plots/chord/index-spec.ts +++ b/__tests__/unit/plots/chord/index-spec.ts @@ -64,7 +64,11 @@ describe('chord', () => { ); // tooltip - chord.chart.showTooltip({ x: 500, y: 100 }); + const edgeView = chord.chart.views[0]; + const edgeElementIdx = edgeView.getData().findIndex((d) => d.source === '北京' && d.target === '天津'); + const element = edgeView.geometries[0].elements[edgeElementIdx]; + const path = element.shape.attr('path'); + chord.chart.showTooltip({ x: path[0][1], y: path[0][2] }); expect(document.querySelector('.g2-tooltip-name').textContent).toBe('北京 -> 天津'); expect(document.querySelector('.g2-tooltip-value').textContent).toBe('30');