Fix empty state not being displayed on missing results
Closes #6031 Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-search': patch
|
||||
---
|
||||
|
||||
Fix empty state not being displayed on missing results.
|
||||
@@ -55,7 +55,7 @@ describe('SearchResult', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('On empty result value state', async () => {
|
||||
it('On no result value state', async () => {
|
||||
(useSearch as jest.Mock).mockReturnValueOnce({
|
||||
result: { loading: false, error: '', value: undefined },
|
||||
});
|
||||
@@ -69,6 +69,20 @@ describe('SearchResult', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('On empty result value state', async () => {
|
||||
(useSearch as jest.Mock).mockReturnValueOnce({
|
||||
result: { loading: false, error: '', value: { results: [] } },
|
||||
});
|
||||
|
||||
const { getByRole } = render(<SearchResult>{() => <></>}</SearchResult>);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByRole('heading', { name: 'Sorry, no results were found' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('Calls children with results set to result.value', () => {
|
||||
(useSearch as jest.Mock).mockReturnValueOnce({
|
||||
result: { loading: false, error: '', value: { results: [] } },
|
||||
|
||||
@@ -41,7 +41,7 @@ const SearchResultComponent = ({ children }: Props) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
if (!value?.results.length) {
|
||||
return <EmptyState missing="data" title="Sorry, no results were found" />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user