@@ -42,6 +42,10 @@ describe('embeddable state transfer', () => {
4242 const destinationApp = 'superUltraVisualize' ;
4343 const originatingApp = 'superUltraTestDashboard' ;
4444
45+ const testAppId = 'testApp' ;
46+
47+ const buildKey = ( appId : string , key : string ) => `${ appId } -${ key } ` ;
48+
4549 beforeEach ( ( ) => {
4650 currentAppId$ = new Subject ( ) ;
4751 currentAppId$ . next ( originatingApp ) ;
@@ -82,7 +86,9 @@ describe('embeddable state transfer', () => {
8286 it ( 'can send an outgoing editor state' , async ( ) => {
8387 await stateTransfer . navigateToEditor ( destinationApp , { state : { originatingApp } } ) ;
8488 expect ( store . set ) . toHaveBeenCalledWith ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
85- [ EMBEDDABLE_EDITOR_STATE_KEY ] : { originatingApp : 'superUltraTestDashboard' } ,
89+ [ buildKey ( destinationApp , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
90+ originatingApp : 'superUltraTestDashboard' ,
91+ } ,
8692 } ) ;
8793 expect ( application . navigateToApp ) . toHaveBeenCalledWith ( 'superUltraVisualize' , {
8894 path : undefined ,
@@ -98,7 +104,9 @@ describe('embeddable state transfer', () => {
98104 } ) ;
99105 expect ( store . set ) . toHaveBeenCalledWith ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
100106 kibanaIsNowForSports : 'extremeSportsKibana' ,
101- [ EMBEDDABLE_EDITOR_STATE_KEY ] : { originatingApp : 'superUltraTestDashboard' } ,
107+ [ buildKey ( destinationApp , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
108+ originatingApp : 'superUltraTestDashboard' ,
109+ } ,
102110 } ) ;
103111 expect ( application . navigateToApp ) . toHaveBeenCalledWith ( 'superUltraVisualize' , {
104112 path : undefined ,
@@ -117,7 +125,10 @@ describe('embeddable state transfer', () => {
117125 state : { type : 'coolestType' , input : { savedObjectId : '150' } } ,
118126 } ) ;
119127 expect ( store . set ) . toHaveBeenCalledWith ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
120- [ EMBEDDABLE_PACKAGE_STATE_KEY ] : { type : 'coolestType' , input : { savedObjectId : '150' } } ,
128+ [ buildKey ( destinationApp , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
129+ type : 'coolestType' ,
130+ input : { savedObjectId : '150' } ,
131+ } ,
121132 } ) ;
122133 expect ( application . navigateToApp ) . toHaveBeenCalledWith ( 'superUltraVisualize' , {
123134 path : undefined ,
@@ -133,7 +144,10 @@ describe('embeddable state transfer', () => {
133144 } ) ;
134145 expect ( store . set ) . toHaveBeenCalledWith ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
135146 kibanaIsNowForSports : 'extremeSportsKibana' ,
136- [ EMBEDDABLE_PACKAGE_STATE_KEY ] : { type : 'coolestType' , input : { savedObjectId : '150' } } ,
147+ [ buildKey ( destinationApp , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
148+ type : 'coolestType' ,
149+ input : { savedObjectId : '150' } ,
150+ } ,
137151 } ) ;
138152 expect ( application . navigateToApp ) . toHaveBeenCalledWith ( 'superUltraVisualize' , {
139153 path : undefined ,
@@ -151,53 +165,105 @@ describe('embeddable state transfer', () => {
151165
152166 it ( 'can fetch an incoming editor state' , async ( ) => {
153167 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
154- [ EMBEDDABLE_EDITOR_STATE_KEY ] : { originatingApp : 'superUltraTestDashboard' } ,
168+ [ buildKey ( testAppId , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
169+ originatingApp : 'superUltraTestDashboard' ,
170+ } ,
171+ } ) ;
172+ const fetchedState = stateTransfer . getIncomingEditorState ( testAppId ) ;
173+ expect ( fetchedState ) . toEqual ( { originatingApp : 'superUltraTestDashboard' } ) ;
174+ } ) ;
175+
176+ it ( 'can fetch an incoming editor state and ignore state for other apps' , async ( ) => {
177+ store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
178+ [ buildKey ( 'otherApp1' , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
179+ originatingApp : 'whoops not me' ,
180+ } ,
181+ [ buildKey ( 'otherApp2' , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
182+ originatingApp : 'otherTestDashboard' ,
183+ } ,
184+ [ buildKey ( testAppId , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
185+ originatingApp : 'superUltraTestDashboard' ,
186+ } ,
155187 } ) ;
156- const fetchedState = stateTransfer . getIncomingEditorState ( ) ;
188+ const fetchedState = stateTransfer . getIncomingEditorState ( testAppId ) ;
157189 expect ( fetchedState ) . toEqual ( { originatingApp : 'superUltraTestDashboard' } ) ;
190+
191+ const fetchedState2 = stateTransfer . getIncomingEditorState ( 'otherApp2' ) ;
192+ expect ( fetchedState2 ) . toEqual ( { originatingApp : 'otherTestDashboard' } ) ;
158193 } ) ;
159194
160195 it ( 'incoming editor state returns undefined when state is not in the right shape' , async ( ) => {
161196 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
162- [ EMBEDDABLE_EDITOR_STATE_KEY ] : { helloSportsKibana : 'superUltraTestDashboard' } ,
197+ [ buildKey ( testAppId , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
198+ helloSportsKibana : 'superUltraTestDashboard' ,
199+ } ,
163200 } ) ;
164- const fetchedState = stateTransfer . getIncomingEditorState ( ) ;
201+ const fetchedState = stateTransfer . getIncomingEditorState ( testAppId ) ;
165202 expect ( fetchedState ) . toBeUndefined ( ) ;
166203 } ) ;
167204
168205 it ( 'can fetch an incoming embeddable package state' , async ( ) => {
169206 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
170- [ EMBEDDABLE_PACKAGE_STATE_KEY ] : { type : 'skisEmbeddable' , input : { savedObjectId : '123' } } ,
207+ [ buildKey ( testAppId , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
208+ type : 'skisEmbeddable' ,
209+ input : { savedObjectId : '123' } ,
210+ } ,
171211 } ) ;
172- const fetchedState = stateTransfer . getIncomingEmbeddablePackage ( ) ;
212+ const fetchedState = stateTransfer . getIncomingEmbeddablePackage ( testAppId ) ;
173213 expect ( fetchedState ) . toEqual ( { type : 'skisEmbeddable' , input : { savedObjectId : '123' } } ) ;
174214 } ) ;
175215
216+ it ( 'can fetch an incoming embeddable package state and ignore state for other apps' , async ( ) => {
217+ store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
218+ [ buildKey ( testAppId , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
219+ type : 'skisEmbeddable' ,
220+ input : { savedObjectId : '123' } ,
221+ } ,
222+ [ buildKey ( 'testApp2' , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
223+ type : 'crossCountryEmbeddable' ,
224+ input : { savedObjectId : '456' } ,
225+ } ,
226+ } ) ;
227+ const fetchedState = stateTransfer . getIncomingEmbeddablePackage ( testAppId ) ;
228+ expect ( fetchedState ) . toEqual ( { type : 'skisEmbeddable' , input : { savedObjectId : '123' } } ) ;
229+
230+ const fetchedState2 = stateTransfer . getIncomingEmbeddablePackage ( 'testApp2' ) ;
231+ expect ( fetchedState2 ) . toEqual ( {
232+ type : 'crossCountryEmbeddable' ,
233+ input : { savedObjectId : '456' } ,
234+ } ) ;
235+ } ) ;
236+
176237 it ( 'embeddable package state returns undefined when state is not in the right shape' , async ( ) => {
177238 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
178- [ EMBEDDABLE_PACKAGE_STATE_KEY ] : { kibanaIsFor : 'sports' } ,
239+ [ buildKey ( testAppId , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : { kibanaIsFor : 'sports' } ,
179240 } ) ;
180- const fetchedState = stateTransfer . getIncomingEmbeddablePackage ( ) ;
241+ const fetchedState = stateTransfer . getIncomingEmbeddablePackage ( testAppId ) ;
181242 expect ( fetchedState ) . toBeUndefined ( ) ;
182243 } ) ;
183244
184245 it ( 'removes embeddable package key when removeAfterFetch is true' , async ( ) => {
185246 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
186- [ EMBEDDABLE_PACKAGE_STATE_KEY ] : { type : 'coolestType' , input : { savedObjectId : '150' } } ,
247+ [ buildKey ( testAppId , EMBEDDABLE_PACKAGE_STATE_KEY ) ] : {
248+ type : 'coolestType' ,
249+ input : { savedObjectId : '150' } ,
250+ } ,
187251 iSHouldStillbeHere : 'doing the sports thing' ,
188252 } ) ;
189- stateTransfer . getIncomingEmbeddablePackage ( true ) ;
253+ stateTransfer . getIncomingEmbeddablePackage ( testAppId , true ) ;
190254 expect ( store . get ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY ) ) . toEqual ( {
191255 iSHouldStillbeHere : 'doing the sports thing' ,
192256 } ) ;
193257 } ) ;
194258
195259 it ( 'removes editor state key when removeAfterFetch is true' , async ( ) => {
196260 store . set ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY , {
197- [ EMBEDDABLE_EDITOR_STATE_KEY ] : { originatingApp : 'superCoolFootballDashboard' } ,
261+ [ buildKey ( testAppId , EMBEDDABLE_EDITOR_STATE_KEY ) ] : {
262+ originatingApp : 'superCoolFootballDashboard' ,
263+ } ,
198264 iSHouldStillbeHere : 'doing the sports thing' ,
199265 } ) ;
200- stateTransfer . getIncomingEditorState ( true ) ;
266+ stateTransfer . getIncomingEditorState ( testAppId , true ) ;
201267 expect ( store . get ( EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY ) ) . toEqual ( {
202268 iSHouldStillbeHere : 'doing the sports thing' ,
203269 } ) ;
0 commit comments