Only hide EntityAutocompletePicker if there are no options
Signed-off-by: Zach Hammer <zhammer@seatgeek.com>
This commit is contained in:
+50
@@ -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]]}>
|
||||
|
||||
+2
-2
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user