@@ -45,16 +45,14 @@ jest.mock( '../../lock-unlock', () => ( {
4545
4646function createRegistry ( {
4747 getEditedEntityRecord = ( ) => false ,
48- getEntityRecord = ( ) => undefined ,
49- resolveGetEntityRecord = getEntityRecord ,
48+ resolveGetEntityRecord = ( ) => undefined ,
5049} = { } ) {
5150 const actions = {
5251 invalidateResolution : jest . fn ( ) ,
5352 } ;
5453 return {
5554 select : jest . fn ( ( ) => ( {
5655 getEditedEntityRecord,
57- getEntityRecord,
5856 } ) ) ,
5957 dispatch : jest . fn ( ( ) => actions ) ,
6058 resolveSelect : jest . fn ( ( ) => ( {
@@ -169,25 +167,24 @@ describe( 'useOpenImageMediaEditorModal', () => {
169167 caption : 'Original caption' ,
170168 } ,
171169 registryOptions : {
172- getEntityRecord : ( ) => originalAttachment ,
173- resolveGetEntityRecord : ( kind , name , attachmentId , query ) =>
174- query ?. context === 'edit'
175- ? updatedAttachment
176- : originalAttachment ,
170+ getEditedEntityRecord : ( ) => originalAttachment ,
171+ resolveGetEntityRecord : ( ) => updatedAttachment ,
177172 } ,
178173 } ) ;
179174
180175 expect ( setAttributes ) . toHaveBeenCalledWith ( {
181176 alt : 'Updated alt' ,
182177 caption : 'Updated caption' ,
183178 } ) ;
184- expect ( registry . actions . invalidateResolution ) . toHaveBeenCalledWith (
185- 'getEntityRecord' ,
186- [ 'postType' , 'attachment' , 1 ]
179+ // A single, query-less resolution is invalidated: the hook reads,
180+ // resolves, and invalidates the attachment through the entity's default
181+ // (edit) context rather than an explicitly-keyed query.
182+ expect ( registry . actions . invalidateResolution ) . toHaveBeenCalledTimes (
183+ 1
187184 ) ;
188185 expect ( registry . actions . invalidateResolution ) . toHaveBeenCalledWith (
189186 'getEntityRecord' ,
190- [ 'postType' , 'attachment' , 1 , { context : 'edit' } ]
187+ [ 'postType' , 'attachment' , 1 ]
191188 ) ;
192189 } ) ;
193190
@@ -220,8 +217,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
220217 1 ,
221218 'postType' ,
222219 'attachment' ,
223- 1 ,
224- { context : 'edit' }
220+ 1
225221 ) ;
226222 expect ( openMediaEditorModal ) . toHaveBeenCalledWith ( {
227223 id : 1 ,
@@ -263,8 +259,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
263259 1 ,
264260 'postType' ,
265261 'attachment' ,
266- 1 ,
267- { context : 'edit' }
262+ 1
268263 ) ;
269264 expect ( openMediaEditorModal ) . toHaveBeenCalledWith ( {
270265 id : 1 ,
@@ -299,7 +294,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
299294 caption : undefined ,
300295 } ,
301296 registryOptions : {
302- getEntityRecord : ( ) => ( {
297+ getEditedEntityRecord : ( ) => ( {
303298 id : 1 ,
304299 alt_text : '' ,
305300 caption : {
@@ -314,8 +309,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
314309 1 ,
315310 'postType' ,
316311 'attachment' ,
317- 1 ,
318- { context : 'edit' }
312+ 1
319313 ) ;
320314 expect ( setAttributes ) . toHaveBeenCalledWith ( {
321315 caption : 'Updated attachment caption' ,
@@ -341,7 +335,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
341335 caption : '' ,
342336 } ,
343337 registryOptions : {
344- getEntityRecord : ( kind , name , attachmentId ) =>
338+ getEditedEntityRecord : ( kind , name , attachmentId ) =>
345339 attachmentId === 1 ? originalAttachment : undefined ,
346340 resolveGetEntityRecord : ( kind , name , attachmentId ) =>
347341 attachmentId === 2 ? updatedAttachment : undefined ,
@@ -371,7 +365,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
371365 } ;
372366 const deferredAttachment = createDeferred ( ) ;
373367 const registry = createRegistry ( {
374- getEntityRecord : ( kind , name , attachmentId ) =>
368+ getEditedEntityRecord : ( kind , name , attachmentId ) =>
375369 attachmentId === 1 ? originalAttachment : undefined ,
376370 resolveGetEntityRecord : ( kind , name , attachmentId ) =>
377371 attachmentId === 2 ? deferredAttachment . promise : undefined ,
@@ -437,7 +431,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
437431 caption : '' ,
438432 } ,
439433 registryOptions : {
440- getEntityRecord : ( kind , name , attachmentId ) =>
434+ getEditedEntityRecord : ( kind , name , attachmentId ) =>
441435 attachmentId === 1
442436 ? originalAttachment
443437 : {
@@ -469,7 +463,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
469463 caption : undefined ,
470464 } ,
471465 registryOptions : {
472- getEntityRecord : ( ) => ( {
466+ getEditedEntityRecord : ( ) => ( {
473467 id : 1 ,
474468 alt_text : '' ,
475469 caption : { raw : 'Existing caption' } ,
@@ -526,7 +520,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
526520 caption : undefined ,
527521 } ,
528522 registryOptions : {
529- getEntityRecord : ( ) => ( {
523+ getEditedEntityRecord : ( ) => ( {
530524 id : 1 ,
531525 alt_text : 'Original alt' ,
532526 caption : { raw : 'Existing caption' } ,
@@ -556,7 +550,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
556550 caption : { toString : ( ) => '' } ,
557551 } ,
558552 registryOptions : {
559- getEntityRecord : ( ) => ( {
553+ getEditedEntityRecord : ( ) => ( {
560554 id : 1 ,
561555 alt_text : 'Original alt' ,
562556 caption : { raw : 'Existing caption' } ,
@@ -603,7 +597,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
603597 } ;
604598 const deferredAttachment = createDeferred ( ) ;
605599 const registry = createRegistry ( {
606- getEntityRecord : ( ) => ( {
600+ getEditedEntityRecord : ( ) => ( {
607601 id : 1 ,
608602 alt_text : '' ,
609603 caption : { raw : '' } ,
0 commit comments