import { checkIfSeriesHaveSameFormatters } from './check_if_series_have_same_formatters' ; import { DATA_FORMATTERS } from '../../../../common/enums' ; import type { Series } from '../../../../common/types' ; describe ( 'checkIfSeriesHaveSameFormatters(seriesModel, fieldFormatMap)' , ( ) => { const fieldFormatMap = { someField : { id : 'string' , params : { transform : 'upper' } } , anotherField : { id : 'number' , params : { pattern : '$0,0.[00]' } } , } ; it ( 'should return true for the same series formatters' , ( ) => { const seriesModel = [ { formatter : DATA_FORMATTERS . BYTES , metrics : [ { field : 'someField' } ] } , { formatter : DATA_FORMATTERS . BYTES , metrics : [ { field : 'anotherField' } ] } , ] as Series [ ] ; const result = checkIfSeriesHaveSameFormatters ( seriesModel , fieldFormatMap ) ; expect ( result ) . toBe ( true ) ; } ) ; it ( 'should return false for the different value_template series formatters' , ( ) => { const seriesModel = [ { formatter : DATA_FORMATTERS . PERCENT , value_template : '{{value}} first' , } , { formatter : DATA_FORMATTERS . PERCENT , value_template : '{{value}} second' , } , ] as Series [ ] ; const result = checkIfSeriesHaveSameFormatters ( seriesModel , fieldFormatMap ) ; expect ( result ) . toBe ( false ) ; } ) ; it ( 'should return true for the same field formatters' , ( ) => { const seriesModel = [ { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'someField' } ] } , { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'someField' } ] } , ] as Series [ ] ; const result = checkIfSeriesHaveSameFormatters ( seriesModel , fieldFormatMap ) ; expect ( result ) . toBe ( true ) ; } ) ; it ( 'should return false for the different field formatters' , ( ) => { const seriesModel = [ { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'someField' } ] } , { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'anotherField' } ] , } , ] as Series [ ] ; const result = checkIfSeriesHaveSameFormatters ( seriesModel , fieldFormatMap ) ; expect ( result ) . toBe ( false ) ; } ) ; it ( 'should return false for when there is no custom formatter for a field' , ( ) => { const seriesModel = [ { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'someField' } , { field : 'field' } ] , } , { formatter : DATA_FORMATTERS . DEFAULT , metrics : [ { field : 'someField' } ] } , ] as Series [ ] ; const result = checkIfSeriesHaveSameFormatters ( seriesModel , fieldFormatMap ) ; expect ( result ) . toBe ( false ) ; } ) ; } ) ;