Skip to content

Commit

Permalink
test(pie): 补充单测
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Jan 24, 2021
1 parent 6cc5d90 commit c5900c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions __tests__/unit/plots/pie/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe('pie', () => {
});

pie.render();
expect(pie.type).toBe('pie');
// @ts-ignore
expect(pie.getDefaultOptions()).toBe(Pie.getDefaultOptions());

const geometry = pie.chart.geometries[0];
const elements = geometry.elements;
Expand Down
17 changes: 17 additions & 0 deletions __tests__/unit/plots/pie/statistic-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Chart } from '@antv/g2';
import { Pie, PieOptions } from '../../../../src';
import { DEFAULT_OPTIONS } from '../../../../src/plots/pie/contants';
import { POSITIVE_NEGATIVE_DATA } from '../../../data/common';
import { delay } from '../../../utils/delay';
import { createDiv } from '../../../utils/dom';
Expand Down Expand Up @@ -301,6 +302,22 @@ describe('中心文本 - 指标卡', () => {
expect(htmlAnnotations[0].getBoundingClientRect().width).toEqual(600);
});

it('statistic 默认继承 defaultOptions', () => {
pie.update({ statistic: null });
expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(0);

pie.update({ statistic: {} });
expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(2);
expect(pie.options.statistic).toEqual({});
setTimeout(() => {
// @ts-ignore
const annotations = pie.chart.ele.querySelectorAll('.g2-html-annotation') as HTMLDivElement[];
expect(annotations[0].style.fontSize).toEqual(DEFAULT_OPTIONS.statistic.title.fontSize);
expect(annotations[1].style.color).toEqual(DEFAULT_OPTIONS.statistic.content.color);
expect(annotations[1].style).toMatchObject(DEFAULT_OPTIONS.statistic.content);
}, 0);
});

afterEach(() => {
pie.chart.clear();
});
Expand Down

0 comments on commit c5900c1

Please sign in to comment.