11import { OrganizationFixture } from 'sentry-fixture/organization' ;
22import { PageFiltersFixture } from 'sentry-fixture/pageFilters' ;
33
4- import { render , screen , userEvent , within } from 'sentry-test/reactTestingLibrary' ;
4+ import {
5+ render ,
6+ screen ,
7+ userEvent ,
8+ waitFor ,
9+ within ,
10+ } from 'sentry-test/reactTestingLibrary' ;
511
612import type { Organization } from 'sentry/types/organization' ;
713import { DiscoverDatasets } from 'sentry/utils/discover/types' ;
14+ import { FieldKind } from 'sentry/utils/fields' ;
815import { useCustomMeasurements } from 'sentry/utils/useCustomMeasurements' ;
916
1017import { EventsSearchBar } from './eventsSearchBar' ;
@@ -25,45 +32,53 @@ describe('EventsSearchBar', () => {
2532 body : [ ] ,
2633 method : 'POST' ,
2734 } ) ;
35+ MockApiClient . addMockResponse ( {
36+ url : `/organizations/org-slug/tags/` ,
37+ body : [
38+ { key : 'environment' , name : 'environment' , kind : FieldKind . FIELD } ,
39+ { key : 'transaction' , name : 'transaction' , kind : FieldKind . FIELD } ,
40+ ] ,
41+ } ) ;
2842 } ) ;
2943
44+ const widgetQuery = {
45+ aggregates : [ 'count_unique(browser.name)' ] ,
46+ columns : [ ] ,
47+ conditions : '' ,
48+ name : '' ,
49+ orderby : '' ,
50+ fieldAliases : undefined ,
51+ fields : undefined ,
52+ isHidden : undefined ,
53+ onDemand : undefined ,
54+ selectedAggregate : undefined ,
55+ } ;
56+
3057 it . knownFlake ( 'does not show function tags in has: dropdown' , async ( ) => {
3158 render (
3259 < EventsSearchBar
3360 onClose = { jest . fn ( ) }
3461 dataset = { DiscoverDatasets . TRANSACTIONS }
3562 pageFilters = { PageFiltersFixture ( ) }
36- widgetQuery = { {
37- aggregates : [ 'count_unique(browser.name)' ] ,
38- columns : [ ] ,
39- conditions : '' ,
40- name : '' ,
41- orderby : '' ,
42- fieldAliases : undefined ,
43- fields : undefined ,
44- isHidden : undefined ,
45- onDemand : undefined ,
46- selectedAggregate : undefined ,
47- } }
63+ widgetQuery = { widgetQuery }
4864 /> ,
49- {
50- organization,
51- }
65+ { organization}
5266 ) ;
5367
5468 const input = await screen . findByRole ( 'combobox' , { name : 'Add a search term' } ) ;
55- await userEvent . click ( input , { delay : null } ) ;
56- await userEvent . paste ( 'has:p' , { delay : null } ) ;
69+ await userEvent . click ( input ) ;
70+ await userEvent . paste ( 'has:p' ) ;
5771
5872 await userEvent . click (
59- screen . getByRole ( 'button' , { name : 'Edit value for filter: has' } )
73+ await screen . findByRole ( 'button' , { name : 'Edit value for filter: has' } )
6074 ) ;
6175
62- // Assert we actually have has: dropdown options before checking exclusions.
6376 expect ( await screen . findByRole ( 'option' , { name : 'environment' } ) ) . toBeInTheDocument ( ) ;
64-
65- // p50 is a function and should not be suggested as a has: tag.
6677 expect ( screen . queryByRole ( 'option' , { name : 'p50' } ) ) . not . toBeInTheDocument ( ) ;
78+
79+ await waitFor ( ( ) => {
80+ expect ( screen . getByRole ( 'combobox' ) ) . toBeInTheDocument ( ) ;
81+ } ) ;
6782 } ) ;
6883
6984 it ( 'shows the selected aggregate in the dropdown' , async ( ) => {
@@ -72,31 +87,22 @@ describe('EventsSearchBar', () => {
7287 onClose = { jest . fn ( ) }
7388 dataset = { DiscoverDatasets . TRANSACTIONS }
7489 pageFilters = { PageFiltersFixture ( ) }
75- widgetQuery = { {
76- aggregates : [ 'count_unique(browser.name)' ] ,
77- columns : [ ] ,
78- conditions : '' ,
79- name : '' ,
80- orderby : '' ,
81- fieldAliases : undefined ,
82- fields : undefined ,
83- isHidden : undefined ,
84- onDemand : undefined ,
85- selectedAggregate : undefined ,
86- } }
90+ widgetQuery = { widgetQuery }
8791 /> ,
88- {
89- organization,
90- }
92+ { organization}
9193 ) ;
9294
9395 const input = await screen . findByRole ( 'combobox' , { name : 'Add a search term' } ) ;
9496 await userEvent . click ( input ) ;
95- await userEvent . paste ( 'count_uni' , { delay : null } ) ;
97+ await userEvent . paste ( 'count_uni' ) ;
9698
9799 expect (
98100 await within ( await screen . findByRole ( 'listbox' ) ) . findByText ( 'count_unique(...)' )
99101 ) . toBeInTheDocument ( ) ;
102+
103+ await waitFor ( ( ) => {
104+ expect ( screen . getByRole ( 'combobox' ) ) . toBeInTheDocument ( ) ;
105+ } ) ;
100106 } ) ;
101107
102108 it ( 'shows normal tags, e.g. transaction, in the dropdown' , async ( ) => {
@@ -105,33 +111,24 @@ describe('EventsSearchBar', () => {
105111 onClose = { jest . fn ( ) }
106112 dataset = { DiscoverDatasets . TRANSACTIONS }
107113 pageFilters = { PageFiltersFixture ( ) }
108- widgetQuery = { {
109- aggregates : [ 'count_unique(browser.name)' ] ,
110- columns : [ ] ,
111- conditions : '' ,
112- name : '' ,
113- orderby : '' ,
114- fieldAliases : undefined ,
115- fields : undefined ,
116- isHidden : undefined ,
117- onDemand : undefined ,
118- selectedAggregate : undefined ,
119- } }
114+ widgetQuery = { widgetQuery }
120115 /> ,
121- {
122- organization,
123- }
116+ { organization}
124117 ) ;
125118
126119 const input = await screen . findByRole ( 'combobox' , { name : 'Add a search term' } ) ;
127120 await userEvent . clear ( input ) ;
128- await userEvent . click ( input , { delay : null } ) ;
129- await userEvent . paste ( 'transact' , { delay : null } ) ;
121+ await userEvent . click ( input ) ;
122+ await userEvent . paste ( 'transact' ) ;
130123
131124 expect (
132125 await within ( await screen . findByRole ( 'listbox' ) ) . findByRole ( 'option' , {
133126 name : 'transaction' ,
134127 } )
135128 ) . toBeInTheDocument ( ) ;
129+
130+ await waitFor ( ( ) => {
131+ expect ( screen . getByRole ( 'combobox' ) ) . toBeInTheDocument ( ) ;
132+ } ) ;
136133 } ) ;
137134} ) ;
0 commit comments