Skip to content

Commit 57e5657

Browse files
committed
fixup! feat: improve collection sidebar
1 parent a1e2730 commit 57e5657

File tree

1 file changed

+7
-58
lines changed

1 file changed

+7
-58
lines changed

src/library-authoring/collections/CollectionDetails.test.tsx

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,71 +14,20 @@ import {
1414
} from '../../testUtils';
1515
import mockResult from '../__mocks__/collection-search.json';
1616
import { mockContentLibrary } from '../data/api.mocks';
17-
import * as api from '../data/api';
1817
import CollectionDetails from './CollectionDetails';
1918

2019
const searchEndpoint = 'http://mock.meilisearch.local/multi-search';
21-
const mockCollection = {
22-
collectionId: mockResult.results[2].hits[0].block_id,
23-
collectionNoComponents: 'collection-no-components',
24-
collectionMultipleComponents: 'collection-multiple-components',
25-
title: mockResult.results[2].hits[0].display_name,
26-
description: mockResult.results[2].hits[0].description,
27-
};
2820

2921
let axiosMock: MockAdapter;
30-
let mockShowToast: (message: string) => void;
22+
// let mockShowToast: (message: string) => void;
3123

3224
mockContentSearchConfig.applyMock();
3325

3426
describe('<CollectionDetails />', () => {
3527
beforeEach(() => {
3628
const mocks = initializeMocks();
3729
axiosMock = mocks.axiosMock;
38-
mockShowToast = mocks.mockShowToast;
39-
return;
40-
41-
// The Meilisearch client-side API uses fetch, not Axios.
42-
fetchMock.post(searchEndpoint, (_url, req) => {
43-
const requestData = JSON.parse(req.body?.toString() ?? '');
44-
const query = requestData?.queries[0]?.q ?? '';
45-
const mockResultCopy = cloneDeep(mockResult);
46-
// We have to replace the query (search keywords) in the mock results with the actual query,
47-
// because otherwise Instantsearch will update the UI and change the query,
48-
// leading to unexpected results in the test cases.
49-
mockResultCopy.results[0].query = query;
50-
mockResultCopy.results[1].query = query;
51-
mockResultCopy.results[2].query = query;
52-
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
53-
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
54-
mockResultCopy.results[0]?.hits.forEach((hit) => { hit._formatted = { ...hit }; });
55-
const collectionQueryId = requestData?.queries[2]?.filter[2]?.split('block_id = "')[1].split('"')[0];
56-
mockResultCopy.results[0].description = requestData?.queries[2]?.filter[2];
57-
switch (collectionQueryId) {
58-
case mockCollection.collectionNoComponents:
59-
mockResultCopy.results[1].facetDistribution.block_type = {};
60-
break;
61-
case mockCollection.collectionMultipleComponents:
62-
mockResultCopy.results[1].facetDistribution.block_type = {
63-
annotatable: 1,
64-
chapter: 2,
65-
discussion: 3,
66-
drag_and_drop_v2: 4,
67-
html: 5,
68-
library_content: 6,
69-
openassessment: 7,
70-
problem: 8,
71-
sequential: 9,
72-
vertical: 10,
73-
video: 11,
74-
choiceresponse: 12,
75-
};
76-
break;
77-
default:
78-
break;
79-
}
80-
return mockResultCopy;
81-
});
30+
// mockShowToast = mocks.mockShowToast;
8231
});
8332

8433
afterEach(() => {
@@ -87,8 +36,7 @@ describe('<CollectionDetails />', () => {
8736
fetchMock.mockReset();
8837
});
8938

90-
const renderCollectionDetails = async (collectionId?: string) => {
91-
const colId = collectionId || mockCollection.collectionId;
39+
const renderCollectionDetails = async () => {
9240
const collectionData: CollectionHit = formatSearchHit(mockResult.results[2].hits[0]) as CollectionHit;
9341
const library = mockContentLibrary.libraryData;
9442

@@ -107,7 +55,8 @@ describe('<CollectionDetails />', () => {
10755

10856
// Collection Description
10957
expect(screen.getByText('Description / Card Preview Text')).toBeInTheDocument();
110-
expect(screen.getByText(mockCollection.description)).toBeInTheDocument();
58+
const { description } = mockResult.results[2].hits[0];
59+
expect(screen.getByText(description)).toBeInTheDocument();
11160

11261
// Collection History
11362
expect(screen.getByText('Collection History')).toBeInTheDocument();
@@ -138,7 +87,7 @@ describe('<CollectionDetails />', () => {
13887
const mockResultCopy = cloneDeep(mockResult);
13988
mockResultCopy.results[1].facetDistribution.block_type = {};
14089
mockSearchResult(mockResultCopy);
141-
await renderCollectionDetails(mockCollection.collectionNoComponents);
90+
await renderCollectionDetails();
14291

14392
expect(screen.getByText('Collection Stats')).toBeInTheDocument();
14493
expect(await screen.findByText('This collection is currently empty.')).toBeInTheDocument();
@@ -161,7 +110,7 @@ describe('<CollectionDetails />', () => {
161110
choiceresponse: 12,
162111
};
163112
mockSearchResult(mockResultCopy);
164-
await renderCollectionDetails(mockCollection.collectionMultipleComponents);
113+
await renderCollectionDetails();
165114

166115
expect(screen.getByText('Collection Stats')).toBeInTheDocument();
167116
expect(await screen.findByText('78')).toBeInTheDocument();

0 commit comments

Comments
 (0)