@@ -2,7 +2,6 @@ import type MockAdapter from 'axios-mock-adapter';
2
2
import fetchMock from 'fetch-mock-jest' ;
3
3
4
4
import { mockContentSearchConfig , mockGetBlockTypes } from '../../search-manager/data/api.mock' ;
5
- import { type CollectionHit , formatSearchHit } from '../../search-manager/data/api' ;
6
5
import {
7
6
initializeMocks ,
8
7
fireEvent ,
@@ -11,19 +10,21 @@ import {
11
10
waitFor ,
12
11
within ,
13
12
} from '../../testUtils' ;
14
- import mockResult from '../__mocks__/collection-search.json' ;
15
13
import * as api from '../data/api' ;
16
- import { mockContentLibrary } from '../data/api.mocks' ;
14
+ import { mockContentLibrary , mockGetCollectionMetadata } from '../data/api.mocks' ;
17
15
import CollectionDetails from './CollectionDetails' ;
18
16
19
17
let axiosMock : MockAdapter ;
20
18
let mockShowToast : ( message : string ) => void ;
21
19
20
+ mockGetCollectionMetadata . applyMock ( ) ;
22
21
mockContentSearchConfig . applyMock ( ) ;
23
22
mockGetBlockTypes . applyMock ( ) ;
24
23
24
+ const { collectionId } = mockGetCollectionMetadata ;
25
+ const { description : originalDescription } = mockGetCollectionMetadata . collectionData ;
26
+
25
27
const library = mockContentLibrary . libraryData ;
26
- const collectionHit = formatSearchHit ( mockResult . results [ 2 ] . hits [ 0 ] ) as CollectionHit ;
27
28
28
29
describe ( '<CollectionDetails />' , ( ) => {
29
30
beforeEach ( ( ) => {
@@ -39,12 +40,11 @@ describe('<CollectionDetails />', () => {
39
40
} ) ;
40
41
41
42
it ( 'should render Collection Details' , async ( ) => {
42
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
43
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
43
44
44
45
// Collection Description
45
- expect ( screen . getByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
46
- const { description } = collectionHit ;
47
- expect ( screen . getByText ( description ) ) . toBeInTheDocument ( ) ;
46
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
47
+ expect ( screen . getByText ( originalDescription ) ) . toBeInTheDocument ( ) ;
48
48
49
49
// Collection History
50
50
expect ( screen . getByText ( 'Collection History' ) ) . toBeInTheDocument ( ) ;
@@ -55,17 +55,12 @@ describe('<CollectionDetails />', () => {
55
55
} ) ;
56
56
57
57
it ( 'should allow modifying the description' , async ( ) => {
58
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
59
-
60
- const {
61
- description : originalDescription ,
62
- blockId,
63
- contextKey,
64
- } = collectionHit ;
58
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
59
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
65
60
66
61
expect ( screen . getByText ( originalDescription ) ) . toBeInTheDocument ( ) ;
67
62
68
- const url = api . getLibraryCollectionApiUrl ( contextKey , blockId ) ;
63
+ const url = api . getLibraryCollectionApiUrl ( library . id , collectionId ) ;
69
64
axiosMock . onPatch ( url ) . reply ( 200 ) ;
70
65
71
66
const textArea = screen . getByRole ( 'textbox' ) ;
@@ -94,17 +89,12 @@ describe('<CollectionDetails />', () => {
94
89
} ) ;
95
90
96
91
it ( 'should show error while modifing the description' , async ( ) => {
97
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
98
-
99
- const {
100
- description : originalDescription ,
101
- blockId,
102
- contextKey,
103
- } = collectionHit ;
92
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
93
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
104
94
105
95
expect ( screen . getByText ( originalDescription ) ) . toBeInTheDocument ( ) ;
106
96
107
- const url = api . getLibraryCollectionApiUrl ( contextKey , blockId ) ;
97
+ const url = api . getLibraryCollectionApiUrl ( library . id , collectionId ) ;
108
98
axiosMock . onPatch ( url ) . reply ( 500 ) ;
109
99
110
100
const textArea = screen . getByRole ( 'textbox' ) ;
@@ -124,7 +114,8 @@ describe('<CollectionDetails />', () => {
124
114
125
115
it ( 'should render Collection stats' , async ( ) => {
126
116
mockGetBlockTypes ( 'someBlocks' ) ;
127
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
117
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
118
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
128
119
129
120
expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
130
121
expect ( await screen . findByText ( 'Total' ) ) . toBeInTheDocument ( ) ;
@@ -141,15 +132,17 @@ describe('<CollectionDetails />', () => {
141
132
142
133
it ( 'should render Collection stats for empty collection' , async ( ) => {
143
134
mockGetBlockTypes ( 'noBlocks' ) ;
144
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
135
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
136
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
145
137
146
138
expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
147
139
expect ( await screen . findByText ( 'This collection is currently empty.' ) ) . toBeInTheDocument ( ) ;
148
140
} ) ;
149
141
150
142
it ( 'should render Collection stats for big collection' , async ( ) => {
151
143
mockGetBlockTypes ( 'moreBlocks' ) ;
152
- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
144
+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
145
+ expect ( await screen . findByText ( 'Description / Card Preview Text' ) ) . toBeInTheDocument ( ) ;
153
146
154
147
expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
155
148
expect ( await screen . findByText ( '36' ) ) . toBeInTheDocument ( ) ;
0 commit comments