diff --git a/src/search-modal/SearchResult.jsx b/src/search-modal/SearchResult.jsx
index 620608b8be..7fb4cb2599 100644
--- a/src/search-modal/SearchResult.jsx
+++ b/src/search-modal/SearchResult.jsx
@@ -41,7 +41,7 @@ function getItemIcon(blockType) {
*/
function getLibraryHitUrl(hit, libraryAuthoringMfeUrl) {
const { contextKey } = hit;
- return `${libraryAuthoringMfeUrl}library/${contextKey}`;
+ return `${libraryAuthoringMfeUrl}/library/${contextKey}`;
}
/**
@@ -218,7 +218,7 @@ const SearchResult = ({ hit }) => {
diff --git a/src/search-modal/SearchUI.test.jsx b/src/search-modal/SearchUI.test.jsx
index 4fa79346f4..2a5a7a4daa 100644
--- a/src/search-modal/SearchUI.test.jsx
+++ b/src/search-modal/SearchUI.test.jsx
@@ -17,6 +17,10 @@ import {
import fetchMock from 'fetch-mock-jest';
import initializeStore from '../store';
+import { executeThunk } from '../utils';
+import { getStudioHomeApiUrl } from '../studio-home/data/api';
+import { fetchStudioHomeData } from '../studio-home/data/thunks';
+import { generateGetStudioHomeDataApiResponse } from '../studio-home/factories/mockApiResponses';
import mockResult from './__mocks__/search-result.json';
import mockEmptyResult from './__mocks__/empty-search-result.json';
import mockTagsFacetResult from './__mocks__/facet-search.json';
@@ -47,6 +51,7 @@ jest.mock('react-router-dom', () => ({
useNavigate: () => mockNavigate,
}));
+
/** @type {React.FC<{children:React.ReactNode}>} */
const Wrap = ({ children }) => (
@@ -89,6 +94,7 @@ describe('', () => {
index_name: 'studio',
api_key: 'test-key',
});
+
// The Meilisearch client-side API uses fetch, not Axios.
fetchMock.post(searchEndpoint, (_url, req) => {
const requestData = JSON.parse(req.body?.toString() ?? '');
@@ -185,7 +191,13 @@ describe('', () => {
describe('results', () => {
/** @type {import('@testing-library/react').RenderResult} */
let rendered;
- beforeEach(() => {
+ beforeEach(async () => {
+ const data = generateGetStudioHomeDataApiResponse();
+ data.redirectToLibraryAuthoringMfe = true;
+ axiosMock.onGet(getStudioHomeApiUrl()).reply(200, data);
+
+ await executeThunk(fetchStudioHomeData(), store.dispatch);
+
rendered = render();
const { getByRole } = rendered;
fireEvent.change(getByRole('searchbox'), { target: { value: 'giraffe' } });
@@ -284,6 +296,28 @@ describe('', () => {
+ '?show=block-v1%3ASampleTaxonomyOrg1%2BSTC1%2B2023_1%2Btype%40html%2Bblock%400b2d1c0722f742489602b6d8645205f4',
);
});
+
+ test('click lib component result navigates to the context', async () => {
+ const { findByRole } = rendered;
+
+ const resultItem = await findByRole('button', { name: /Library Content/ });
+
+ // Clicking the "Open in new window" button should open the result in a new window:
+ const { open, location } = window;
+ window.open = jest.fn();
+ fireEvent.click(within(resultItem).getByRole('button', { name: 'Open in new window' }));
+ expect(window.open).toHaveBeenCalledWith(
+ 'http://localhost:3001/library/lib:org1:libafter1',
+ '_blank',
+ );
+ window.open = open;
+
+ window.location = { href: '' };
+ // Clicking in the result should navigate to the result's URL:
+ fireEvent.click(resultItem);
+ expect(window.location.href = 'http://localhost:3001/library/lib:org1:libafter1');
+ window.location = location;
+ });
});
describe('filters', () => {
diff --git a/src/search-modal/__mocks__/search-result.json b/src/search-modal/__mocks__/search-result.json
index 6a4f184d71..5371f3d5c7 100644
--- a/src/search-modal/__mocks__/search-result.json
+++ b/src/search-modal/__mocks__/search-result.json
@@ -58,7 +58,7 @@
}
},
{
- "display_name": "Text1",
+ "display_name": "Library Content",
"block_id": "a1fa8bdd-dc67-4976-9bf5-0ea75a9bca3d",
"content": {
"html_content": " Test "