From bd9f398150381ce928b1939550d87e966ef6b8ce Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Fri, 30 Sep 2022 14:53:59 +0200 Subject: [PATCH] Tests for custom no result component Co-authored-by: Camila Loiola Signed-off-by: Emma Indal --- .../SearchResultGroup.test.tsx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/plugins/search-react/src/components/SearchResultGroup/SearchResultGroup.test.tsx b/plugins/search-react/src/components/SearchResultGroup/SearchResultGroup.test.tsx index c1b45cc433..7943dba3f7 100644 --- a/plugins/search-react/src/components/SearchResultGroup/SearchResultGroup.test.tsx +++ b/plugins/search-react/src/components/SearchResultGroup/SearchResultGroup.test.tsx @@ -291,6 +291,46 @@ describe('SearchResultGroup', () => { }); }); + it('Does not render result group if no results returned and disableRenderingWithNoResults prop is provided', async () => { + query.mockResolvedValueOnce({ results: [] }); + await renderWithEffects( + wrapInTestApp( + + } + title="Documentation" + disableRenderingWithNoResults + /> + , + ), + ); + + await waitFor(() => { + expect(screen.queryByText('Documentation')).not.toBeInTheDocument(); + }); + }); + + it('Should render custom component when no results returned', async () => { + query.mockResolvedValueOnce({ results: [] }); + await renderWithEffects( + wrapInTestApp( + + } + title="Documentation" + noResultsComponent="No results were found" + /> + , + ), + ); + + await waitFor(() => { + expect(screen.getByText('No results were found')).toBeInTheDocument(); + }); + }); + it('Shows an error panel when results rendering fails', async () => { query.mockRejectedValueOnce(new Error()); await renderWithEffects(