@@ -10,12 +10,60 @@ import { resolveMarkdownMediaPreview, wrapExpandedImageIndex } from "./ExpandedI
1010
1111afterEach ( ( ) => document . body . replaceChildren ( ) ) ;
1212
13- it . each ( [ true , false ] ) (
14- "keeps linked private images authenticated when navigating from a linked=%s image" ,
15- async ( linked ) => {
13+ it ( "keeps the selected preview and other images available when a neighboring asset fails" , async ( ) => {
14+ const base =
15+ "https://dev.azure.com/org/project/_apis/git/repositories/repo/pullRequests/42/attachments" ;
16+ const environmentId = EnvironmentId . make ( "remote" ) ;
17+ const selected = { src : "https://remote.example/selected.gif" , name : "Selected" } ;
18+ const failed = {
19+ src : "https://remote.example/thumbnail.gif" ,
20+ name : "Unavailable target" ,
21+ originalUrl : `${ base } /failed.gif` ,
22+ } ;
23+ const available = {
24+ src : `${ base } /available.gif` ,
25+ name : "Available" ,
26+ originalUrl : `${ base } /available.gif` ,
27+ } ;
28+ const createAssetUrl = vi . fn < Parameters < typeof resolveMarkdownMediaPreview > [ 0 ] [ "createAssetUrl" ] > (
29+ async ( { input } ) => {
30+ if ( "url" in input . resource && input . resource . url . endsWith ( "failed.gif" ) )
31+ throw new Error ( "Asset unavailable" ) ;
32+ return AsyncResult . success ( {
33+ relativeUrl : "/api/assets/signed/available.gif" ,
34+ expiresAt : 2000 ,
35+ } ) ;
36+ } ,
37+ ) ;
38+ const resolved = await resolveMarkdownImageGallery (
39+ { images : [ selected , failed , available ] , index : 0 } ,
40+ {
41+ cwd : "/repo" ,
42+ environmentId,
43+ pullRequestMedia : true ,
44+ httpBaseUrl : "https://remote.example" ,
45+ createAssetUrl,
46+ } ,
47+ ) ;
48+ expect ( resolved . index ) . toBe ( 0 ) ;
49+ expect ( resolved . images [ 0 ] ) . toBe ( selected ) ;
50+ expect ( resolved . images [ 1 ] ) . toBe ( failed ) ;
51+ expect ( resolved . images [ 2 ] ?. src ) . toBe ( "https://remote.example/api/assets/signed/available.gif" ) ;
52+ expect ( createAssetUrl ) . toHaveBeenCalledTimes ( 2 ) ;
53+ } ) ;
54+
55+ it . each ( [
56+ { linked : true , protocolRelative : false } ,
57+ { linked : false , protocolRelative : false } ,
58+ { linked : true , protocolRelative : true } ,
59+ ] ) (
60+ "keeps private gallery images authenticated ($linked, $protocolRelative)" ,
61+ async ( { linked, protocolRelative } ) => {
1662 const base =
1763 "https://dev.azure.com/org/project/_apis/git/repositories/repo/pullRequests/42/attachments" ;
18- const urls = [ `${ base } /first.gif#preview` , `${ base } /second.gif#preview` ] ;
64+ const urls = [ `${ base } /first.gif#preview` , `${ base } /second.gif#preview` ] . map ( ( url ) =>
65+ protocolRelative ? url . replace ( "https:" , "" ) : url ,
66+ ) ;
1967 const container = document . createElement ( "div" ) ;
2068 container . setAttribute ( "data-image-gallery" , "" ) ;
2169 document . body . append ( container ) ;
@@ -64,7 +112,10 @@ it.each([true, false])(
64112 url : `${ base } /second.gif` ,
65113 } ,
66114 } ) ;
67- expect ( gallery . images [ gallery . index ] ) . toBe ( selected ) ;
115+ if ( ! protocolRelative ) expect ( gallery . images [ gallery . index ] ) . toBe ( selected ) ;
116+ expect ( gallery . images [ gallery . index ] ?. src ) . toBe (
117+ "https://remote.example/api/assets/signed/first.gif#preview" ,
118+ ) ;
68119 expect ( createAssetUrl ) . toHaveBeenCalledTimes ( 2 ) ;
69120 } ,
70121) ;
0 commit comments