@@ -14,13 +14,13 @@ describe('liquid statistic', () => {
14
14
15
15
it ( '默认展示' , async ( ) => {
16
16
await delay ( 50 ) ;
17
- const annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
17
+ const annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
18
18
expect ( annotations . length ) . toBe ( 1 ) ;
19
19
} ) ;
20
20
21
21
it ( '默认展示当前数值' , ( ) => {
22
22
liquid . update ( { statistic : { content : { } } } ) ;
23
- const annotation = document . body . querySelector ( '.g2-html-annotation' ) ;
23
+ const annotation = liquid . chart . ele . querySelector ( '.g2-html-annotation' ) ;
24
24
expect ( ( annotation as HTMLElement ) . innerText ) . toBe ( '65.00%' ) ;
25
25
} ) ;
26
26
@@ -29,24 +29,24 @@ describe('liquid statistic', () => {
29
29
meta : { percent : { formatter : ( v ) => `${ v * 100 } .000%` } } ,
30
30
statistic : { content : { formatter : null } } ,
31
31
} ) ;
32
- const annotation = document . body . querySelector ( '.g2-html-annotation' ) ;
32
+ const annotation = liquid . chart . ele . querySelector ( '.g2-html-annotation' ) ;
33
33
expect ( ( annotation as HTMLElement ) . innerText ) . toBe ( '65.000%' ) ;
34
34
} ) ;
35
35
36
36
it ( 'statistic 配置的格式化方式, 优先级高于 meta' , ( ) => {
37
37
liquid . update ( { statistic : { content : { formatter : ( { percent } ) => `${ percent * 100 } .0%` } } } ) ;
38
- const annotation = document . body . querySelector ( '.g2-html-annotation' ) ;
38
+ const annotation = liquid . chart . ele . querySelector ( '.g2-html-annotation' ) ;
39
39
expect ( ( annotation as HTMLElement ) . innerText ) . toBe ( '65.0%' ) ;
40
40
} ) ;
41
41
42
42
it ( 'statistic 配置title' , ( ) => {
43
43
liquid . update ( { statistic : { content : { } , title : { } } } ) ;
44
- let annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
44
+ let annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
45
45
expect ( annotations . length ) . toBe ( 2 ) ;
46
46
expect ( ( annotations [ 0 ] as HTMLElement ) . innerText ) . toBe ( '' ) ;
47
47
48
48
liquid . update ( { statistic : { content : { } , title : { formatter : ( ) => '测试' } } } ) ;
49
- annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
49
+ annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
50
50
expect ( ( annotations [ 0 ] as HTMLElement ) . innerText ) . toBe ( '测试' ) ;
51
51
} ) ;
52
52
@@ -72,29 +72,29 @@ describe('liquid statistic', () => {
72
72
73
73
it ( '关闭 statistic' , ( ) => {
74
74
liquid . update ( { statistic : { content : null } } ) ;
75
- let annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
75
+ let annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
76
76
expect ( annotations . length ) . toBe ( 1 ) ;
77
77
liquid . update ( { statistic : { content : null , title : null } } ) ;
78
- annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
78
+ annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
79
79
expect ( annotations . length ) . toBe ( 0 ) ;
80
80
} ) ;
81
81
82
82
it ( 'change data' , ( ) => {
83
83
liquid . update ( { statistic : { title : { } , content : { formatter : ( { percent : v } ) => `${ v * 100 } .0%` } } } ) ;
84
84
liquid . changeData ( 0.35 ) ;
85
- const annotations = document . body . querySelectorAll ( '.g2-html-annotation' ) ;
85
+ const annotations = liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) ;
86
86
expect ( annotations . length ) . toBe ( 2 ) ;
87
87
expect ( ( annotations [ 1 ] as HTMLElement ) . innerText ) . toBe ( '35.0%' ) ;
88
88
89
89
liquid . changeData ( 0.15 ) ;
90
- expect ( ( document . body . querySelectorAll ( '.g2-html-annotation' ) [ 1 ] as HTMLElement ) . innerText ) . toBe ( '15.0%' ) ;
90
+ expect ( ( liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) [ 1 ] as HTMLElement ) . innerText ) . toBe ( '15.0%' ) ;
91
91
92
92
liquid . update ( { statistic : { content : { } , title : false } } ) ;
93
- expect ( document . body . querySelectorAll ( '.g2-html-annotation' ) . length ) . toBe ( 1 ) ;
94
- expect ( ( document . body . querySelectorAll ( '.g2-html-annotation' ) [ 0 ] as HTMLElement ) . innerText ) . toBe ( '15.0%' ) ;
93
+ expect ( liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) . length ) . toBe ( 1 ) ;
94
+ expect ( ( liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) [ 0 ] as HTMLElement ) . innerText ) . toBe ( '15.0%' ) ;
95
95
96
96
liquid . changeData ( 0.05 ) ;
97
- expect ( ( document . body . querySelectorAll ( '.g2-html-annotation' ) [ 0 ] as HTMLElement ) . innerText ) . toBe ( '5.0%' ) ;
97
+ expect ( ( liquid . chart . ele . querySelectorAll ( '.g2-html-annotation' ) [ 0 ] as HTMLElement ) . innerText ) . toBe ( '5.0%' ) ;
98
98
} ) ;
99
99
100
100
afterAll ( ( ) => {
0 commit comments