@@ -14,71 +14,20 @@ import {
14
14
} from '../../testUtils' ;
15
15
import mockResult from '../__mocks__/collection-search.json' ;
16
16
import { mockContentLibrary } from '../data/api.mocks' ;
17
- import * as api from '../data/api' ;
18
17
import CollectionDetails from './CollectionDetails' ;
19
18
20
19
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
- } ;
28
20
29
21
let axiosMock : MockAdapter ;
30
- let mockShowToast : ( message : string ) => void ;
22
+ // let mockShowToast: (message: string) => void;
31
23
32
24
mockContentSearchConfig . applyMock ( ) ;
33
25
34
26
describe ( '<CollectionDetails />' , ( ) => {
35
27
beforeEach ( ( ) => {
36
28
const mocks = initializeMocks ( ) ;
37
29
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;
82
31
} ) ;
83
32
84
33
afterEach ( ( ) => {
@@ -87,8 +36,7 @@ describe('<CollectionDetails />', () => {
87
36
fetchMock . mockReset ( ) ;
88
37
} ) ;
89
38
90
- const renderCollectionDetails = async ( collectionId ?: string ) => {
91
- const colId = collectionId || mockCollection . collectionId ;
39
+ const renderCollectionDetails = async ( ) => {
92
40
const collectionData : CollectionHit = formatSearchHit ( mockResult . results [ 2 ] . hits [ 0 ] ) as CollectionHit ;
93
41
const library = mockContentLibrary . libraryData ;
94
42
@@ -107,7 +55,8 @@ describe('<CollectionDetails />', () => {
107
55
108
56
// Collection Description
109
57
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 ( ) ;
111
60
112
61
// Collection History
113
62
expect ( screen . getByText ( 'Collection History' ) ) . toBeInTheDocument ( ) ;
@@ -138,7 +87,7 @@ describe('<CollectionDetails />', () => {
138
87
const mockResultCopy = cloneDeep ( mockResult ) ;
139
88
mockResultCopy . results [ 1 ] . facetDistribution . block_type = { } ;
140
89
mockSearchResult ( mockResultCopy ) ;
141
- await renderCollectionDetails ( mockCollection . collectionNoComponents ) ;
90
+ await renderCollectionDetails ( ) ;
142
91
143
92
expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
144
93
expect ( await screen . findByText ( 'This collection is currently empty.' ) ) . toBeInTheDocument ( ) ;
@@ -161,7 +110,7 @@ describe('<CollectionDetails />', () => {
161
110
choiceresponse : 12 ,
162
111
} ;
163
112
mockSearchResult ( mockResultCopy ) ;
164
- await renderCollectionDetails ( mockCollection . collectionMultipleComponents ) ;
113
+ await renderCollectionDetails ( ) ;
165
114
166
115
expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
167
116
expect ( await screen . findByText ( '78' ) ) . toBeInTheDocument ( ) ;
0 commit comments