Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 chord 单测和增加 pie 单测 #2127

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions __tests__/bugs/issue-2096-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
6 changes: 5 additions & 1 deletion __tests__/unit/plots/chord/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down