@@ -50,7 +50,11 @@ import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks
5050import { layerTypes , Visualization } from '../..' ;
5151import { set } from '@kbn/safer-lodash-set' ;
5252import { SavedObjectReference } from '@kbn/core-saved-objects-api-server' ;
53- import { getAnnotationsLayers } from './visualization_helpers' ;
53+ import {
54+ getAnnotationsLayers ,
55+ isAnnotationsLayer ,
56+ isByReferenceAnnotationsLayer ,
57+ } from './visualization_helpers' ;
5458import { cloneDeep } from 'lodash' ;
5559import { DataViewsServicePublic } from '@kbn/data-views-plugin/public' ;
5660
@@ -3240,6 +3244,59 @@ describe('xy_visualization', () => {
32403244 } ) ;
32413245 } ) ;
32423246
3247+ describe ( '#cloneLayer' , ( ) => {
3248+ it ( 'should turned cloned by-reference annotation groups into by-value' , ( ) => {
3249+ const state = exampleState ( ) ;
3250+ const layer : XYByValueAnnotationLayerConfig = {
3251+ layerId : 'layer-id' ,
3252+ layerType : 'annotations' ,
3253+ indexPatternId : 'some-index-pattern' ,
3254+ ignoreGlobalFilters : false ,
3255+ annotations : [
3256+ {
3257+ id : 'some-annotation-id' ,
3258+ type : 'manual' ,
3259+ key : {
3260+ type : 'point_in_time' ,
3261+ timestamp : 'timestamp' ,
3262+ } ,
3263+ } as PointInTimeEventAnnotationConfig ,
3264+ ] ,
3265+ } ;
3266+
3267+ state . layers = [
3268+ {
3269+ ...layer ,
3270+ annotationGroupId : 'some-group-id' ,
3271+ __lastSaved : {
3272+ ...layer ,
3273+ title : '' ,
3274+ description : '' ,
3275+ tags : [ ] ,
3276+ } ,
3277+ } ,
3278+ ] ;
3279+
3280+ const newLayerId = 'new-layer-id' ;
3281+
3282+ const stateWithClonedLayer = xyVisualization . cloneLayer ! (
3283+ state ,
3284+ layer . layerId ,
3285+ newLayerId ,
3286+ new Map ( )
3287+ ) ;
3288+
3289+ expect (
3290+ isAnnotationsLayer ( stateWithClonedLayer . layers [ 0 ] ) &&
3291+ isByReferenceAnnotationsLayer ( stateWithClonedLayer . layers [ 0 ] )
3292+ ) . toBe ( true ) ;
3293+ expect (
3294+ isAnnotationsLayer ( stateWithClonedLayer . layers [ 1 ] ) &&
3295+ isByReferenceAnnotationsLayer ( stateWithClonedLayer . layers [ 1 ] )
3296+ ) . toBe ( false ) ;
3297+ } ) ;
3298+ } ) ;
3299+
32433300 describe ( '#getUniqueLabels' , ( ) => {
32443301 it ( 'creates unique labels for single annotations layer with repeating labels' , async ( ) => {
32453302 const annotationLayer : XYAnnotationLayerConfig = {
0 commit comments