Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/internal/base-component/__tests__/panorama-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PanoramaClient } from '../metrics/log-clients';
declare global {
interface Window {
panorama?: any;
[key: symbol]: any;
}
}

Expand Down Expand Up @@ -86,4 +87,20 @@ describe('PanoramaClient', () => {
panorama.sendMetric({ timestamp: 15 });
expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', expect.objectContaining({ timestamp: 15 }));
});

test('finds panorama function from Symbol.for("panorama") property', () => {
// Remove the regular panorama property
delete window.panorama;

const mockPanoramaSymbolFn = jest.fn();
const panoramaSymbol = Symbol.for('panorama');
(window as any)[panoramaSymbol] = mockPanoramaSymbolFn;

panorama.sendMetric({ eventValue: 'symbol-test' });

expect(mockPanoramaSymbolFn).toHaveBeenCalledWith(
'trackCustomEvent',
expect.objectContaining({ eventType: 'awsui', eventValue: 'symbol-test' })
);
});
});
6 changes: 6 additions & 0 deletions src/internal/base-component/metrics/log-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export class PanoramaClient {
return currentWindow?.panorama;
}

const panoramaSymbol = Symbol.for('panorama');
const symbolProperty = (currentWindow as any)?.[panoramaSymbol];
if (typeof symbolProperty === 'function') {
return symbolProperty as PanoramaFunction;
}

if (!currentWindow || currentWindow.parent === currentWindow) {
// When the window has no more parents, it references itself
return undefined;
Expand Down
Loading