@@ -15,10 +15,12 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from "react" ;
18
- import { fireEvent , render } from "@testing-library/react" ;
18
+ import { fireEvent , render , waitFor } from "@testing-library/react" ;
19
19
import userEvent from "@testing-library/user-event" ;
20
+ import { CryptoApi } from "matrix-js-sdk/src/matrix" ;
20
21
21
22
import ImportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ImportE2eKeysDialog" ;
23
+ import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption" ;
22
24
import { createTestClient } from "../../../../test-utils" ;
23
25
24
26
describe ( "ImportE2eKeysDialog" , ( ) => {
@@ -64,4 +66,30 @@ describe("ImportE2eKeysDialog", () => {
64
66
await userEvent . paste ( "passphrase" ) ;
65
67
expect ( container . querySelector ( "[type=submit]" ) ! ) . toBeEnabled ( ) ;
66
68
} ) ;
69
+
70
+ it ( "should import exported keys on submit" , async ( ) => {
71
+ const cli = createTestClient ( ) ;
72
+ const onFinished = jest . fn ( ) ;
73
+ const file = new File ( [ "test" ] , "file.txt" , { type : "text/plain" } ) ;
74
+ const importRoomKeys = jest . fn ( ) ;
75
+ cli . getCrypto = ( ) => {
76
+ return {
77
+ importRoomKeys,
78
+ } as unknown as CryptoApi ;
79
+ } ;
80
+
81
+ // Mock the result of decrypting the sessions, to avoid needing to
82
+ // create encrypted input data.
83
+ jest . spyOn ( MegolmExportEncryption , "decryptMegolmKeyFile" ) . mockResolvedValue ( "[]" ) ;
84
+
85
+ const { container } = render ( < ImportE2eKeysDialog matrixClient = { cli } onFinished = { onFinished } /> ) ;
86
+ fireEvent . change ( container . querySelector ( "[type=file]" ) ! , {
87
+ target : { files : [ file ] } ,
88
+ } ) ;
89
+ await userEvent . click ( container . querySelector ( "[type=password]" ) ! ) ;
90
+ await userEvent . paste ( "passphrase" ) ;
91
+ fireEvent . click ( container . querySelector ( "[type=submit]" ) ! ) ;
92
+
93
+ await waitFor ( ( ) => expect ( importRoomKeys ) . toHaveBeenCalled ( ) ) ;
94
+ } ) ;
67
95
} ) ;
0 commit comments