Skip to content

Commit

Permalink
test(tooltip): 添加 tooltip 测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Mar 17, 2020
1 parent 6f5693d commit afb877f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/bugs/2174-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';

describe('#2174, #2175', () => {
it('tooltip', () => {
const data = [
{ name: 'London', 月份: 'Jan.', 月均降雨量: 18.9 },
];

const chart = new Chart({
container: createDiv(),
width: 400,
height: 300,
});

chart.data(data);
chart.scale('月均降雨量', {
nice: true,
});
chart.tooltip({
shared: true
});

chart
.interval()
.position('月份*月均降雨量');

chart.render();

const point = chart.getXY({ name: 'London', 月份: 'Jan.', 月均降雨量: 18.9 });
// 相同的内容,先展示,再关闭,再展示,tooltip 应该展示
chart.showTooltip(point);
chart.hideTooltip();

chart.showTooltip(point);

const tooltip = chart.ele.getElementsByClassName('g2-tooltip')[0];
// @ts-ignore
expect(tooltip.style.visibility).toBe('visible');

// 如果内容为空,tooltip 应该隐藏
chart.showTooltip({
x: point.x - 100,
y: point.y
});
// @ts-ignore
expect(tooltip.style.visibility).toBe('hidden');
});
});

0 comments on commit afb877f

Please sign in to comment.