11import { OrganizationFixture } from 'sentry-fixture/organization' ;
22
3- import { render , screen , userEvent , within } from 'sentry-test/reactTestingLibrary' ;
3+ import {
4+ render ,
5+ screen ,
6+ userEvent ,
7+ waitFor ,
8+ within ,
9+ } from 'sentry-test/reactTestingLibrary' ;
410
511import { SavedSearchType } from 'sentry/types/group' ;
612import type { Organization } from 'sentry/types/organization' ;
@@ -11,6 +17,8 @@ import {ResultsSearchQueryBuilder} from './resultsSearchQueryBuilder';
1117describe ( 'ResultsSearchQueryBuilder' , ( ) => {
1218 let organization : Organization ;
1319 beforeEach ( ( ) => {
20+ MockApiClient . clearMockResponses ( ) ;
21+
1422 organization = OrganizationFixture ( ) ;
1523 MockApiClient . addMockResponse ( {
1624 url : `/organizations/org-slug/recent-searches/` ,
@@ -27,68 +35,53 @@ describe('ResultsSearchQueryBuilder', () => {
2735 } ) ;
2836 } ) ;
2937
38+ const defaultProps = {
39+ query : '' ,
40+ onSearch : jest . fn ( ) ,
41+ onChange : jest . fn ( ) ,
42+ projectIds : [ ] as number [ ] ,
43+ supportedTags : {
44+ environment : { key : 'environment' , name : 'environment' , kind : FieldKind . FIELD } ,
45+ p50 : { key : 'p50' , name : 'p50' , kind : FieldKind . FUNCTION } ,
46+ transaction : { key : 'transaction' , name : 'transaction' , kind : FieldKind . FIELD } ,
47+ user : { key : 'user' , name : 'user' , kind : FieldKind . FIELD } ,
48+ } ,
49+ recentSearches : SavedSearchType . EVENT ,
50+ fields : [ { field : 'p50(transaction.duration)' } ] ,
51+ } ;
52+
3053 it . knownFlake ( 'does not show function tags in has: dropdown' , async ( ) => {
31- render (
32- < ResultsSearchQueryBuilder
33- query = ""
34- onSearch = { jest . fn ( ) }
35- onChange = { jest . fn ( ) }
36- projectIds = { [ ] }
37- supportedTags = { {
38- environment : { key : 'environment' , name : 'environment' , kind : FieldKind . FIELD } ,
39- p50 : { key : 'p50' , name : 'p50' , kind : FieldKind . FUNCTION } ,
40- transaction : { key : 'transaction' , name : 'transaction' , kind : FieldKind . FIELD } ,
41- user : { key : 'user' , name : 'user' , kind : FieldKind . FIELD } ,
42- } }
43- recentSearches = { SavedSearchType . EVENT }
44- // This fields definition is what caused p50 to appear as a function tag
45- fields = { [ { field : 'p50(transaction.duration)' } ] }
46- /> ,
47- {
48- organization,
49- }
50- ) ;
54+ render ( < ResultsSearchQueryBuilder { ...defaultProps } /> , { organization} ) ;
5155
52- // Focus the input and type "has:p" to simulate a search for p50
5356 const input = await screen . findByRole ( 'combobox' ) ;
54- await userEvent . type ( input , 'has:p' ) ;
57+ await userEvent . click ( input ) ;
58+ await screen . findByRole ( 'listbox' ) ;
59+ await userEvent . keyboard ( 'has:p' ) ;
5560
56- // Check that "p50" (a function tag) is NOT in the dropdown
57- expect (
58- within ( screen . getByRole ( 'listbox' ) ) . queryByText ( 'p50' )
59- ) . not . toBeInTheDocument ( ) ;
61+ const listbox = await screen . findByRole ( 'listbox' ) ;
62+ expect ( within ( listbox ) . queryByText ( 'p50' ) ) . not . toBeInTheDocument ( ) ;
63+
64+ await waitFor ( ( ) => {
65+ expect ( screen . getByRole ( 'combobox' ) ) . toBeInTheDocument ( ) ;
66+ } ) ;
6067 } ) ;
6168
6269 it . knownFlake ( 'shows normal tags, e.g. transaction, in the dropdown' , async ( ) => {
63- render (
64- < ResultsSearchQueryBuilder
65- query = ""
66- onSearch = { jest . fn ( ) }
67- onChange = { jest . fn ( ) }
68- projectIds = { [ ] }
69- supportedTags = { {
70- environment : { key : 'environment' , name : 'environment' , kind : FieldKind . FIELD } ,
71- p50 : { key : 'p50' , name : 'p50' , kind : FieldKind . FUNCTION } ,
72- transaction : { key : 'transaction' , name : 'transaction' , kind : FieldKind . FIELD } ,
73- user : { key : 'user' , name : 'user' , kind : FieldKind . FIELD } ,
74- } }
75- recentSearches = { SavedSearchType . EVENT }
76- // This fields definition is what caused p50 to appear as a function tag
77- fields = { [ { field : 'p50(transaction.duration)' } ] }
78- /> ,
79- {
80- organization,
81- }
82- ) ;
70+ render ( < ResultsSearchQueryBuilder { ...defaultProps } /> , { organization} ) ;
8371
84- // Check that a normal tag (e.g. "transaction") IS in the dropdown
8572 const input = await screen . findByRole ( 'combobox' ) ;
86- await userEvent . type ( input , 'transact' ) ;
73+ await userEvent . click ( input ) ;
74+ await screen . findByRole ( 'listbox' ) ;
75+ await userEvent . keyboard ( 'transact' ) ;
8776
8877 expect (
8978 await within ( screen . getByRole ( 'listbox' ) ) . findByRole ( 'option' , {
9079 name : 'transaction' ,
9180 } )
9281 ) . toBeInTheDocument ( ) ;
82+
83+ await waitFor ( ( ) => {
84+ expect ( screen . getByRole ( 'combobox' ) ) . toBeInTheDocument ( ) ;
85+ } ) ;
9386 } ) ;
9487} ) ;
0 commit comments