Skip to content

Commit 5a8c85d

Browse files
authored
修复 chord 单测和增加 pie 单测 (#2127)
* test: 修复 chord 测试挂了 * test: 增加单测,保证"开启中心文本交互时,显式注册 tooltip 交互可以开启 tooltip"
1 parent b513761 commit 5a8c85d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

__tests__/bugs/issue-2096-spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Pie } from '../../src';
2+
import { createDiv } from '../utils/dom';
3+
4+
describe('#2096', () => {
5+
const pie = new Pie(createDiv(), {
6+
data: [
7+
{ type: '1', value: 10 },
8+
{ type: '13', value: 10 },
9+
{ type: '55', value: 10 },
10+
],
11+
angleField: 'value',
12+
colorField: 'type',
13+
radius: 0.8,
14+
});
15+
16+
it('normal', () => {
17+
pie.render();
18+
expect(pie.chart.interactions.tooltip).toBeDefined();
19+
});
20+
21+
it('开启中心文本交互时,默认关闭 tooltip', () => {
22+
pie.update({
23+
innerRadius: 0.64,
24+
statistic: {},
25+
interactions: [{ type: 'pie-statistic-active' }],
26+
});
27+
28+
expect(pie.chart.interactions.tooltip).not.toBeDefined();
29+
});
30+
31+
it('开启中心文本交互时,需要显式注册 tooltip 交互来开启 tooltip', () => {
32+
pie.update({
33+
interactions: [{ type: 'pie-statistic-active' }, { type: 'tooltip' }],
34+
});
35+
expect(pie.chart.interactions.tooltip).toBeDefined();
36+
});
37+
});

__tests__/unit/plots/chord/index-spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ describe('chord', () => {
6464
);
6565

6666
// tooltip
67-
chord.chart.showTooltip({ x: 500, y: 100 });
67+
const edgeView = chord.chart.views[0];
68+
const edgeElementIdx = edgeView.getData().findIndex((d) => d.source === '北京' && d.target === '天津');
69+
const element = edgeView.geometries[0].elements[edgeElementIdx];
70+
const path = element.shape.attr('path');
71+
chord.chart.showTooltip({ x: path[0][1], y: path[0][2] });
6872
expect(document.querySelector('.g2-tooltip-name').textContent).toBe('北京 -> 天津');
6973
expect(document.querySelector('.g2-tooltip-value').textContent).toBe('30');
7074

0 commit comments

Comments
 (0)