@@ -55,10 +55,20 @@ describe('Client Metrics support', () => {
5555 } ) ;
5656
5757 test ( 'does nothing when window.AWSC.Clog is undefined' , ( ) => {
58- window . AWSC = undefined ;
58+ window . AWSC = { } ;
5959 metrics . sendMetric ( 'name' , 0 ) ; // only proves no exception thrown
6060 } ) ;
6161
62+ test ( 'uses panorama API as fallback when AWSC.Clog.log is unavailable' , ( ) => {
63+ delete window . AWSC ;
64+ metrics . sendMetric ( 'name' , 0 ) ;
65+ expect ( window . panorama ) . toHaveBeenCalledWith ( 'trackCustomEvent' , {
66+ eventName : 'name' ,
67+ eventValue : '0' ,
68+ timestamp : expect . any ( Number ) ,
69+ } ) ;
70+ } ) ;
71+
6272 test ( 'does nothing when window.AWSC.Clog.log is undefined' , ( ) => {
6373 window . AWSC = {
6474 Clog : undefined ,
@@ -68,10 +78,15 @@ describe('Client Metrics support', () => {
6878
6979 describe ( 'within an iframe' , ( ) => {
7080 mockConsoleError ( ) ;
81+ const originalWindowParent = Object . getOwnPropertyDescriptor ( window , 'parent' ) ! ;
82+
83+ afterEach ( ( ) => {
84+ Object . defineProperty ( window , 'parent' , originalWindowParent ) ;
85+ expect ( window . parent . AWSC ) . toBeUndefined ( ) ;
86+ } ) ;
87+
7188 const setupIframe = ( ) => {
72- const parentWindow = { ...window } ;
73- Object . defineProperty ( window , 'parent' , { value : parentWindow } ) ;
74- Object . defineProperty ( parentWindow , 'parent' , { value : parentWindow } ) ;
89+ Object . defineProperty ( window , 'parent' , { configurable : true , writable : true , value : { parent : { } } } ) ;
7590 } ;
7691
7792 test ( 'does nothing when AWSC is not defined in the parent iframe' , ( ) => {
@@ -91,6 +106,8 @@ describe('Client Metrics support', () => {
91106 } ,
92107 } ;
93108 jest . spyOn ( window . parent . AWSC . Clog , 'log' ) ;
109+ expect ( window . AWSC ) . toBeUndefined ( ) ;
110+ expect ( window . parent . AWSC ) . toBeDefined ( ) ;
94111
95112 metrics . sendMetric ( 'name' , 0 , undefined ) ;
96113 expect ( window . parent . AWSC . Clog . log ) . toHaveBeenCalledWith ( 'name' , 0 , undefined ) ;
@@ -173,6 +190,17 @@ describe('Client Metrics support', () => {
173190 } ) ;
174191
175192 describe ( 'sendMetricObject' , ( ) => {
193+ test ( 'uses panorama API as fallback when AWSC.Clog.log is unavailable' , ( ) => {
194+ window . AWSC = undefined ;
195+ metrics . sendMetricObject ( { source : 'pkg' , action : 'used' , version : '5.0' } , 1 ) ;
196+ expect ( window . panorama ) . toHaveBeenCalledWith ( 'trackCustomEvent' , {
197+ eventDetail : '{"o":"main","s":"pkg","t":"default","a":"used","f":"react","v":"5.0"}' ,
198+ eventName : 'awsui_pkg_d50' ,
199+ eventValue : '1' ,
200+ timestamp : expect . any ( Number ) ,
201+ } ) ;
202+ } ) ;
203+
176204 describe ( 'correctly maps input object to metric name' , ( ) => {
177205 test ( 'applies default values for theme (default) and framework (react)' , ( ) => {
178206 metrics . sendMetricObject (
0 commit comments