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 <ciprianna.engel@wpengine.com>
This commit is contained in:
Ciprianna Engel
2023-06-22 22:24:21 -05:00
parent 126e862ece
commit c3381408d6
3 changed files with 40 additions and 1 deletions
+5
View File
@@ -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.
@@ -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(
<ApiProvider apis={apiRegistry}>
<SearchContextProvider initialState={initialState}>
<SearchModal open hidden={false} toggleModal={toggleModal} />
</SearchContextProvider>
</ApiProvider>,
{
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');
});
});
@@ -154,7 +154,7 @@ export const Modal = ({ toggleModal }: SearchModalChildrenProps) => {
className={classes.button}
color="primary"
endIcon={<ArrowForwardIcon />}
onClick={handleSearchResultClick}
onClick={handleSearchBarSubmit}
disableRipple
>
View Full Results