@@ -10,9 +10,12 @@ import {
1010} from 'sentry-test/reactTestingLibrary' ;
1111
1212import type { DatePageFilterProps } from 'sentry/components/organizations/datePageFilter' ;
13+ import { trackAnalytics } from 'sentry/utils/analytics' ;
1314import { MetricsTabContent } from 'sentry/views/explore/metrics/metricsTab' ;
1415import { MultiMetricsQueryParamsProvider } from 'sentry/views/explore/metrics/multiMetricsQueryParams' ;
1516
17+ jest . mock ( 'sentry/utils/analytics' ) ;
18+
1619const datePageFilterProps : DatePageFilterProps = {
1720 defaultPeriod : '7d' as const ,
1821 maxPickableDays : 7 ,
@@ -217,4 +220,35 @@ describe('MetricsTabContent', () => {
217220 expect ( within ( toolbars [ 2 ] ! ) . getByRole ( 'button' , { name : 'foo' } ) ) . toBeInTheDocument ( ) ;
218221 expect ( screen . getAllByTestId ( 'metric-panel' ) ) . toHaveLength ( 3 ) ;
219222 } ) ;
223+
224+ it ( 'should fire analytics for metadata' , async ( ) => {
225+ render (
226+ < ProviderWrapper >
227+ < MetricsTabContent datePageFilterProps = { datePageFilterProps } />
228+ </ ProviderWrapper > ,
229+ {
230+ initialRouterConfig,
231+ organization,
232+ }
233+ ) ;
234+
235+ const toolbars = screen . getAllByTestId ( 'metric-toolbar' ) ;
236+ expect ( toolbars ) . toHaveLength ( 1 ) ;
237+
238+ await waitFor ( ( ) => {
239+ expect ( within ( toolbars [ 0 ] ! ) . getByRole ( 'button' , { name : 'bar' } ) ) . toBeInTheDocument ( ) ;
240+ } ) ;
241+
242+ await waitFor ( ( ) => {
243+ expect ( trackAnalytics ) . toHaveBeenCalledWith (
244+ 'metrics.explorer.metadata' ,
245+ expect . objectContaining ( {
246+ organization,
247+ metric_queries_count : 1 ,
248+ } )
249+ ) ;
250+ } ) ;
251+
252+ expect ( trackAnalytics ) . toHaveBeenCalledTimes ( 1 ) ;
253+ } ) ;
220254} ) ;
0 commit comments