From c092af9f6b402420bee23a8ec7e05ca1d039fd3f Mon Sep 17 00:00:00 2001 From: Haris Rozajac Date: Tue, 3 Feb 2026 17:11:35 -0700 Subject: [PATCH] add exporter test --- .../scene/export/exporters.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/public/app/features/dashboard-scene/scene/export/exporters.test.ts b/public/app/features/dashboard-scene/scene/export/exporters.test.ts index d13af3e8092..12ab9f563bd 100644 --- a/public/app/features/dashboard-scene/scene/export/exporters.test.ts +++ b/public/app/features/dashboard-scene/scene/export/exporters.test.ts @@ -7,6 +7,8 @@ import { LibraryPanelKind, PanelKind, QueryVariableKind, + AdhocVariableKind, + GroupByVariableKind, } from '@grafana/schema/dist/esm/schema/dashboard/v2'; import { handyTestingSchema } from '@grafana/schema/dist/esm/schema/dashboard/v2_examples'; import config from 'app/core/config'; @@ -718,6 +720,35 @@ describe('dashboard exporter v2', () => { expect(annotationQuery.spec.query?.datasource?.name).toBeUndefined(); }); + it('should assign export labels to data queries during export', async () => { + const { dashboard } = await setup(); + + const panel = dashboard.elements['panel-1']; + if (panel.kind !== 'Panel') { + throw new Error('Panel should be a Panel'); + } + const panelQuery = panel.spec.data.spec.queries[0]; + expect(panelQuery.spec.query.labels?.exportLabel).toBe('prometheus-1'); + + const queryVariable = dashboard.variables.find( + (variable) => variable.kind === 'QueryVariable' + ) as QueryVariableKind; + expect(queryVariable.spec.query.labels?.exportLabel).toBe('prometheus-1'); + + const groupByVariable = dashboard.variables.find( + (variable) => variable.kind === 'GroupByVariable' + ) as GroupByVariableKind; + expect(groupByVariable.labels?.exportLabel).toBe('prometheus-2'); + + const adhocVariable = dashboard.variables.find( + (variable) => variable.kind === 'AdhocVariable' + ) as AdhocVariableKind; + expect(adhocVariable.labels?.exportLabel).toBe('prometheus-3'); + + const annotationQuery = dashboard.annotations[0]; + expect(annotationQuery.spec.query.labels?.exportLabel).toBe('prometheus-4'); + }); + it('should not remove datasource ref from panel that uses a datasource variable', async () => { const { dashboard } = await setup(); const panel = dashboard.elements['panel-using-datasource-var'];