Skip to content

Commit 8e35d04

Browse files
committed
test(pie): 补充单测
1 parent 288b174 commit 8e35d04

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

__tests__/unit/plots/pie/index-spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ describe('pie', () => {
2020
});
2121

2222
pie.render();
23+
expect(pie.type).toBe('pie');
24+
// @ts-ignore
25+
expect(pie.getDefaultOptions()).toBe(Pie.getDefaultOptions());
2326

2427
const geometry = pie.chart.geometries[0];
2528
const elements = geometry.elements;

__tests__/unit/plots/pie/statistic-spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Chart } from '@antv/g2';
22
import { Pie, PieOptions } from '../../../../src';
3+
import { DEFAULT_OPTIONS } from '../../../../src/plots/pie/contants';
34
import { POSITIVE_NEGATIVE_DATA } from '../../../data/common';
45
import { delay } from '../../../utils/delay';
56
import { createDiv } from '../../../utils/dom';
@@ -301,6 +302,22 @@ describe('中心文本 - 指标卡', () => {
301302
expect(htmlAnnotations[0].getBoundingClientRect().width).toEqual(600);
302303
});
303304

305+
it('statistic 默认继承 defaultOptions', () => {
306+
pie.update({ statistic: null });
307+
expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(0);
308+
309+
pie.update({ statistic: {} });
310+
expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(2);
311+
expect(pie.options.statistic).toEqual({});
312+
setTimeout(() => {
313+
// @ts-ignore
314+
const annotations = pie.chart.ele.querySelectorAll('.g2-html-annotation') as HTMLDivElement[];
315+
expect(annotations[0].style.fontSize).toEqual(DEFAULT_OPTIONS.statistic.title.fontSize);
316+
expect(annotations[1].style.color).toEqual(DEFAULT_OPTIONS.statistic.content.color);
317+
expect(annotations[1].style).toMatchObject(DEFAULT_OPTIONS.statistic.content);
318+
}, 0);
319+
});
320+
304321
afterEach(() => {
305322
pie.chart.clear();
306323
});

0 commit comments

Comments
 (0)