From c3381408d6336e356d1a7deb502de1bc593868cf Mon Sep 17 00:00:00 2001 From: Ciprianna Engel Date: Thu, 22 Jun 2023 22:24:21 -0500 Subject: [PATCH] Use navigation handler in onClick to view full results Full results button in searchModal was not correctly navigating onClick. This switches the onClick to the correct handler function to navigate. Signed-off-by: Ciprianna Engel --- .changeset/afraid-windows-rule.md | 5 +++ .../SearchModal/SearchModal.test.tsx | 34 +++++++++++++++++++ .../components/SearchModal/SearchModal.tsx | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/afraid-windows-rule.md diff --git a/.changeset/afraid-windows-rule.md b/.changeset/afraid-windows-rule.md new file mode 100644 index 0000000000..5ed217d3a3 --- /dev/null +++ b/.changeset/afraid-windows-rule.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search': patch +--- + +Fixed bug in "View Full Results" link of Search Modal that did not navigate to the full results page. diff --git a/plugins/search/src/components/SearchModal/SearchModal.test.tsx b/plugins/search/src/components/SearchModal/SearchModal.test.tsx index 1ab7952a2b..33c2df9ab8 100644 --- a/plugins/search/src/components/SearchModal/SearchModal.test.tsx +++ b/plugins/search/src/components/SearchModal/SearchModal.test.tsx @@ -45,6 +45,7 @@ describe('SearchModal', () => { beforeEach(() => { query.mockClear(); + navigate.mockClear(); }); const toggleModal = jest.fn(); @@ -207,4 +208,37 @@ describe('SearchModal', () => { expect(navigate).toHaveBeenCalledWith('/search?query=new term'); }); + + it('should navigate with correct search terms to full results', async () => { + const initialState = { + term: 'term', + filters: {}, + types: [], + pageCursor: '', + }; + + await renderInTestApp( + + + + , + { + mountedRoutes: { + '/search': rootRouteRef, + }, + }, + ); + + expect(query).toHaveBeenCalledWith( + expect.objectContaining({ term: 'term' }), + ); + + const fullResultsBtn = screen.getByRole('button', { + name: /view full results/i, + }); + await userEvent.click(fullResultsBtn); + + expect(navigate).toHaveBeenCalledWith('/search?query=term'); + }); }); diff --git a/plugins/search/src/components/SearchModal/SearchModal.tsx b/plugins/search/src/components/SearchModal/SearchModal.tsx index 777a285107..dec0f9f482 100644 --- a/plugins/search/src/components/SearchModal/SearchModal.tsx +++ b/plugins/search/src/components/SearchModal/SearchModal.tsx @@ -154,7 +154,7 @@ export const Modal = ({ toggleModal }: SearchModalChildrenProps) => { className={classes.button} color="primary" endIcon={} - onClick={handleSearchResultClick} + onClick={handleSearchBarSubmit} disableRipple > View Full Results