Skip to content

Commit

Permalink
test: add test case for Point geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Oct 28, 2019
1 parent e41a86b commit e290619
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/geometry/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Point extends Geometry {

return {
...shapeCfg,
isStack: !!this.getAdjust('adjust'),
isStack: !!this.getAdjust('adjust'), // 层叠点图
};
}
}
48 changes: 48 additions & 0 deletions tests/unit/geometry/point-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getCoordinate } from '@antv/coord';
import Point from '../../../src/geometry/point';
import Theme from '../../../src/theme/antv';
import { createCanvas, createDiv, removeDom } from '../../util/dom';

import 'jest-extended';

const CartesianCoordinate = getCoordinate('rect');

describe('Point', () => {
const div = createDiv();
const canvas = createCanvas({
container: div,
width: 300,
height: 300,
});
const rectCoord = new CartesianCoordinate({
start: { x: 0, y: 300 },
end: { x: 300, y: 0 },
});

it('draw point', () => {
const point = new Point({
data: [{ x: 1996, y: 30 }, { x: 1990, y: 210 }, { x: 1993, y: 29 }],
container: canvas.addGroup(),
theme: Theme,
coordinate: rectCoord,
});

point.position('x*y');
point.initial();
point.paint();
canvas.draw();

expect(point.shapeType).toBe('point');
// @ts-ignore
expect(point.generatePoints).toBe(true);

const element = point.elements[0];
expect(element.data).toEqual({ x: 1996, y: 30 });
expect(element.model.isStack).toBe(false);
});

afterAll(() => {
canvas.destroy();
removeDom(div);
});
});

0 comments on commit e290619

Please sign in to comment.