@@ -122,6 +122,29 @@ describe('PoChartNewComponent', () => {
122
122
expect ( component ) . toBeTruthy ( ) ;
123
123
} ) ;
124
124
125
+ it ( 'should show tooltip only when content overflows' , ( ) => {
126
+ const event : any = {
127
+ target : document . createElement ( 'div' )
128
+ } ;
129
+
130
+ const element = event . target as HTMLElement ;
131
+
132
+ // Simula overflow
133
+ Object . defineProperty ( element , 'scrollWidth' , { value : 150 , configurable : true } ) ;
134
+ Object . defineProperty ( element , 'offsetWidth' , { value : 100 , configurable : true } ) ;
135
+
136
+ component . title = 'Long Title' ;
137
+ component . showTooltipTitle ( event ) ;
138
+ expect ( component [ 'tooltipTitle' ] ) . toBe ( 'Long Title' ) ;
139
+
140
+ // Simula conteúdo sem overflow
141
+ Object . defineProperty ( element , 'scrollWidth' , { value : 80 } ) ;
142
+ Object . defineProperty ( element , 'offsetWidth' , { value : 100 } ) ;
143
+
144
+ component . showTooltipTitle ( event ) ;
145
+ expect ( component [ 'tooltipTitle' ] ) . toBeUndefined ( ) ;
146
+ } ) ;
147
+
125
148
describe ( 'Lifecycle hooks:' , ( ) => {
126
149
it ( 'ngAfterViewInit: should initialize echarts' , ( ) => {
127
150
spyOn ( component , < any > 'initECharts' ) ;
@@ -399,6 +422,35 @@ describe('PoChartNewComponent', () => {
399
422
expect ( component . seriesHover . emit ) . not . toHaveBeenCalled ( ) ;
400
423
} ) ;
401
424
425
+ it ( 'should emit seriesClick event when clicking on the chart if params.seriesName is undefined' , ( ) => {
426
+ component [ 'chartInstance' ] = {
427
+ on : jasmine . createSpy ( 'on' )
428
+ } as any ;
429
+
430
+ spyOn ( component . seriesClick , 'emit' ) ;
431
+ spyOn ( component . seriesHover , 'emit' ) ;
432
+
433
+ component [ 'initEChartsEvents' ] ( ) ;
434
+
435
+ expect ( component [ 'chartInstance' ] . on ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
436
+
437
+ const clickCallback = component [ 'chartInstance' ] . on . calls . argsFor ( 0 ) [ 1 ] ;
438
+
439
+ const mockParams = { value : 100 , name : 'Name X' } ;
440
+ clickCallback ( mockParams ) ;
441
+
442
+ const mouseoverCallback = component [ 'chartInstance' ] . on . calls . argsFor ( 1 ) [ 1 ] ;
443
+
444
+ const mockParamsMouse = { } ;
445
+ mouseoverCallback ( mockParamsMouse ) ;
446
+
447
+ expect ( component . seriesClick . emit ) . toHaveBeenCalledWith ( {
448
+ label : 'Name X' ,
449
+ data : 100
450
+ } ) ;
451
+ expect ( component . seriesHover . emit ) . not . toHaveBeenCalled ( ) ;
452
+ } ) ;
453
+
402
454
it ( 'should emit seriesHover event when hovering over a series' , ( ) => {
403
455
const tooltipElement = document . createElement ( 'div' ) ;
404
456
tooltipElement . id = 'custom-tooltip' ;
@@ -465,7 +517,7 @@ describe('PoChartNewComponent', () => {
465
517
on : jasmine . createSpy ( 'on' )
466
518
} as any ;
467
519
468
- spyOn ( component . poTooltip , 'toggleTooltipVisibility' ) ;
520
+ spyOn ( component . poTooltip . last , 'toggleTooltipVisibility' ) ;
469
521
470
522
component [ 'initEChartsEvents' ] ( ) ;
471
523
@@ -475,7 +527,7 @@ describe('PoChartNewComponent', () => {
475
527
476
528
mouseoutCallback ( ) ;
477
529
478
- expect ( component . poTooltip . toggleTooltipVisibility ) . toHaveBeenCalledWith ( false ) ;
530
+ expect ( component . poTooltip . last . toggleTooltipVisibility ) . toHaveBeenCalledWith ( false ) ;
479
531
} ) ;
480
532
481
533
it ( 'should set tooltipText as "seriesName: value" when tooltip is not defined' , ( ) => {
@@ -524,7 +576,7 @@ describe('PoChartNewComponent', () => {
524
576
525
577
mouseoverCallback ( mockParamsNoSeriesName ) ;
526
578
527
- expect ( component . tooltipText . replace ( / \s / g, '' ) ) . toBe ( 'CategoriaSemNome<b>99</b>' . replace ( / \s / g, '' ) ) ;
579
+ expect ( component . tooltipText . replace ( / \s / g, '' ) ) . toBe ( 'CategoriaSemNome: <b>99</b>' . replace ( / \s / g, '' ) ) ;
528
580
} ) ;
529
581
} ) ;
530
582
@@ -735,9 +787,11 @@ describe('PoChartNewComponent', () => {
735
787
736
788
const result = component [ 'setSeries' ] ( ) ;
737
789
738
- expect ( result . length ) . toBe ( 2 ) ;
790
+ expect ( result . length ) . toBe ( 1 ) ;
739
791
expect ( result [ 0 ] . type ) . toBe ( 'pie' ) ;
740
- expect ( result [ 0 ] . name ) . toBe ( 'Serie 1' ) ;
792
+ expect ( result [ 0 ] . data [ 0 ] . name ) . toBe ( 'Serie 1' ) ;
793
+ expect ( result [ 0 ] . data [ 1 ] . name ) . toBe ( 'Serie 2' ) ;
794
+ expect ( result [ 0 ] . data . length ) . toBe ( 2 ) ;
741
795
} ) ;
742
796
743
797
it ( 'should transform series correctly with default configurations' , ( ) => {
@@ -1013,6 +1067,33 @@ describe('PoChartNewComponent', () => {
1013
1067
1014
1068
expect ( component [ 'setTableColumns' ] ) . not . toHaveBeenCalled ( ) ;
1015
1069
} ) ;
1070
+
1071
+ it ( 'should set Series if type is Pie' , ( ) => {
1072
+ component . type = PoChartType . Pie ;
1073
+ component . series = [
1074
+ { data : 80 , label : 'Pie Value 1' } ,
1075
+ { data : 20 , label : 'Pie Value 2' }
1076
+ ] ;
1077
+ component [ 'chartInstance' ] = {
1078
+ getOption : jasmine . createSpy ( 'getOption' ) . and . returnValue ( {
1079
+ series : [
1080
+ {
1081
+ name : 'Série A' ,
1082
+ data : [
1083
+ { name : 'Pie Value 1' , value : 80 } ,
1084
+ { name : 'Pie Value 2' , value : 20 }
1085
+ ]
1086
+ }
1087
+ ]
1088
+ } )
1089
+ } as any ;
1090
+ spyOn ( component as any , 'setTableColumns' ) ;
1091
+
1092
+ component [ 'setTableProperties' ] ( ) ;
1093
+
1094
+ expect ( component [ 'setTableColumns' ] ) . not . toHaveBeenCalled ( ) ;
1095
+ expect ( component [ 'itemsTable' ] ) . toEqual ( [ { 'Série' : '-' , 'Pie Value 1' : 80 , 'Pie Value 2' : 20 } ] ) ;
1096
+ } ) ;
1016
1097
} ) ;
1017
1098
1018
1099
describe ( 'setTableColumns:' , ( ) => {
@@ -1055,6 +1136,7 @@ describe('PoChartNewComponent', () => {
1055
1136
{ serie : 'Série 1' , valor1 : 10 , valor2 : undefined } ,
1056
1137
{ serie : 'Série 2' , valor1 : 30 }
1057
1138
] ;
1139
+ component [ 'columnsTable' ] = [ { property : 'serie' } , { property : 'valor1' } , { property : 'valor2' } ] ;
1058
1140
component . options = { } as any ;
1059
1141
1060
1142
component [ 'downloadCsv' ] ( ) ;
@@ -1192,47 +1274,6 @@ describe('PoChartNewComponent', () => {
1192
1274
expect ( component [ 'setHeaderProperties' ] ) . not . toHaveBeenCalled ( ) ;
1193
1275
} ) ;
1194
1276
1195
- // it('should create and download a PNG image correctly', done => {
1196
- // const chartElement = document.createElement('div');
1197
- // chartElement.style.width = '800px';
1198
- // chartElement.style.height = '600px';
1199
-
1200
- // const headerElement = document.createElement('div');
1201
- // headerElement.style.height = '50px';
1202
-
1203
- // const mockImage = new Image();
1204
- // const canvas = document.createElement('canvas');
1205
- // const ctx = canvas.getContext('2d');
1206
- // spyOn(canvas, 'getContext').and.returnValue(ctx);
1207
-
1208
- // const link = document.createElement('a');
1209
- // spyOn(document, 'createElement').and.callFake((tag: string) => {
1210
- // if (tag === 'canvas') return canvas;
1211
- // if (tag === 'a') return link;
1212
- // return document.createElement(tag);
1213
- // });
1214
-
1215
- // spyOn(canvas, 'toDataURL').and.returnValue('data:image/png;base64,fakeImageData');
1216
- // spyOn(link, 'click');
1217
-
1218
- // component['configureImageCanvas']('png', mockImage);
1219
-
1220
- // setTimeout(() => {
1221
- // mockImage.onload?.(new Event('load'));
1222
- // }, 100);
1223
-
1224
- // setTimeout(() => {
1225
- // try {
1226
- // expect(link.href).toBe('data:image/png;base64,fakeImageData');
1227
- // expect(link.download).toBe('grafico-exportado.png');
1228
- // expect(link.click).toHaveBeenCalled();
1229
- // done();
1230
- // } catch (error) {
1231
- // done.fail(error);
1232
- // }
1233
- // }, 300);
1234
- // });
1235
-
1236
1277
it ( 'should create and download a PNG image correctly' , done => {
1237
1278
const chartElement = document . createElement ( 'div' ) ;
1238
1279
chartElement . style . width = '800px' ;
0 commit comments