@@ -16,7 +16,7 @@ limitations under the License.
1616
1717import React from "react" ;
1818import { fireEvent , render , screen } from "@testing-library/react" ;
19- import { EventType , MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
19+ import { EventType , getHttpUriForMxc , MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
2020import fetchMock from "fetch-mock-jest" ;
2121import encrypt from "matrix-encrypt-attachment" ;
2222import { mocked } from "jest-mock" ;
@@ -171,4 +171,39 @@ describe("<MImageBody/>", () => {
171171 expect ( screen . getByRole ( "progressbar" ) ) . toBeInTheDocument ( ) ;
172172 } ) ;
173173 } ) ;
174+
175+ it ( "should fall back to /download/ if /thumbnail/ fails" , async ( ) => {
176+ const thumbUrl = "https://server/_matrix/media/r0/thumbnail/server/image?width=800&height=600&method=scale" ;
177+ const downloadUrl = "https://server/_matrix/media/r0/download/server/image" ;
178+ // eslint-disable-next-line no-restricted-properties
179+ cli . mxcUrlToHttp . mockImplementation (
180+ ( mxcUrl : string , width ?: number , height ?: number , resizeMethod ?: string , allowDirectLinks ?: boolean ) => {
181+ return getHttpUriForMxc ( "https://server" , mxcUrl , width , height , resizeMethod , allowDirectLinks ) ;
182+ } ,
183+ ) ;
184+
185+ const event = new MatrixEvent ( {
186+ room_id : "!room:server" ,
187+ sender : userId ,
188+ type : EventType . RoomMessage ,
189+ content : {
190+ body : "alt for a test image" ,
191+ info : {
192+ w : 40 ,
193+ h : 50 ,
194+ } ,
195+ url : "mxc://server/image" ,
196+ } ,
197+ } ) ;
198+
199+ const { container } = render (
200+ < MImageBody { ...props } mxEvent = { event } mediaEventHelper = { new MediaEventHelper ( event ) } /> ,
201+ ) ;
202+
203+ const img = container . querySelector ( ".mx_MImageBody_thumbnail" ) ! ;
204+ expect ( img ) . toHaveProperty ( "src" , thumbUrl ) ;
205+
206+ fireEvent . error ( img ) ;
207+ expect ( img ) . toHaveProperty ( "src" , downloadUrl ) ;
208+ } ) ;
174209} ) ;
0 commit comments