@@ -1139,6 +1139,122 @@ describe('state_helpers', () => {
11391139 } ) . columns . col1
11401140 ) . toEqual ( expect . objectContaining ( { label : 'Average of bytes' } ) ) ;
11411141 } ) ;
1142+
1143+ it ( 'should carry over a custom label when transitioning to a managed reference' , ( ) => {
1144+ expect (
1145+ replaceColumn ( {
1146+ layer : {
1147+ indexPatternId : '1' ,
1148+ columnOrder : [ 'col1' , 'col2' ] ,
1149+ columns : {
1150+ col1 : {
1151+ label : 'MY CUSTOM LABEL' ,
1152+ customLabel : true ,
1153+ dataType : 'string' ,
1154+ isBucketed : true ,
1155+ operationType : 'terms' ,
1156+ sourceField : 'source' ,
1157+ params : {
1158+ orderBy : { type : 'alphabetical' } ,
1159+ orderDirection : 'asc' ,
1160+ size : 5 ,
1161+ } ,
1162+ } ,
1163+ } ,
1164+ } ,
1165+ indexPattern,
1166+ columnId : 'col1' ,
1167+ op : 'formula' ,
1168+ field : indexPattern . fields [ 2 ] , // bytes field
1169+ visualizationGroups : [ ] ,
1170+ shouldResetLabel : undefined ,
1171+ } ) . columns . col1
1172+ ) . toEqual ( expect . objectContaining ( { label : 'MY CUSTOM LABEL' } ) ) ;
1173+ } ) ;
1174+
1175+ it ( 'should overwrite the current label when transitioning to a managed reference operation when not custom' , ( ) => {
1176+ expect (
1177+ replaceColumn ( {
1178+ layer : {
1179+ indexPatternId : '1' ,
1180+ columnOrder : [ 'col1' , 'col2' ] ,
1181+ columns : {
1182+ col1 : {
1183+ label : 'Average of bytes' ,
1184+ dataType : 'number' ,
1185+ isBucketed : false ,
1186+ operationType : 'average' ,
1187+ sourceField : 'bytes' ,
1188+ } ,
1189+ } ,
1190+ } ,
1191+ indexPattern,
1192+ columnId : 'col1' ,
1193+ op : 'formula' ,
1194+ field : indexPattern . fields [ 2 ] , // bytes field
1195+ visualizationGroups : [ ] ,
1196+ shouldResetLabel : undefined ,
1197+ } ) . columns . col1
1198+ ) . toEqual ( expect . objectContaining ( { label : 'average(bytes)' } ) ) ;
1199+ } ) ;
1200+
1201+ it ( 'should carry over a custom label when transitioning from a managed reference' , ( ) => {
1202+ expect (
1203+ replaceColumn ( {
1204+ layer : {
1205+ indexPatternId : '1' ,
1206+ columnOrder : [ 'col1' , 'col2' ] ,
1207+ columns : {
1208+ col1 : {
1209+ label : 'MY CUSTOM LABEL' ,
1210+ customLabel : true ,
1211+ dataType : 'number' ,
1212+ operationType : 'formula' ,
1213+ isBucketed : false ,
1214+ scale : 'ratio' ,
1215+ params : { isFormulaBroken : false , formula : 'average(bytes)' } ,
1216+ references : [ ] ,
1217+ } ,
1218+ } ,
1219+ } ,
1220+ indexPattern,
1221+ columnId : 'col1' ,
1222+ op : 'average' ,
1223+ field : indexPattern . fields [ 2 ] , // bytes field
1224+ visualizationGroups : [ ] ,
1225+ shouldResetLabel : undefined ,
1226+ } ) . columns . col1
1227+ ) . toEqual ( expect . objectContaining ( { label : 'MY CUSTOM LABEL' } ) ) ;
1228+ } ) ;
1229+
1230+ it ( 'should not carry over the managed reference default label to the new operation' , ( ) => {
1231+ expect (
1232+ replaceColumn ( {
1233+ layer : {
1234+ indexPatternId : '1' ,
1235+ columnOrder : [ 'col1' , 'col2' ] ,
1236+ columns : {
1237+ col1 : {
1238+ label : 'average(bytes)' ,
1239+ customLabel : true ,
1240+ dataType : 'number' ,
1241+ operationType : 'formula' ,
1242+ isBucketed : false ,
1243+ scale : 'ratio' ,
1244+ params : { isFormulaBroken : false , formula : 'average(bytes)' } ,
1245+ references : [ ] ,
1246+ } ,
1247+ } ,
1248+ } ,
1249+ indexPattern,
1250+ columnId : 'col1' ,
1251+ op : 'average' ,
1252+ field : indexPattern . fields [ 2 ] , // bytes field
1253+ visualizationGroups : [ ] ,
1254+ shouldResetLabel : undefined ,
1255+ } ) . columns . col1
1256+ ) . toEqual ( expect . objectContaining ( { label : 'Average of bytes' } ) ) ;
1257+ } ) ;
11421258 } ) ;
11431259
11441260 it ( 'should execute adjustments for other columns' , ( ) => {
0 commit comments