grafana/public/app/plugins/datasource/grafana-azure-monitor-datasource/module.test.ts
Yaelle Chaudy 711c504b39
Azure Monitor: Updated grafana_ds_azuremonitor_dashboard_loaded event, replaced array of queries for stats (#54286)
* Replaced array of queries for stats

* Added ds_version prop

* Added ds_version to tests

* Extracted event name to tracking file

* Extracted event to tracking file

* Removed ds_version - useless for core plugin

* Addressed comments

* Added note to event documentation
2022-08-30 09:55:40 +02:00

49 lines
1.5 KiB
TypeScript

import { DashboardLoadedEvent } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import './module';
jest.mock('@grafana/runtime', () => {
return {
...jest.requireActual('@grafana/runtime'),
reportInteraction: jest.fn(),
getAppEvents: () => ({
subscribe: jest.fn((e, handler) => {
// Trigger test event
handler(
new DashboardLoadedEvent({
dashboardId: 'dashboard123',
orgId: 1,
userId: 2,
grafanaVersion: 'v9.0.0',
queries: {
'grafana-azure-monitor-datasource': [
{ queryType: 'Azure Monitor', hide: false },
{ queryType: 'Azure Log Analytics', hide: false },
{ queryType: 'Azure Resource Graph', hide: true },
{ queryType: 'Azure Monitor', hide: false },
],
},
})
);
}),
}),
};
});
describe('queriesOnInitDashboard', () => {
it('should report a `grafana_ds_azuremonitor_dashboard_loaded` interaction ', () => {
// subscribeDashboardLoadedEvent();
expect(reportInteraction).toHaveBeenCalledWith('grafana_ds_azuremonitor_dashboard_loaded', {
dashboard_id: 'dashboard123',
grafana_version: 'v9.0.0',
org_id: 1,
azure_monitor_queries: 2,
azure_log_analytics_queries: 1,
azure_resource_graph_queries: 0,
azure_monitor_queries_hidden: 0,
azure_log_analytics_queries_hidden: 0,
azure_resource_graph_queries_hidden: 1,
});
});
});