File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/internal/base-component Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { PanoramaClient } from '../metrics/log-clients';
66declare global {
77 interface Window {
88 panorama ?: any ;
9+ [ key : symbol ] : any ;
910 }
1011}
1112
@@ -86,4 +87,20 @@ describe('PanoramaClient', () => {
8687 panorama . sendMetric ( { timestamp : 15 } ) ;
8788 expect ( window . panorama ) . toHaveBeenCalledWith ( 'trackCustomEvent' , expect . objectContaining ( { timestamp : 15 } ) ) ;
8889 } ) ;
90+
91+ test ( 'finds panorama function from Symbol.for("panorama") property' , ( ) => {
92+ // Remove the regular panorama property
93+ delete window . panorama ;
94+
95+ const mockPanoramaSymbolFn = jest . fn ( ) ;
96+ const panoramaSymbol = Symbol . for ( 'panorama' ) ;
97+ ( window as any ) [ panoramaSymbol ] = mockPanoramaSymbolFn ;
98+
99+ panorama . sendMetric ( { eventValue : 'symbol-test' } ) ;
100+
101+ expect ( mockPanoramaSymbolFn ) . toHaveBeenCalledWith (
102+ 'trackCustomEvent' ,
103+ expect . objectContaining ( { eventType : 'awsui' , eventValue : 'symbol-test' } )
104+ ) ;
105+ } ) ;
89106} ) ;
Original file line number Diff line number Diff line change @@ -142,6 +142,12 @@ export class PanoramaClient {
142142 return currentWindow ?. panorama ;
143143 }
144144
145+ const panoramaSymbol = Symbol . for ( 'panorama' ) ;
146+ const symbolProperty = ( currentWindow as any ) ?. [ panoramaSymbol ] ;
147+ if ( typeof symbolProperty === 'function' ) {
148+ return symbolProperty as PanoramaFunction ;
149+ }
150+
145151 if ( ! currentWindow || currentWindow . parent === currentWindow ) {
146152 // When the window has no more parents, it references itself
147153 return undefined ;
You can’t perform that action at this time.
0 commit comments