Only hide EntityAutocompletePicker if there are no options

Signed-off-by: Zach Hammer <zhammer@seatgeek.com>
This commit is contained in:
Zach Hammer
2024-03-20 12:55:33 -04:00
parent 8cc47df993
commit 24d302fce0
2 changed files with 52 additions and 2 deletions
@@ -88,6 +88,56 @@ describe('<EntityAutocompletePicker/>', () => {
});
});
it('hides filter if there are no available options', async () => {
const mockCatalogApiNoOptions: Partial<jest.Mocked<CatalogApi>> = {
getEntityFacets: jest.fn().mockResolvedValue({
facets: {
'spec.options': [],
},
}),
};
render(
<TestApiProvider apis={[[catalogApiRef, mockCatalogApiNoOptions]]}>
<MockEntityListContextProvider value={{}}>
<EntityAutocompletePicker<EntityFilters>
label="Options"
path="spec.options"
name="options"
Filter={EntityOptionFilter}
/>
</MockEntityListContextProvider>
</TestApiProvider>,
);
await waitFor(() => {
expect(screen.queryByText('Options')).not.toBeInTheDocument();
});
});
it('renders filter if there is one available option', async () => {
const mockCatalogApiOneOption: Partial<jest.Mocked<CatalogApi>> = {
getEntityFacets: jest.fn().mockResolvedValue({
facets: {
'spec.options': [{ value: 'option1', count: 1 }],
},
}),
};
render(
<TestApiProvider apis={[[catalogApiRef, mockCatalogApiOneOption]]}>
<MockEntityListContextProvider value={{}}>
<EntityAutocompletePicker<EntityFilters>
label="Options"
path="spec.options"
name="options"
Filter={EntityOptionFilter}
/>
</MockEntityListContextProvider>
</TestApiProvider>,
);
await waitFor(() => {
expect(screen.queryByText('Options')).toBeInTheDocument();
});
});
it('renders unique options in alphabetical order', async () => {
render(
<TestApiProvider apis={[[catalogApiRef, mockCatalogApi]]}>
@@ -144,8 +144,8 @@ export function EntityAutocompletePicker<
return null;
}
// Hide if there are 1 or fewer options; nothing to pick from
if (availableOptions.length <= 1) return null;
// Hide if there are no options; nothing to pick from
if (availableOptions.length === 0) return null;
return (
<Box className={classes.root} pb={1} pt={1}>