11import * as utilsFunctions from '../../utils/util' ;
22import { expectPropertiesValues , expectSettersMethod } from '../../util-test/util-expect.spec' ;
33import { PoDateService } from '../../services/po-date/po-date.service' ;
4+ import { poLocaleDefault } from '../../utils/util' ;
45
56import { PoTableAction } from './interfaces/po-table-action.interface' ;
67import { PoTableBaseComponent , poTableLiteralsDefault } from './po-table-base.component' ;
78import { PoTableColumn } from './interfaces/po-table-column.interface' ;
8- import { poLocaleDefault } from '../../utils/util' ;
99
1010class PoTableComponent extends PoTableBaseComponent {
1111 calculateWidthHeaders ( ) { }
@@ -383,27 +383,28 @@ describe('PoTableBaseComponent:', () => {
383383 component . sort = true ;
384384 const column = component . columns [ 1 ] ;
385385
386- spyOn ( component , 'sortArray' ) . and . callThrough ( ) ;
386+ spyOn ( component , < any > 'sortArray' ) . and . callThrough ( ) ;
387387 component . sortColumn ( column ) ;
388- expect ( component . sortArray ) . toHaveBeenCalledWith ( column , true ) ;
388+ expect ( component [ ' sortArray' ] ) . toHaveBeenCalledWith ( column , true ) ;
389389
390390 component . sortColumn ( column ) ;
391- expect ( component . sortArray ) . toHaveBeenCalledWith ( column , false ) ;
391+ expect ( component [ ' sortArray' ] ) . toHaveBeenCalledWith ( column , false ) ;
392392 } ) ;
393393
394394 it ( 'should sort values descending' , ( ) => {
395395 const column = component . columns [ 1 ] ;
396396 const sortedItemsDesc = items . slice ( ) . sort ( ( a , b ) => b . numberData - a . numberData ) ;
397397
398- component . sortArray ( column , false ) ;
398+ component [ ' sortArray' ] ( column , false ) ;
399399 expect ( component . items ) . toEqual ( sortedItemsDesc ) ;
400400 } ) ;
401401
402402 it ( 'should sort values ascending' , ( ) => {
403403 const column = component . columns [ 1 ] ;
404404 const sortedItemsAsc = items . slice ( ) . sort ( ( a , b ) => a . numberData - b . numberData ) ;
405405
406- component . sortArray ( column , true ) ;
406+ component [ 'sortArray' ] ( column , true ) ;
407+
407408 expect ( component . items ) . toEqual ( sortedItemsAsc ) ;
408409 } ) ;
409410
@@ -422,29 +423,19 @@ describe('PoTableBaseComponent:', () => {
422423 expect ( component . items ) . toContain ( newItem ) ;
423424 } ) ;
424425
425- it ( 'should return name column detail' , ( ) => {
426- expect ( component . getNameColumnDetail ( ) ) . toBe ( 'detail' ) ;
427- } ) ;
428-
429426 it ( 'should return detail columns and not call sort array using detail column' , ( ) => {
430427 const columnDetail = component . columns [ 3 ] ;
431428
432- expect ( component . getColumnMasterDetail ( ) ) . toEqual ( component . columns [ 3 ] ) ;
433- spyOn ( component , 'sortArray' ) ;
434- component . sortColumn ( columnDetail ) ;
435- expect ( component . sortArray ) . not . toHaveBeenCalled ( ) ;
436- } ) ;
429+ expect ( component [ 'getColumnMasterDetail' ] ( ) ) . toEqual ( component . columns [ 3 ] ) ;
430+ spyOn ( component , < any > 'sortArray' ) ;
437431
438- it ( 'should return null because not have master-detail' , ( ) => {
439- const fakeThis = {
440- getColumnMasterDetail : ( ) => this . columnsTable
441- } ;
432+ component . sortColumn ( columnDetail ) ;
442433
443- expect ( component . getNameColumnDetail . call ( fakeThis ) ) . toBeNull ( ) ;
434+ expect ( component [ 'sortArray' ] ) . not . toHaveBeenCalled ( ) ;
444435 } ) ;
445436
446437 it ( 'should not return the columns of type subtitle' , ( ) => {
447- expect ( component . getSubtitleColumns ( ) . length ) . toBe ( 0 ) ;
438+ expect ( component [ ' getSubtitleColumns' ] ( ) . length ) . toBe ( 0 ) ;
448439 } ) ;
449440
450441 it ( 'should return the columns of type subtitle' , ( ) => {
@@ -455,19 +446,19 @@ describe('PoTableBaseComponent:', () => {
455446 { value : 'canceled' , color : 'color-07' , label : 'Cancelado' , content : '3' }
456447 ]
457448 } ) ;
458- expect ( component . getSubtitleColumns ( ) . length ) . toBe ( 1 ) ;
449+ expect ( component [ ' getSubtitleColumns' ] ( ) . length ) . toBe ( 1 ) ;
459450 } ) ;
460451
461452 it ( 'should return false when items undefined in hasItems method' , ( ) => {
462453 component . items = undefined ;
463454
464- expect ( component . hasItems ( ) ) . toBeFalsy ( ) ;
455+ expect ( component . hasItems ) . toBeFalsy ( ) ;
465456 } ) ;
466457
467458 it ( 'should return true when has items in hasItems method' , ( ) => {
468459 component . items = [ { label : 'teste' } ] ;
469460
470- expect ( component . hasItems ( ) ) . toBeTruthy ( ) ;
461+ expect ( component . hasItems ) . toBeTruthy ( ) ;
471462 } ) ;
472463
473464 describe ( 'Methods:' , ( ) => {
@@ -714,19 +705,6 @@ describe('PoTableBaseComponent:', () => {
714705
715706 } ) ;
716707
717- it ( 'getIconColumns: shouldn´t return the columns of type `icon`.' , ( ) => {
718- expect ( component . getIconColumns ( ) . length ) . toBe ( 0 ) ;
719- } ) ;
720-
721- it ( 'getIconColumns: should return the columns of type `icon`.' , ( ) => {
722- component . columns . push (
723- { property : 'columnIcon' , label : 'Like' , type : 'icon' , color : 'color-08' , icons : [
724- { value : 'po-icon-star' , action : ( ) => this . notification ( ) }
725- ] }
726- ) ;
727- expect ( component . getIconColumns ) . toBeTruthy ( ) ;
728- } ) ;
729-
730708 it ( 'hasColumns: should return `true` if have columns and columns.length is greater then 0' , ( ) => {
731709 expect ( component . hasColumns ) . toBe ( true ) ;
732710 } ) ;
@@ -739,21 +717,21 @@ describe('PoTableBaseComponent:', () => {
739717 } ) ;
740718
741719 it ( 'hasItems: should return `true` if have items and items.length is greater then 0' , ( ) => {
742- expect ( component . hasItems ( ) ) . toBe ( true ) ;
720+ expect ( component . hasItems ) . toBe ( true ) ;
743721 } ) ;
744722
745723 it ( 'hasItems: should return `false` if not have items' , ( ) => {
746724 component . items = undefined ;
747725
748- expect ( component . hasItems ( ) ) . toBeFalsy ( ) ;
726+ expect ( component . hasItems ) . toBeFalsy ( ) ;
749727 } ) ;
750728
751729 it ( `sortArray: should call 'sortDate' when column type is 'date'.` , ( ) => {
752730 const columnDate = component . columns [ 2 ] ;
753731
754732 spyOn ( component [ 'poDate' ] , 'sortDate' ) ;
755733
756- component . sortArray ( columnDate , true ) ;
734+ component [ ' sortArray' ] ( columnDate , true ) ;
757735
758736 expect ( component [ 'poDate' ] . sortDate ) . toHaveBeenCalled ( ) ;
759737 } ) ;
@@ -763,7 +741,7 @@ describe('PoTableBaseComponent:', () => {
763741
764742 spyOn ( component [ 'poDate' ] , 'sortDate' ) ;
765743
766- component . sortArray ( columnDate , true ) ;
744+ component [ ' sortArray' ] ( columnDate , true ) ;
767745
768746 expect ( component [ 'poDate' ] . sortDate ) . toHaveBeenCalled ( ) ;
769747 } ) ;
@@ -773,7 +751,7 @@ describe('PoTableBaseComponent:', () => {
773751
774752 spyOn ( utilsFunctions , 'sortValues' ) ;
775753
776- component . sortArray ( columnDate , true ) ;
754+ component [ ' sortArray' ] ( columnDate , true ) ;
777755
778756 expect ( utilsFunctions . sortValues ) . toHaveBeenCalled ( ) ;
779757 } ) ;
@@ -820,15 +798,15 @@ describe('PoTableBaseComponent:', () => {
820798 component . sortBy . observers = < any > [ { next : ( ) => { } } ] ;
821799
822800 spyOn ( component . sortBy , 'emit' ) . and . callThrough ( ) ;
823- spyOn ( component , 'sortArray' ) . and . callThrough ( ) ;
801+ spyOn ( component , < any > 'sortArray' ) . and . callThrough ( ) ;
824802
825803 component . sortColumn ( column ) ;
826804 expect ( component . sortBy . emit ) . toHaveBeenCalledWith ( { column, type : 'ascending' } ) ;
827- expect ( component . sortArray ) . toHaveBeenCalled ( ) ;
805+ expect ( component [ ' sortArray' ] ) . toHaveBeenCalled ( ) ;
828806
829807 component . sortColumn ( column ) ;
830808 expect ( component . sortBy . emit ) . toHaveBeenCalledWith ( { column, type : 'descending' } ) ;
831- expect ( component . sortArray ) . toHaveBeenCalled ( ) ;
809+ expect ( component [ ' sortArray' ] ) . toHaveBeenCalled ( ) ;
832810 } ) ;
833811
834812 it ( `onShowMore: 'showMore' should emit an object parameter containing 'ascending' as value of property 'type'` , ( ) => {
@@ -1007,6 +985,92 @@ describe('PoTableBaseComponent:', () => {
1007985 expect ( component . collapsed . emit ) . not . toHaveBeenCalled ( ) ;
1008986 } ) ;
1009987
988+ it ( 'onChangeColumns: should call `setMainColumns`, `setColumnMasterDetail` and `setSubtitleColumns`' , ( ) => {
989+ const spySetMainColumns = spyOn ( component , < any > 'setMainColumns' ) ;
990+ const spySetColumnMasterDetail = spyOn ( component , < any > 'setColumnMasterDetail' ) ;
991+ const spySetSubtitleColumns = spyOn ( component , < any > 'setSubtitleColumns' ) ;
992+
993+ component [ 'onChangeColumns' ] ( ) ;
994+
995+ expect ( spySetMainColumns ) . toHaveBeenCalled ( ) ;
996+ expect ( spySetColumnMasterDetail ) . toHaveBeenCalled ( ) ;
997+ expect ( spySetSubtitleColumns ) . toHaveBeenCalled ( ) ;
998+ } ) ;
999+
1000+ it ( 'setColumnMasterDetail: should set `columnMasterDetail` and call `getColumnMasterDetail`' , ( ) => {
1001+ const detailColumn : PoTableColumn = { property : 'detail' , type : 'detail' } ;
1002+ const expectedValue = { ...detailColumn } ;
1003+
1004+ const spyGetColumnMasterDetail = spyOn ( component , < any > 'getColumnMasterDetail' ) . and . callThrough ( ) ;
1005+
1006+ component . columns = [ { ...detailColumn } ] ;
1007+ component [ 'setColumnMasterDetail' ] ( ) ;
1008+
1009+ expect ( component . columnMasterDetail ) . toEqual ( expectedValue ) ;
1010+ expect ( spyGetColumnMasterDetail ) . toHaveBeenCalled ( ) ;
1011+ } ) ;
1012+
1013+ it ( 'setMainColumns: should set mainColumns with visibleColumns, hasMainColumns with true and allColumnsWidthPixels with false' , ( ) => {
1014+ const visibleColumns : Array < PoTableColumn > = [
1015+ { property : 'name' }
1016+ ] ;
1017+
1018+ const invisibleColumns : Array < PoTableColumn > = [
1019+ { property : 'age' , visible : false } ,
1020+ { property : 'address' , type : 'auhdsuha' }
1021+ ] ;
1022+
1023+ component [ '_columns' ] = [ ...visibleColumns , ...invisibleColumns ] ;
1024+
1025+ const expectedValue = [ ...visibleColumns ] ;
1026+
1027+ component [ 'setMainColumns' ] ( ) ;
1028+
1029+ expect ( component . mainColumns ) . toEqual ( expectedValue ) ;
1030+ expect ( component . hasMainColumns ) . toBe ( true ) ;
1031+ expect ( component . allColumnsWidthPixels ) . toBe ( false ) ;
1032+
1033+ } ) ;
1034+
1035+ it ( 'setMainColumns: should set mainColumns with visibleColumns, hasMainColumns with true and allColumnsWidthPixels with true' , ( ) => {
1036+ const visibleColumns : Array < PoTableColumn > = [
1037+ { property : 'name' , width : '50px' } ,
1038+ { property : 'age' , width : '50px' }
1039+ ] ;
1040+
1041+ const invisibleColumns : Array < PoTableColumn > = [
1042+ { property : 'age' , visible : false } ,
1043+ { property : 'address' , type : 'auhdsuha' }
1044+ ] ;
1045+
1046+ component [ '_columns' ] = [ ...visibleColumns , ...invisibleColumns ] ;
1047+
1048+ const expectedValue = [ ...visibleColumns ] ;
1049+
1050+ component [ 'setMainColumns' ] ( ) ;
1051+
1052+ expect ( component . mainColumns ) . toEqual ( expectedValue ) ;
1053+ expect ( component . allColumnsWidthPixels ) . toBe ( true ) ;
1054+ expect ( component . hasMainColumns ) . toBe ( true ) ;
1055+
1056+ } ) ;
1057+
1058+ it ( 'setSubtitleColumns: should set `subtitleColumns` and call `getSubtitleColumns`' , ( ) => {
1059+ const subTitleColumn : PoTableColumn = { property : 'sub' , type : 'subtitle' , subtitles : [
1060+ { value : 'arrived' , color : 'color-07' , label : 'Arrived' , content : 'OK' }
1061+ ] } ;
1062+
1063+ const expectedValue = [ { ...subTitleColumn } ] ;
1064+
1065+ const spyGetSubtitleColumns = spyOn ( component , < any > 'getSubtitleColumns' ) . and . callThrough ( ) ;
1066+
1067+ component . columns = [ { property : 'name' } , { ...subTitleColumn } ] ;
1068+ component [ 'setSubtitleColumns' ] ( ) ;
1069+
1070+ expect ( component . subtitleColumns ) . toEqual ( expectedValue ) ;
1071+ expect ( spyGetSubtitleColumns ) . toHaveBeenCalled ( ) ;
1072+ } ) ;
1073+
10101074 } ) ;
10111075
10121076 describe ( 'Properties:' , ( ) => {
@@ -1112,7 +1176,7 @@ describe('PoTableBaseComponent:', () => {
11121176 it ( 'p-columns, p-items: should call `getDefaultColumns` with item if doesn`t have columns but has items to set default column' , ( ) => {
11131177 const item = { table : 'table' } ;
11141178
1115- spyOn ( component , < any > 'getDefaultColumns' ) ;
1179+ spyOn ( component , < any > 'getDefaultColumns' ) . and . callThrough ( ) ;
11161180
11171181 component . items = [ item ] ;
11181182 component . columns = [ ] ;
@@ -1156,6 +1220,22 @@ describe('PoTableBaseComponent:', () => {
11561220
11571221 expect ( component [ 'sortType' ] ) . toBe ( 'descending' ) ;
11581222 } ) ;
1223+
1224+ it ( 'nameColumnDetail: should return name column detail' , ( ) => {
1225+ const nameColumn = 'extras' ;
1226+ const detailColumn = { property : nameColumn , type : 'detail' } ;
1227+
1228+ component . columns = [ { property : 'name' } , { ...detailColumn } ] ;
1229+
1230+ expect ( component . nameColumnDetail ) . toBe ( nameColumn ) ;
1231+ } ) ;
1232+
1233+ it ( 'nameColumnDetail: should return null if not have master-detail' , ( ) => {
1234+ component . columns = [ { property : 'name' } ] ;
1235+
1236+ expect ( component . nameColumnDetail ) . toBeNull ( ) ;
1237+ } ) ;
1238+
11591239 } ) ;
11601240
11611241} ) ;
0 commit comments