From e29061966c78926d7bd95cea8798d2f1aacec44f Mon Sep 17 00:00:00 2001 From: simaQ Date: Mon, 28 Oct 2019 15:55:26 +0800 Subject: [PATCH] test: add test case for Point geometry --- src/geometry/point.ts | 2 +- tests/unit/geometry/point-spec.ts | 48 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/unit/geometry/point-spec.ts diff --git a/src/geometry/point.ts b/src/geometry/point.ts index 4aad594892..fbbf7617de 100644 --- a/src/geometry/point.ts +++ b/src/geometry/point.ts @@ -14,7 +14,7 @@ export default class Point extends Geometry { return { ...shapeCfg, - isStack: !!this.getAdjust('adjust'), + isStack: !!this.getAdjust('adjust'), // 层叠点图 }; } } diff --git a/tests/unit/geometry/point-spec.ts b/tests/unit/geometry/point-spec.ts new file mode 100644 index 0000000000..802eb09065 --- /dev/null +++ b/tests/unit/geometry/point-spec.ts @@ -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); + }); +});