diff --git a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.test.ts b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.test.ts index 742efaab9f..1d9eaa8af7 100644 --- a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.test.ts +++ b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.test.ts @@ -70,6 +70,21 @@ describe('useFacetsEntities', () => { expect(result.current[0]).toEqual({ value: { items: [] }, loading: true }); }); + it(`should return empty response when facet is not present`, async () => { + mockedGetEntityFacets.mockResolvedValueOnce({ + facets: { 'metadata.tags': [{ value: 'tag', count: 1 }] }, + }); + mockedGetEntitiesByRefs.mockResolvedValueOnce({ items: [] }); + const { result } = renderHook(() => useFacetsEntities({ enabled: true })); + result.current[1]({ text: '' }); + await waitFor(() => { + expect(result.current[0]).toEqual({ + value: { items: [] }, + loading: false, + }); + }); + }); + it(`should return the owners`, async () => { const entityRefs = ['component:default/e1', 'component:default/e2']; mockedGetEntityFacets.mockResolvedValue(facetsFromEntityRefs(entityRefs)); diff --git a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts index 10a5c5a8c2..9bb27eab98 100644 --- a/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts +++ b/plugins/catalog-react/src/components/EntityOwnerPicker/useFacetsEntities.ts @@ -52,7 +52,7 @@ export function useFacetsEntities({ enabled }: { enabled: boolean }) { const facetsResponse = await catalogApi.getEntityFacets({ facets: [facet], }); - const entityRefs = facetsResponse.facets[facet].map(e => e.value); + const entityRefs = facetsResponse.facets[facet]?.map(e => e.value) ?? []; return catalogApi .getEntitiesByRefs({ entityRefs })