diff --git a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx index 95ebbb01afc..303bf88837a 100644 --- a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx +++ b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx @@ -5,6 +5,7 @@ import React, { useState } from 'react'; import { TraceqlSearchScope } from '../dataquery.gen'; import { TempoDatasource } from '../datasource'; import TempoLanguageProvider from '../language_provider'; +import { initTemplateSrv } from '../test_utils'; import { TempoQuery } from '../types'; import { GroupByField } from './GroupByField'; @@ -40,6 +41,8 @@ describe('GroupByField', () => { // Need to use delay: null here to work with fakeTimers // see https://github.com/testing-library/user-event/issues/833 user = userEvent.setup({ delay: null }); + + initTemplateSrv([{ name: 'templateVariable1' }, { name: 'templateVariable2' }], {}); }); afterEach(() => { @@ -132,4 +135,21 @@ describe('GroupByField', () => { expect(groupByFilter?.tag).toBe('http.method'); } }); + + it('should allow selecting template variables', async () => { + const { container } = render( + + ); + + const tagSelect = container.querySelector(`input[aria-label="Select tag for filter 1"]`); + expect(tagSelect).not.toBeNull(); + expect(tagSelect).toBeInTheDocument(); + + if (tagSelect) { + await user.click(tagSelect); + jest.advanceTimersByTime(1000); + expect(await screen.findByText('$templateVariable1')).toBeInTheDocument(); + expect(await screen.findByText('$templateVariable2')).toBeInTheDocument(); + } + }); }); diff --git a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx index e88ab32a21c..bcf53682d7e 100644 --- a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx +++ b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx @@ -11,6 +11,7 @@ import { TempoDatasource } from '../datasource'; import { TempoQuery } from '../types'; import InlineSearchField from './InlineSearchField'; +import { withTemplateVariableOptions } from './SearchField'; import { replaceAt } from './utils'; interface Props { @@ -89,15 +90,20 @@ export const GroupByField = (props: Props) => {