From 43f894236a5a807b18e9474563662d270e985cb3 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Wed, 3 Jan 2024 12:15:50 +0100 Subject: [PATCH] tests update --- .../dashboard-scene/utils/interactions.ts | 2 +- .../AddPanelButton/AddPanelMenu.test.tsx | 14 +++++-- .../SharePublicDashboard.test.tsx | 30 ++++++++++----- .../dashgrid/DashboardEmpty.test.tsx | 18 +++++++-- .../features/dashboard/utils/tracking.test.ts | 38 ++++++++++--------- 5 files changed, 69 insertions(+), 33 deletions(-) diff --git a/public/app/features/dashboard-scene/utils/interactions.ts b/public/app/features/dashboard-scene/utils/interactions.ts index 3897eab192e..eef19b024bf 100644 --- a/public/app/features/dashboard-scene/utils/interactions.ts +++ b/public/app/features/dashboard-scene/utils/interactions.ts @@ -150,7 +150,7 @@ export const DashboardInteractions = { }; const reportDashboardInteraction: typeof reportInteraction = (name, properties) => { - const meta = isScenesContextSet ? { scenesView: true } : {}; + const meta = isScenesContextSet ? { scenesView: true } : undefined; if (properties) { reportInteraction(`dashboards_${name}`, properties, meta); diff --git a/public/app/features/dashboard/components/AddPanelButton/AddPanelMenu.test.tsx b/public/app/features/dashboard/components/AddPanelButton/AddPanelMenu.test.tsx index ecd44d27f03..8b196ac5f2a 100644 --- a/public/app/features/dashboard/components/AddPanelButton/AddPanelMenu.test.tsx +++ b/public/app/features/dashboard/components/AddPanelButton/AddPanelMenu.test.tsx @@ -110,7 +110,11 @@ it('creates new visualization when clicked on menu item Visualization', () => { fireEvent.click(screen.getByRole('menuitem', { name: 'Visualization' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_toolbar_add_clicked', { item: 'add_visualization' }); + expect(reportInteraction).toHaveBeenCalledWith( + 'dashboards_toolbar_add_clicked', + { item: 'add_visualization' }, + undefined + ); expect(locationService.partial).toHaveBeenCalled(); expect(onCreateNewPanel).toHaveBeenCalled(); }); @@ -122,7 +126,7 @@ it('creates new row when clicked on menu item Row', () => { fireEvent.click(screen.getByRole('menuitem', { name: 'Row' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_toolbar_add_clicked', { item: 'add_row' }); + expect(reportInteraction).toHaveBeenCalledWith('dashboards_toolbar_add_clicked', { item: 'add_row' }, undefined); expect(locationService.partial).not.toHaveBeenCalled(); expect(onCreateNewRow).toHaveBeenCalled(); }); @@ -134,7 +138,11 @@ it('adds a library panel when clicked on menu item Import from library', () => { fireEvent.click(screen.getByRole('menuitem', { name: 'Import from library' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_toolbar_add_clicked', { item: 'import_from_library' }); + expect(reportInteraction).toHaveBeenCalledWith( + 'dashboards_toolbar_add_clicked', + { item: 'import_from_library' }, + undefined + ); expect(locationService.partial).not.toHaveBeenCalled(); expect(onAddLibraryPanel).toHaveBeenCalled(); }); diff --git a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx index e5d26f503a8..d58024bd28f 100644 --- a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx +++ b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx @@ -371,9 +371,13 @@ describe('SharePublic - Report interactions', () => { await waitFor(() => { expect(reportInteraction).toHaveBeenCalledTimes(1); - expect(reportInteraction).toHaveBeenLastCalledWith('dashboards_sharing_public_time_picker_clicked', { - enabled: !pubdashResponse.timeSelectionEnabled, - }); + expect(reportInteraction).toHaveBeenLastCalledWith( + 'dashboards_sharing_public_time_picker_clicked', + { + enabled: !pubdashResponse.timeSelectionEnabled, + }, + undefined + ); }); }); @@ -388,9 +392,13 @@ describe('SharePublic - Report interactions', () => { await waitFor(() => { expect(reportInteraction).toHaveBeenCalledTimes(1); - expect(reportInteraction).toHaveBeenLastCalledWith('dashboards_sharing_public_annotations_clicked', { - enabled: !pubdashResponse.annotationsEnabled, - }); + expect(reportInteraction).toHaveBeenLastCalledWith( + 'dashboards_sharing_public_annotations_clicked', + { + enabled: !pubdashResponse.annotationsEnabled, + }, + undefined + ); }); }); it('reports interaction when pause is clicked', async () => { @@ -402,9 +410,13 @@ describe('SharePublic - Report interactions', () => { await waitFor(() => { expect(reportInteraction).toHaveBeenCalledTimes(1); - expect(reportInteraction).toHaveBeenLastCalledWith('dashboards_sharing_public_pause_clicked', { - paused: pubdashResponse.isEnabled, - }); + expect(reportInteraction).toHaveBeenLastCalledWith( + 'dashboards_sharing_public_pause_clicked', + { + paused: pubdashResponse.isEnabled, + }, + undefined + ); }); }); }); diff --git a/public/app/features/dashboard/dashgrid/DashboardEmpty.test.tsx b/public/app/features/dashboard/dashgrid/DashboardEmpty.test.tsx index 341a67ba10e..bb751d51d56 100644 --- a/public/app/features/dashboard/dashgrid/DashboardEmpty.test.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardEmpty.test.tsx @@ -75,7 +75,11 @@ it('creates new visualization when clicked Add visualization', () => { fireEvent.click(screen.getByRole('button', { name: 'Add visualization' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_emptydashboard_clicked', { item: 'add_visualization' }); + expect(reportInteraction).toHaveBeenCalledWith( + 'dashboards_emptydashboard_clicked', + { item: 'add_visualization' }, + undefined + ); expect(locationService.partial).toHaveBeenCalled(); expect(onCreateNewPanel).toHaveBeenCalled(); }); @@ -87,7 +91,11 @@ it('open import dashboard when clicked Import dashboard', () => { fireEvent.click(screen.getByRole('button', { name: 'Import dashboard' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_emptydashboard_clicked', { item: 'import_dashboard' }); + expect(reportInteraction).toHaveBeenCalledWith( + 'dashboards_emptydashboard_clicked', + { item: 'import_dashboard' }, + undefined + ); expect(onImportDashboard).toHaveBeenCalled(); }); @@ -98,7 +106,11 @@ it('adds a library panel when clicked Add library panel', () => { fireEvent.click(screen.getByRole('button', { name: 'Add library panel' })); }); - expect(reportInteraction).toHaveBeenCalledWith('dashboards_emptydashboard_clicked', { item: 'import_from_library' }); + expect(reportInteraction).toHaveBeenCalledWith( + 'dashboards_emptydashboard_clicked', + { item: 'import_from_library' }, + undefined + ); expect(locationService.partial).not.toHaveBeenCalled(); expect(onAddLibraryPanel).toHaveBeenCalled(); }); diff --git a/public/app/features/dashboard/utils/tracking.test.ts b/public/app/features/dashboard/utils/tracking.test.ts index b92aa5a87d5..83c6eae746e 100644 --- a/public/app/features/dashboard/utils/tracking.test.ts +++ b/public/app/features/dashboard/utils/tracking.test.ts @@ -35,22 +35,26 @@ describe('trackDashboardLoaded', () => { trackDashboardLoaded(model, 16); - expect(reportInteractionSpy).toHaveBeenCalledWith('dashboards_init_dashboard_completed', { - uid: 'dashboard-123', - title: 'Test Dashboard', - schemaVersion: model.schemaVersion, // This value is based on public/app/features/dashboard/state/DashboardMigrator.ts#L81 - panels_count: 7, - variable_type_query_count: 2, - variable_type_interval_count: 1, - version_before_migration: 16, - panel_type_row_count: 1, - panel_type_stat_count: 1, - panel_type_graph_count: 2, - panel_type_timeseries_count: 1, - 'panel_type_grafana-worldmap-panel_count': 1, - panel_type_geomap_count: 1, - settings_nowdelay: '1m', - settings_livenow: true, - }); + expect(reportInteractionSpy).toHaveBeenCalledWith( + 'dashboards_init_dashboard_completed', + { + uid: 'dashboard-123', + title: 'Test Dashboard', + schemaVersion: model.schemaVersion, // This value is based on public/app/features/dashboard/state/DashboardMigrator.ts#L81 + panels_count: 7, + variable_type_query_count: 2, + variable_type_interval_count: 1, + version_before_migration: 16, + panel_type_row_count: 1, + panel_type_stat_count: 1, + panel_type_graph_count: 2, + panel_type_timeseries_count: 1, + 'panel_type_grafana-worldmap-panel_count': 1, + panel_type_geomap_count: 1, + settings_nowdelay: '1m', + settings_livenow: true, + }, + undefined + ); }); });