From f015a44eb1b5db0145c4c99d6327997e8ef52cb1 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 23 Jun 2022 06:23:02 -0400 Subject: [PATCH] Template Variable: Datasource variable can be used when MIXED option is selected in panel query (#51170) (#51181) * user essentials mob! :trident: * user essentials mob! :trident: lastFile:public/app/features/query/components/QueryEditorRowHeader.test.tsx * user essentials mob! :trident: * test variables showing in data source picker dropdown on MIXED * clean up unused imports * remove comment * remove unused mock Co-authored-by: Alexandra Vargas Co-authored-by: Joao Silva Co-authored-by: joshhunt Co-authored-by: Ashley Harrison (cherry picked from commit 665da5d063d0880db660fb8d4bcd179c2553195a) Co-authored-by: polibb <13227501+polibb@users.noreply.github.com> --- .../components/QueryEditorRowHeader.test.tsx | 16 +++++++++++++++- .../query/components/QueryEditorRowHeader.tsx | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/app/features/query/components/QueryEditorRowHeader.test.tsx b/public/app/features/query/components/QueryEditorRowHeader.test.tsx index 736c8bc2a95..8873c55a10d 100644 --- a/public/app/features/query/components/QueryEditorRowHeader.test.tsx +++ b/public/app/features/query/components/QueryEditorRowHeader.test.tsx @@ -1,5 +1,6 @@ import { fireEvent, render, screen } from '@testing-library/react'; import React from 'react'; +import { openMenu } from 'react-select-event'; import { DataSourceInstanceSettings } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; @@ -13,11 +14,16 @@ const mockDS = mockDataSource({ type: DataSourceType.Alertmanager, }); +const mockVariable = mockDataSource({ + name: '${dsVariable}', + type: 'datasource', +}); + jest.mock('@grafana/runtime/src/services/dataSourceSrv', () => { return { getDataSourceSrv: () => ({ get: () => Promise.resolve(mockDS), - getList: () => [mockDS], + getList: ({ variables }: { variables: boolean }) => (variables ? [mockDS, mockVariable] : [mockDS]), getInstanceSettings: () => mockDS, }), }; @@ -68,6 +74,14 @@ describe('QueryEditorRowHeader', () => { expect(screen.queryByLabelText(selectors.components.DataSourcePicker.container)).toBeNull(); }); + + it('should render variables in the data source picker', async () => { + renderScenario({ onChangeDataSource: () => {} }); + + const dsSelect = screen.getByLabelText(selectors.components.DataSourcePicker.inputV2); + openMenu(dsSelect); + expect(await screen.findByText('${dsVariable}')).toBeInTheDocument(); + }); }); function renderScenario(overrides: Partial) { diff --git a/public/app/features/query/components/QueryEditorRowHeader.tsx b/public/app/features/query/components/QueryEditorRowHeader.tsx index 20c8d86e900..144401ccf0d 100644 --- a/public/app/features/query/components/QueryEditorRowHeader.tsx +++ b/public/app/features/query/components/QueryEditorRowHeader.tsx @@ -140,7 +140,7 @@ const renderDataSource = ( return (
- +
); };