Skip to content

Commit

Permalink
test(funnel): 增加漏斗图单测
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Jun 13, 2021
1 parent f9867fb commit 9266947
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions __tests__/unit/plots/funnel/style-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Funnel } from '../../../../src';
import { PV_DATA_COMPARE } from '../../../data/conversion';
import { createDiv } from '../../../utils/dom';

describe('funnel', () => {
const plot = new Funnel(createDiv(), {
data: PV_DATA_COMPARE,
autoFit: true,
xField: 'action',
yField: 'pv',
minSize: 0.3,
maxSize: 0.8,
funnelStyle: {
fill: 'red',
},
});

plot.render();

it('default', () => {
expect(plot.type).toBe('funnel');

const geometry = plot.chart.geometries[0];
const elements = geometry.elements;
expect(elements[0].shape.attr('fill')).toEqual('red');

plot.update({ funnelStyle: () => ({ fill: 'red', stroke: 'blue' }) });
expect(plot.chart.geometries[0].elements[0].shape.attr('stroke')).toEqual('blue');
});

it('对比漏斗图', () => {
plot.update({ compareField: 'quarter' });
expect(plot.chart.views.length).toEqual(2);

const geometry = plot.chart.views[0].geometries[0];
const elements = geometry.elements;
expect(elements[0].shape.attr('fill')).toEqual('red');
expect(elements[0].shape.attr('stroke')).toEqual('blue');
expect(elements[0].shape.attr('lineWidth')).toEqual(1);

plot.update({ funnelStyle: undefined });
// 还原默认
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('#fff');

plot.update({ funnelStyle: { stroke: 'yellow' } });
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('yellow');

// function
plot.update({ funnelStyle: () => ({ stroke: 'blue' }) });
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('blue');
});
});

0 comments on commit 9266947

Please sign in to comment.