@@ -14,6 +14,8 @@ import { mocked } from "jest-mock";
1414import { ChangeRecoveryKey } from "../../../../../../src/components/views/settings/encryption/ChangeRecoveryKey" ;
1515import { createTestClient , withClientContextRenderOptions } from "../../../../../test-utils" ;
1616import { copyPlaintext } from "../../../../../../src/utils/strings" ;
17+ import Modal from "../../../../../../src/Modal" ;
18+ import ErrorDialog from "../../../../../../src/components/views/dialogs/ErrorDialog" ;
1719
1820jest . mock ( "../../../../../../src/utils/strings" , ( ) => ( {
1921 copyPlaintext : jest . fn ( ) ,
@@ -120,22 +122,33 @@ describe("<ChangeRecoveryKey />", () => {
120122 mocked ( matrixClient . getCrypto ( ) ! ) . bootstrapSecretStorage . mockRejectedValue ( new Error ( "can't bootstrap" ) ) ;
121123
122124 const user = userEvent . setup ( ) ;
123- renderComponent ( false ) ;
125+ const { getByRole , getByText , getByTitle } = renderComponent ( false ) ;
124126
125127 // Display the recovery key to save
126- await waitFor ( ( ) => user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ) ;
128+ await waitFor ( ( ) => user . click ( getByRole ( "button" , { name : "Continue" } ) ) ) ;
127129 // Display the form to confirm the recovery key
128- await waitFor ( ( ) => user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ) ;
130+ await waitFor ( ( ) => user . click ( getByRole ( "button" , { name : "Continue" } ) ) ) ;
129131
130- await waitFor ( ( ) => expect ( screen . getByText ( "Enter your recovery key to confirm" ) ) . toBeInTheDocument ( ) ) ;
132+ await waitFor ( ( ) => expect ( getByText ( "Enter your recovery key to confirm" ) ) . toBeInTheDocument ( ) ) ;
131133
132- const finishButton = screen . getByRole ( "button" , { name : "Finish set up" } ) ;
133- const input = screen . getByTitle ( "Enter recovery key" ) ;
134+ const finishButton = getByRole ( "button" , { name : "Finish set up" } ) ;
135+ const input = getByTitle ( "Enter recovery key" ) ;
134136 await userEvent . type ( input , "encoded private key" ) ;
137+
138+ await waitFor ( ( ) => {
139+ expect ( finishButton ) . not . toBeDisabled ( ) ;
140+ } ) ;
141+
142+ jest . spyOn ( Modal , "createDialog" ) ;
143+
135144 await user . click ( finishButton ) ;
136145
137- await screen . findByText ( "Failed to set up secret storage" ) ;
138- await screen . findByText ( "Error: can't bootstrap" ) ;
146+ expect ( Modal . createDialog ) . toHaveBeenCalledWith ( ErrorDialog , {
147+ title : "Failed to set up secret storage" ,
148+ description : "Error: can't bootstrap" ,
149+ } ) ;
150+ await waitFor ( ( ) => user . click ( getByRole ( "button" , { name : "OK" } ) ) ) ;
151+
139152 expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
140153 "Failed to set up secret storage:" ,
141154 new Error ( "can't bootstrap" ) ,
@@ -149,22 +162,25 @@ describe("<ChangeRecoveryKey />", () => {
149162 } ) ;
150163
151164 const user = userEvent . setup ( ) ;
152- renderComponent ( false ) ;
165+ const { getByRole , getByText , getByTitle } = renderComponent ( false ) ;
153166
154167 // Display the recovery key to save
155- await waitFor ( ( ) => user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ) ;
168+ await waitFor ( ( ) => user . click ( getByRole ( "button" , { name : "Continue" } ) ) ) ;
156169 // Display the form to confirm the recovery key
157- await waitFor ( ( ) => user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ) ;
170+ await waitFor ( ( ) => user . click ( getByRole ( "button" , { name : "Continue" } ) ) ) ;
158171
159- await waitFor ( ( ) => expect ( screen . getByText ( "Enter your recovery key to confirm" ) ) . toBeInTheDocument ( ) ) ;
172+ await waitFor ( ( ) => expect ( getByText ( "Enter your recovery key to confirm" ) ) . toBeInTheDocument ( ) ) ;
160173
161- const finishButton = screen . getByRole ( "button" , { name : "Finish set up" } ) ;
162- const input = screen . getByTitle ( "Enter recovery key" ) ;
174+ const finishButton = getByRole ( "button" , { name : "Finish set up" } ) ;
175+ const input = getByTitle ( "Enter recovery key" ) ;
163176 await userEvent . type ( input , "encoded private key" ) ;
177+
178+ await waitFor ( ( ) => {
179+ expect ( finishButton . getAttribute ( "aria-disabled" ) ) . not . toEqual ( "true" ) ;
180+ } ) ;
181+
164182 await user . click ( finishButton ) ;
165- await user . click ( finishButton ) ;
166- await user . click ( finishButton ) ;
167- expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
183+ await waitFor ( ( ) => expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ) ;
168184 } ) ;
169185 } ) ;
170186
0 commit comments