@@ -376,6 +376,54 @@ describe('PoChartNewComponent', () => {
376
376
} ) ;
377
377
} ) ;
378
378
379
+ describe ( 'checkShowCEcharts' , ( ) => {
380
+ it ( 'should call initECharts and disconnect observer when element is visible and hideDomEchartsDiv is true' , ( ) => {
381
+ const chartElement = document . createElement ( 'div' ) ;
382
+ chartElement . id = 'chart-id' ;
383
+
384
+ ( component [ 'el' ] . nativeElement . querySelector as jasmine . Spy ) . and . returnValue ( chartElement ) ;
385
+ component [ 'hideDomEchartsDiv' ] = true ;
386
+
387
+ spyOn ( component as any , 'initECharts' ) ;
388
+
389
+ const observeSpy = jasmine . createSpy ( 'observe' ) ;
390
+ const disconnectSpy = jasmine . createSpy ( 'disconnect' ) ;
391
+
392
+ let callback : ( entries : Array < IntersectionObserverEntry > ) => void ;
393
+
394
+ ( window as any ) . IntersectionObserver = function ( cb : any ) {
395
+ callback = cb ;
396
+ return {
397
+ observe : observeSpy ,
398
+ disconnect : disconnectSpy
399
+ } ;
400
+ } ;
401
+
402
+ ( component as any ) . checkShowCEcharts ( ) ;
403
+
404
+ callback ( [ { isIntersecting : true } ] as any ) ;
405
+
406
+ expect ( ( component as any ) . initECharts ) . toHaveBeenCalled ( ) ;
407
+ expect ( observeSpy ) . toHaveBeenCalledWith ( chartElement ) ;
408
+ expect ( disconnectSpy ) . toHaveBeenCalled ( ) ;
409
+ } ) ;
410
+ } ) ;
411
+
412
+ it ( 'should set showPopup to false when hideExportCsv, hideExportImage are true and there are no customActions' , ( ) => {
413
+ component [ 'options' ] = {
414
+ header : {
415
+ hideExportCsv : true ,
416
+ hideExportImage : true
417
+ }
418
+ } ;
419
+
420
+ component [ 'customActions' ] = [ ] ;
421
+
422
+ ( component as any ) . setInitialPopupActions ( ) ;
423
+
424
+ expect ( component [ 'showPopup' ] ) . toBeFalse ( ) ;
425
+ } ) ;
426
+
379
427
describe ( 'initECHarts:' , ( ) => {
380
428
it ( 'should not initialize the chart if #chart-id is not found' , ( ) => {
381
429
const originalQuerySelector = component [ 'el' ] . nativeElement . querySelector ;
@@ -394,24 +442,24 @@ describe('PoChartNewComponent', () => {
394
442
395
443
it ( 'should emit seriesClick event when clicking on the chart' , ( ) => {
396
444
const onSpy = jasmine . createSpy ( 'on' ) ;
445
+
397
446
component [ 'chartInstance' ] = {
398
447
on : onSpy
399
- } as Partial < EChartsType > as EChartsType ;
448
+ } as any ;
400
449
401
450
spyOn ( component . seriesClick , 'emit' ) ;
402
451
spyOn ( component . seriesHover , 'emit' ) ;
403
452
404
453
component [ 'initEChartsEvents' ] ( ) ;
405
454
406
- expect ( component [ 'chartInstance' ] . on ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
455
+ expect ( onSpy ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
407
456
408
457
const clickCallback = onSpy . calls . argsFor ( 0 ) [ 1 ] ;
409
458
410
459
const mockParams = { seriesName : 'Exemplo' , value : 100 , name : 'Categoria X' } ;
411
460
clickCallback ( mockParams ) ;
412
461
413
462
const mouseoverCallback = onSpy . calls . argsFor ( 1 ) [ 1 ] ;
414
-
415
463
const mockParamsMouse = { } ;
416
464
mouseoverCallback ( mockParamsMouse ) ;
417
465
@@ -420,6 +468,7 @@ describe('PoChartNewComponent', () => {
420
468
data : 100 ,
421
469
category : 'Categoria X'
422
470
} ) ;
471
+
423
472
expect ( component . seriesHover . emit ) . not . toHaveBeenCalled ( ) ;
424
473
} ) ;
425
474
@@ -701,29 +750,31 @@ describe('PoChartNewComponent', () => {
701
750
expect ( result . yAxis . splitLine . show ) . toBeTrue ( ) ;
702
751
} ) ;
703
752
704
- it ( 'should apply correct axis configurations if type is Bar' , ( ) => {
705
- const categories = [ 'Mon' , 'Tue' , 'Wed' ] ;
753
+ it ( 'should configure axes correctly when isTypeBar is true' , ( ) => {
706
754
component . isTypeBar = true ;
707
- component . options . axis = {
708
- minRange : 10 ,
709
- maxRange : 100 ,
710
- gridLines : 7 ,
711
- showXAxis : false ,
712
- showYAxis : true ,
713
- paddingLeft : 60
755
+
756
+ component . options = {
757
+ axis : {
758
+ showXAxis : undefined ,
759
+ showYAxis : false
760
+ }
714
761
} ;
715
- component . categories = categories ;
716
762
717
- const result = component [ 'setOptions' ] ( ) as any ;
718
- expect ( result . yAxis . min ) . toBe ( 10 ) ;
719
- expect ( result . yAxis . max ) . toBe ( 100 ) ;
720
- expect ( result . yAxis . splitNumber ) . toBe ( 7 ) ;
721
- expect ( result . yAxis . type ) . toBe ( 'category' ) ;
722
- expect ( result . yAxis . data ) . toEqual ( categories ) ;
723
- expect ( result . grid . left ) . toBe ( 60 ) ;
724
- expect ( result . xAxis . type ) . toBe ( 'value' ) ;
725
- expect ( result . xAxis . splitLine . show ) . toBeFalse ( ) ;
726
- expect ( result . yAxis . splitLine . show ) . toBeTrue ( ) ;
763
+ component . categories = [ 'Jan' , 'Feb' , 'Mar' ] ;
764
+
765
+ const options : any = { } ;
766
+
767
+ component [ 'chartGridUtils' ] . setOptionsAxis ( options ) ;
768
+
769
+ expect ( options . xAxis . type ) . toBe ( 'value' ) ;
770
+
771
+ expect ( options . xAxis . splitLine . show ) . toBeTrue ( ) ;
772
+
773
+ expect ( options . yAxis . type ) . toBe ( 'category' ) ;
774
+
775
+ expect ( options . yAxis . splitLine . show ) . toBeFalse ( ) ;
776
+
777
+ expect ( options . yAxis . data ) . toEqual ( [ 'Jan' , 'Feb' , 'Mar' ] ) ;
727
778
} ) ;
728
779
729
780
it ( 'should apply number formatting when labelType is Number' , ( ) => {
@@ -784,12 +835,13 @@ describe('PoChartNewComponent', () => {
784
835
} ) ;
785
836
786
837
describe ( 'setShowAxisDetails: ' , ( ) => {
787
- it ( 'deve adicionar tooltip com axisPointer quando showAxisDetails for true' , ( ) => {
838
+ it ( 'should add tooltip with axisPointer when showAxisDetails is true' , ( ) => {
788
839
component [ 'options' ] = {
789
840
axis : {
790
841
showAxisDetails : true
791
842
}
792
843
} ;
844
+ spyOn ( component , 'getCSSVariable' ) . and . returnValue ( '#4a5c60' ) ;
793
845
794
846
const options : any = { } ;
795
847
@@ -800,13 +852,34 @@ describe('PoChartNewComponent', () => {
800
852
axisPointer : {
801
853
type : 'cross' ,
802
854
label : {
803
- backgroundColor : '#6a7985 '
855
+ backgroundColor : '#4a5c60 '
804
856
}
805
857
}
806
858
} ) ;
807
859
} ) ;
808
860
} ) ;
809
861
862
+ it ( 'should set splitNumber on xAxis when isTypeBar is true' , ( ) => {
863
+ component . isTypeBar = true ;
864
+ component . options = {
865
+ axis : {
866
+ gridLines : 7 ,
867
+ minRange : 0 ,
868
+ maxRange : 100
869
+ }
870
+ } ;
871
+
872
+ const options : any = {
873
+ xAxis : {
874
+ axisLabel : { }
875
+ }
876
+ } ;
877
+
878
+ ( component as any ) . formatLabelOption ( options ) ;
879
+
880
+ expect ( options . xAxis . splitNumber ) . toBe ( 7 ) ;
881
+ } ) ;
882
+
810
883
describe ( 'setSeries:' , ( ) => {
811
884
let mockSeriesWithColor : Array < PoChartSerie > ;
812
885
@@ -1371,7 +1444,7 @@ describe('PoChartNewComponent', () => {
1371
1444
spyOn ( document , 'createElement' ) . and . callFake ( ( tag : string ) => {
1372
1445
if ( tag === 'canvas' ) return canvas ;
1373
1446
if ( tag === 'a' ) return link ;
1374
- return originalCreateElement . call ( document , tag ) ; // aqui corrigido
1447
+ return originalCreateElement . call ( document , tag ) ;
1375
1448
} ) ;
1376
1449
1377
1450
spyOn ( canvas , 'toDataURL' ) . and . returnValue ( 'data:image/png;base64,fakeImageData' ) ;
0 commit comments