@@ -10,11 +10,13 @@ import React from "react";
10
10
import { mocked } from "jest-mock" ;
11
11
import { render , fireEvent , waitFor } from "jest-matrix-react" ;
12
12
import fetchMock from "fetch-mock-jest" ;
13
+ import { MatrixEvent } from "matrix-js-sdk/src/matrix" ;
13
14
14
15
import ImageView from "../../../../../src/components/views/elements/ImageView" ;
15
16
import { FileDownloader } from "../../../../../src/utils/FileDownloader" ;
16
17
import Modal from "../../../../../src/Modal" ;
17
18
import ErrorDialog from "../../../../../src/components/views/dialogs/ErrorDialog" ;
19
+ import { stubClient } from "../../../../test-utils" ;
18
20
19
21
jest . mock ( "../../../../../src/utils/FileDownloader" ) ;
20
22
@@ -44,6 +46,39 @@ describe("<ImageView />", () => {
44
46
expect ( fetchMock ) . toHaveFetched ( "https://example.com/image.png" ) ;
45
47
} ) ;
46
48
49
+ it ( "should use event as download source if given" , async ( ) => {
50
+ stubClient ( ) ;
51
+
52
+ const event = new MatrixEvent ( {
53
+ event_id : "$eventId" ,
54
+ type : "m.image" ,
55
+ content : {
56
+ body : "fromEvent.png" ,
57
+ url : "mxc://test.dummy/fromEvent.png" ,
58
+ file_name : "filename.png" ,
59
+ } ,
60
+ origin_server_ts : new Date ( 2000 , 0 , 1 , 0 , 0 , 0 , 0 ) . getTime ( ) ,
61
+ } ) ;
62
+
63
+ fetchMock . get ( "http://this.is.a.url/test.dummy/fromEvent.png" , "TESTFILE" ) ;
64
+ const { getByRole } = render (
65
+ < ImageView
66
+ src = "https://test.dummy/fromSrc.png"
67
+ name = "fromName.png"
68
+ onFinished = { jest . fn ( ) }
69
+ mxEvent = { event }
70
+ /> ,
71
+ ) ;
72
+ fireEvent . click ( getByRole ( "button" , { name : "Download" } ) ) ;
73
+ await waitFor ( ( ) =>
74
+ expect ( mocked ( FileDownloader ) . mock . instances [ 0 ] . download ) . toHaveBeenCalledWith ( {
75
+ blob : expect . anything ( ) ,
76
+ name : "fromEvent.png" ,
77
+ } ) ,
78
+ ) ;
79
+ expect ( fetchMock ) . toHaveFetched ( "http://this.is.a.url/test.dummy/fromEvent.png" ) ;
80
+ } ) ;
81
+
47
82
it ( "should start download on Ctrl+S" , async ( ) => {
48
83
fetchMock . get ( "https://example.com/image.png" , "TESTFILE" ) ;
49
84
0 commit comments