diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.test.tsx index 4656e43692a8..dccf1109b8df 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.test.tsx @@ -10,8 +10,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { render, screen } from '@testing-library/react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; import { TagSource } from '../../../generated/type/tagLabel'; +import { searchGlossaryTerms } from '../../../rest/glossaryAPI'; +import { convertGlossaryTermsToTreeOptions } from '../../../utils/GlossaryUtils'; import { SelectOption } from './AsyncSelectList.interface'; import TreeAsyncSelectList from './TreeAsyncSelectList'; @@ -56,4 +58,46 @@ describe('TreeAsyncSelectList', () => { it('should render the component', () => { expect(screen.getByTestId('tag-selector')).toBeInTheDocument(); }); + + it('should expand every level of the search results', async () => { + jest.useFakeTimers(); + (convertGlossaryTermsToTreeOptions as jest.Mock).mockImplementation( + jest.requireActual('../../../utils/GlossaryUtils') + .convertGlossaryTermsToTreeOptions + ); + (searchGlossaryTerms as jest.Mock).mockResolvedValue([ + { + id: 'g', + name: 'Business', + fullyQualifiedName: 'Business', + children: [ + { + id: 'c', + name: 'Customer', + fullyQualifiedName: 'Business.Customer', + children: [ + { + id: 't', + name: 'Churn', + fullyQualifiedName: 'Business.Customer.Churn', + }, + ], + }, + ], + }, + ]); + + fireEvent.change(screen.getByRole('combobox'), { + target: { value: 'Churn' }, + }); + await act(async () => { + jest.advanceTimersByTime(300); + }); + + expect( + await screen.findByTestId('tag-Business.Customer.Churn') + ).toBeInTheDocument(); + + jest.useRealTimers(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.tsx index d6a15877c888..3df7afc20daa 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/AsyncSelectList/TreeAsyncSelectList.tsx @@ -52,6 +52,7 @@ import { import { getEntityName } from '../../../utils/EntityNameUtils'; import { filterTreeNodeOptions, + findExpandableKeysForArray, findItemByFqn, } from '../../../utils/GlossaryPureUtils'; import { convertGlossaryTermsToTreeOptions } from '../../../utils/GlossaryUtils'; @@ -433,9 +434,14 @@ const TreeAsyncSelectList: FC = ({ const encodedValue = getEncodedFqn(escapeESReservedCharacters(value)); const results: Glossary[] = await searchGlossaryTerms(encodedValue); - setSearchOptions(filterTreeNodeOptions(results, filterOptions)); + const filteredResults = filterTreeNodeOptions(results, filterOptions); + + setSearchOptions(filteredResults); + // Expand every level so matches nested under parent terms are visible setExpandedRowKeys( - results.map((result) => result.fullyQualifiedName as string) + findExpandableKeysForArray( + filteredResults as unknown as ModifiedGlossaryTerm[] + ) ); setIsLoading(false); } else {