Skip to content

Commit b06ca47

Browse files
JoshuaKGoldbergclaudegetsantry[bot]
authored
fix(test): stabilize flaky EventsSearchBar has: dropdown test (#111903)
The `has:` dropdown values come from `useTags()` which reads `TagStore`. In this unit test, no parent page component calls `loadOrganizationTags`, but `SearchQueryBuilder` still fires a `GET /organizations/org-slug/tags/` request internally. Without a mock, that request silently fails (mock client swallows it), leaving the dropdown unreliably populated. - Mock `/organizations/org-slug/tags/` so the `has:` dropdown is deterministically populated - `findByRole` instead of `getByRole` for elements that appear asynchronously - `waitFor` at end of each test to let pending state updates settle before unmount Fixes DAIN-1271 Made with [Cursor](https://cursor.com) --------- Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent abe7c05 commit b06ca47

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

static/app/views/dashboards/widgetBuilder/buildSteps/filterResultsStep/eventsSearchBar.spec.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import {OrganizationFixture} from 'sentry-fixture/organization';
22
import {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

612
import type {Organization} from 'sentry/types/organization';
713
import {DiscoverDatasets} from 'sentry/utils/discover/types';
14+
import {FieldKind} from 'sentry/utils/fields';
815
import {useCustomMeasurements} from 'sentry/utils/useCustomMeasurements';
916

1017
import {EventsSearchBar} from './eventsSearchBar';
@@ -25,6 +32,13 @@ 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

3044
it.isKnownFlake('does not show function tags in has: dropdown', async () => {
@@ -64,6 +78,10 @@ describe('EventsSearchBar', () => {
6478

6579
// p50 is a function and should not be suggested as a has: tag.
6680
expect(screen.queryByRole('option', {name: 'p50'})).not.toBeInTheDocument();
81+
82+
await waitFor(() => {
83+
expect(screen.getByRole('combobox')).toBeInTheDocument();
84+
});
6785
});
6886

6987
it('shows the selected aggregate in the dropdown', async () => {
@@ -97,6 +115,10 @@ describe('EventsSearchBar', () => {
97115
expect(
98116
await within(await screen.findByRole('listbox')).findByText('count_unique(...)')
99117
).toBeInTheDocument();
118+
119+
await waitFor(() => {
120+
expect(screen.getByRole('combobox')).toBeInTheDocument();
121+
});
100122
});
101123

102124
it('shows normal tags, e.g. transaction, in the dropdown', async () => {
@@ -133,5 +155,9 @@ describe('EventsSearchBar', () => {
133155
name: 'transaction',
134156
})
135157
).toBeInTheDocument();
158+
159+
await waitFor(() => {
160+
expect(screen.getByRole('combobox')).toBeInTheDocument();
161+
});
136162
});
137163
});

0 commit comments

Comments
 (0)