@@ -12,18 +12,48 @@ import { transformWorkpadIn } from './transform_workpad_in';
1212import { embeddableService , logger } from '../kibana_services' ;
1313import { getDecodedConfig , makeWorkpad } from './fixtures' ;
1414
15+ const mockLensTransformIn = jest . fn ( ( config : any ) => {
16+ const { savedObjectId, ...remainingConfig } = config ;
17+ return {
18+ state : remainingConfig ,
19+ references : [
20+ { id : savedObjectId , name : 'savedObjectRef' , type : 'lens' } ,
21+ ] as SavedObjectReference [ ] ,
22+ } ;
23+ } ) ;
24+
25+ const mockVisualizationTransformIn = jest . fn ( ( config : any ) => {
26+ const { savedObjectId, ...remainingConfig } = config ;
27+ return {
28+ state : remainingConfig ,
29+ references : [
30+ { id : savedObjectId , name : 'savedObjectRef' , type : 'visualization' } ,
31+ ] as SavedObjectReference [ ] ,
32+ } ;
33+ } ) ;
34+
35+ const mockMapTransformIn = jest . fn ( ( config : any ) => {
36+ const { savedObjectId, ...remainingConfig } = config ;
37+ return {
38+ state : remainingConfig ,
39+ references : [
40+ { id : savedObjectId , name : 'savedObjectRef' , type : 'map' } ,
41+ ] as SavedObjectReference [ ] ,
42+ } ;
43+ } ) ;
1544jest . mock ( '../kibana_services' , ( ) => ( {
1645 embeddableService : {
17- getTransforms : jest . fn ( ) . mockReturnValue ( {
18- transformIn : jest . fn ( ( config : any ) => {
19- const { savedObjectId, ...remainingConfig } = config ;
20- return {
21- state : { ...remainingConfig } ,
22- references : [
23- { id : savedObjectId , name : 'savedObjectRef' , type : 'lens' } ,
24- ] as SavedObjectReference [ ] ,
25- } ;
26- } ) ,
46+ getTransforms : jest . fn ( ( type : string ) => {
47+ switch ( type ) {
48+ case 'lens-dashboard-app' :
49+ return { transformIn : mockLensTransformIn } ;
50+ case 'visualization' :
51+ return { transformIn : mockVisualizationTransformIn } ;
52+ case 'map' :
53+ return { transformIn : mockMapTransformIn } ;
54+ default :
55+ return ;
56+ }
2757 } ) ,
2858 } ,
2959 logger : {
@@ -32,7 +62,7 @@ jest.mock('../kibana_services', () => ({
3262} ) ) ;
3363
3464describe ( 'transformWorkpadIn' , ( ) => {
35- it ( 'transforms embeddable config on the way in ' , ( ) => {
65+ it ( 'transforms embeddable with lens config from stored state to REST API state ' , ( ) => {
3666 const workpad = makeWorkpad (
3767 `embeddable type="lens" config="${ encode ( {
3868 title : 'Test lens embeddable' ,
@@ -52,12 +82,67 @@ describe('transformWorkpadIn', () => {
5282 } ,
5383 ] ) ;
5484
55- expect ( embeddableService ?. getTransforms ( 'lens' ) ?. transformIn ) . toHaveBeenCalledWith ( {
85+ expect ( embeddableService ?. getTransforms ) . toHaveBeenCalledWith ( 'lens-dashboard-app' ) ;
86+ expect ( mockLensTransformIn ) . toHaveBeenCalledWith ( {
5687 savedObjectId : 'test-id' ,
5788 title : 'Test lens embeddable' ,
5889 } ) ;
5990 } ) ;
6091
92+ it ( 'transforms embeddable with visualization config from stored state to REST API state' , ( ) => {
93+ const workpad = makeWorkpad (
94+ `embeddable type="visualization" config="${ encode ( {
95+ title : 'Test visualization embeddable' ,
96+ savedObjectId : 'test-id' ,
97+ } ) } "`
98+ ) ;
99+
100+ const { attributes, references } = transformWorkpadIn ( workpad ) ;
101+ expect ( getDecodedConfig ( attributes ) ) . toEqual ( {
102+ title : 'Test visualization embeddable' ,
103+ } ) ;
104+ expect ( references ) . toEqual ( [
105+ {
106+ id : 'test-id' ,
107+ name : 'element-id:savedObjectRef' ,
108+ type : 'visualization' ,
109+ } ,
110+ ] ) ;
111+
112+ expect ( embeddableService ?. getTransforms ) . toHaveBeenCalledWith ( 'visualization' ) ;
113+ expect ( mockVisualizationTransformIn ) . toHaveBeenCalledWith ( {
114+ savedObjectId : 'test-id' ,
115+ title : 'Test visualization embeddable' ,
116+ } ) ;
117+ } ) ;
118+
119+ it ( 'transforms embeddable with map config from stored state to REST API state' , ( ) => {
120+ const workpad = makeWorkpad (
121+ `embeddable type="map" config="${ encode ( {
122+ title : 'Test map embeddable' ,
123+ savedObjectId : 'test-id' ,
124+ } ) } "`
125+ ) ;
126+
127+ const { attributes, references } = transformWorkpadIn ( workpad ) ;
128+ expect ( getDecodedConfig ( attributes ) ) . toEqual ( {
129+ title : 'Test map embeddable' ,
130+ } ) ;
131+ expect ( references ) . toEqual ( [
132+ {
133+ id : 'test-id' ,
134+ name : 'element-id:savedObjectRef' ,
135+ type : 'map' ,
136+ } ,
137+ ] ) ;
138+
139+ expect ( embeddableService ?. getTransforms ) . toHaveBeenCalledWith ( 'map' ) ;
140+ expect ( mockMapTransformIn ) . toHaveBeenCalledWith ( {
141+ savedObjectId : 'test-id' ,
142+ title : 'Test map embeddable' ,
143+ } ) ;
144+ } ) ;
145+
61146 it ( 'logs warnings when transformation fails and returns the original embeddable config and no references' , ( ) => {
62147 ( embeddableService . getTransforms as jest . Mock ) . mockReturnValue ( {
63148 transformIn : jest . fn ( ( ) => {
0 commit comments