Skip to content

Commit

Permalink
fix(ui): Fix incorrect search dynamic in 'Search Support' modal
Browse files Browse the repository at this point in the history
Fix the bug in which the search query sent in the search request
is the previous input value instead of the current one
(incorrect use of 'componentDidUpdate' in 'static/app/components/
helpSearch.tsx').

Fixes GH-70305
  • Loading branch information
floels committed May 5, 2024
1 parent 3e90887 commit 92922ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions static/app/components/helpSearch.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {SentryGlobalSearch} from '@sentry-internal/global-search';

import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import HelpSearch from 'sentry/components/helpSearch';
Expand Down Expand Up @@ -60,11 +62,15 @@ const mockResults = [
},
];

jest.mock('@sentry-internal/global-search', () => ({
SentryGlobalSearch: jest
.fn()
.mockImplementation(() => ({query: () => Promise.resolve(mockResults)})),
}));
jest.mock('@sentry-internal/global-search', () => {
const mockQuery = jest.fn(() => Promise.resolve(mockResults));

return {
SentryGlobalSearch: jest.fn().mockImplementation(() => ({
query: mockQuery,
})),
};
});

describe('HelpSearch', function () {
it('produces search results', async function () {
Expand All @@ -79,6 +85,14 @@ describe('HelpSearch', function () {

await userEvent.type(screen.getByTestId('search'), 'dummy');

const mockSentryGlobalSearch = new SentryGlobalSearch();

expect(mockSentryGlobalSearch.query).toHaveBeenLastCalledWith(
'dummy',
{platforms: []},
{analyticsTags: ['source:dashboard']}
);

await screen.findByText('From Documentation');

for (const result of mockResults) {
Expand Down
6 changes: 3 additions & 3 deletions static/app/components/search/sources/helpSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class HelpSource extends Component<Props, State> {
}
}

componentDidUpdate(nextProps: Props) {
if (nextProps.query !== this.props.query) {
this.doSearch(nextProps.query);
componentDidUpdate(prevProps: Props) {
if (prevProps.query !== this.props.query) {
this.doSearch(this.props.query);
}
}

Expand Down

0 comments on commit 92922ae

Please sign in to comment.