grafana/public/app/plugins/datasource/cloudwatch/tracking.test.ts
Erik Sundell 469f915b8c
CloudWatch: Enable feature adoption tracking in the plugin (#54299)
* improve typing for DashboardLoadedEvent

* cleanup

* add cloudwatch tracking event

* add test

* revert test change

* fix typo

* remove optional

* pr feedback

* reactor test

* revert changes to api and azure

* cleanup

* refactoring test

* pr feedback
2022-09-19 08:53:42 +02:00

40 lines
1.2 KiB
TypeScript

import { DashboardLoadedEvent } from '@grafana/data';
let handler: (e: DashboardLoadedEvent<CloudWatchQuery>) => {};
import { reportInteraction } from '@grafana/runtime';
import './module';
import { CloudWatchDashboardLoadedEvent } from './__mocks__/dashboardOnLoadedEvent';
import { CloudWatchQuery } from './types';
jest.mock('@grafana/runtime', () => {
return {
...jest.requireActual('@grafana/runtime'),
reportInteraction: jest.fn(),
getAppEvents: () => ({
subscribe: jest.fn((e, h) => {
handler = h;
}),
}),
};
});
describe('onDashboardLoadedHandler', () => {
it('should report a `grafana_ds_cloudwatch_dashboard_loaded` interaction ', () => {
handler(CloudWatchDashboardLoadedEvent);
expect(reportInteraction).toHaveBeenCalledWith('grafana_ds_cloudwatch_dashboard_loaded', {
dashboard_id: 'dashboard123',
grafana_version: 'v9.0.0',
org_id: 1,
logs_queries_count: 1,
metrics_queries_count: 21,
metrics_query_builder_count: 3,
metrics_query_code_count: 4,
metrics_query_count: 7,
metrics_search_builder_count: 9,
metrics_search_code_count: 5,
metrics_search_count: 14,
metrics_search_match_exact_count: 9,
});
});
});