From df51a5507381b7aa487c088fa198b48dcfc9a9e5 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Tue, 22 Jun 2021 17:19:32 +0200 Subject: [PATCH] Fix empty state not being displayed on missing results Closes #6031 Signed-off-by: Oliver Sand --- .changeset/breezy-books-matter.md | 5 +++++ .../SearchResult/SearchResult.test.tsx | 16 +++++++++++++++- .../src/components/SearchResult/SearchResult.tsx | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/breezy-books-matter.md diff --git a/.changeset/breezy-books-matter.md b/.changeset/breezy-books-matter.md new file mode 100644 index 0000000000..1bc206bdc5 --- /dev/null +++ b/.changeset/breezy-books-matter.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search': patch +--- + +Fix empty state not being displayed on missing results. diff --git a/plugins/search/src/components/SearchResult/SearchResult.test.tsx b/plugins/search/src/components/SearchResult/SearchResult.test.tsx index 0a18690353..9508eec259 100644 --- a/plugins/search/src/components/SearchResult/SearchResult.test.tsx +++ b/plugins/search/src/components/SearchResult/SearchResult.test.tsx @@ -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({() => <>}); + + 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: [] } }, diff --git a/plugins/search/src/components/SearchResult/SearchResult.tsx b/plugins/search/src/components/SearchResult/SearchResult.tsx index d720ff933a..a713ae3372 100644 --- a/plugins/search/src/components/SearchResult/SearchResult.tsx +++ b/plugins/search/src/components/SearchResult/SearchResult.tsx @@ -41,7 +41,7 @@ const SearchResultComponent = ({ children }: Props) => { ); } - if (!value) { + if (!value?.results.length) { return ; }