@@ -2,7 +2,6 @@ import type MockAdapter from 'axios-mock-adapter';
22import fetchMock from 'fetch-mock-jest' ;
33
44import { mockContentSearchConfig , mockGetBlockTypes } from '../../search-manager/data/api.mock' ;
5- import { type CollectionHit , formatSearchHit } from '../../search-manager/data/api' ;
65import {
76 initializeMocks ,
87 fireEvent ,
@@ -11,19 +10,21 @@ import {
1110 waitFor ,
1211 within ,
1312} from '../../testUtils' ;
14- import mockResult from '../__mocks__/collection-search.json' ;
1513import * as api from '../data/api' ;
16- import { mockContentLibrary } from '../data/api.mocks' ;
14+ import { mockContentLibrary , mockGetCollectionMetadata } from '../data/api.mocks' ;
1715import CollectionDetails from './CollectionDetails' ;
1816
1917let axiosMock : MockAdapter ;
2018let mockShowToast : ( message : string ) => void ;
2119
20+ mockGetCollectionMetadata . applyMock ( ) ;
2221mockContentSearchConfig . applyMock ( ) ;
2322mockGetBlockTypes . applyMock ( ) ;
2423
24+ const { collectionId } = mockGetCollectionMetadata ;
25+ const { description : originalDescription } = mockGetCollectionMetadata . collectionData ;
26+
2527const library = mockContentLibrary . libraryData ;
26- const collectionHit = formatSearchHit ( mockResult . results [ 2 ] . hits [ 0 ] ) as CollectionHit ;
2728
2829describe ( '<CollectionDetails />' , ( ) => {
2930 beforeEach ( ( ) => {
@@ -39,12 +40,11 @@ describe('<CollectionDetails />', () => {
3940 } ) ;
4041
4142 it ( 'should render Collection Details' , async ( ) => {
42- render ( < CollectionDetails library = { library } collection = { collectionHit } /> ) ;
43+ render ( < CollectionDetails library = { library } collectionId = { collectionId } /> ) ;
4344
4445 // 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 ( ) ;
4848
4949 // Collection History
5050 expect ( screen . getByText ( 'Collection History' ) ) . toBeInTheDocument ( ) ;
@@ -55,17 +55,12 @@ describe('<CollectionDetails />', () => {
5555 } ) ;
5656
5757 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 ( ) ;
6560
6661 expect ( screen . getByText ( originalDescription ) ) . toBeInTheDocument ( ) ;
6762
68- const url = api . getLibraryCollectionApiUrl ( contextKey , blockId ) ;
63+ const url = api . getLibraryCollectionApiUrl ( library . id , collectionId ) ;
6964 axiosMock . onPatch ( url ) . reply ( 200 ) ;
7065
7166 const textArea = screen . getByRole ( 'textbox' ) ;
@@ -94,17 +89,12 @@ describe('<CollectionDetails />', () => {
9489 } ) ;
9590
9691 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 ( ) ;
10494
10595 expect ( screen . getByText ( originalDescription ) ) . toBeInTheDocument ( ) ;
10696
107- const url = api . getLibraryCollectionApiUrl ( contextKey , blockId ) ;
97+ const url = api . getLibraryCollectionApiUrl ( library . id , collectionId ) ;
10898 axiosMock . onPatch ( url ) . reply ( 500 ) ;
10999
110100 const textArea = screen . getByRole ( 'textbox' ) ;
@@ -124,7 +114,8 @@ describe('<CollectionDetails />', () => {
124114
125115 it ( 'should render Collection stats' , async ( ) => {
126116 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 ( ) ;
128119
129120 expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
130121 expect ( await screen . findByText ( 'Total' ) ) . toBeInTheDocument ( ) ;
@@ -141,15 +132,17 @@ describe('<CollectionDetails />', () => {
141132
142133 it ( 'should render Collection stats for empty collection' , async ( ) => {
143134 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 ( ) ;
145137
146138 expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
147139 expect ( await screen . findByText ( 'This collection is currently empty.' ) ) . toBeInTheDocument ( ) ;
148140 } ) ;
149141
150142 it ( 'should render Collection stats for big collection' , async ( ) => {
151143 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 ( ) ;
153146
154147 expect ( screen . getByText ( 'Collection Stats' ) ) . toBeInTheDocument ( ) ;
155148 expect ( await screen . findByText ( '36' ) ) . toBeInTheDocument ( ) ;
0 commit comments