@@ -10,6 +10,7 @@ import { test, expect } from "../../element-web-test";
10
10
import { isDendrite } from "../../plugins/homeserver/dendrite" ;
11
11
import { completeCreateSecretStorageDialog , createBot , logIntoElement } from "./utils.ts" ;
12
12
import { type Client } from "../../pages/client.ts" ;
13
+ import { type ElementAppPage } from "../../pages/ElementAppPage.ts" ;
13
14
14
15
const NAME = "Alice" ;
15
16
@@ -49,13 +50,7 @@ test.describe("Dehydration", () => {
49
50
50
51
await completeCreateSecretStorageDialog ( page ) ;
51
52
52
- // Open the settings again
53
- await app . settings . openUserSettings ( "Security & Privacy" ) ;
54
-
55
- // The Security tab should indicate that there is a dehydrated device present
56
- await expect ( securityTab . getByText ( "Offline device enabled" ) ) . toBeVisible ( ) ;
57
-
58
- await app . settings . closeDialog ( ) ;
53
+ await expectDehydratedDeviceEnabled ( app ) ;
59
54
60
55
// the dehydrated device gets created with the name "Dehydrated
61
56
// device". We want to make sure that it is not visible as a normal
@@ -64,6 +59,33 @@ test.describe("Dehydration", () => {
64
59
await expect ( sessionsTab . getByText ( "Dehydrated device" ) ) . not . toBeVisible ( ) ;
65
60
} ) ;
66
61
62
+ test ( "'Set up recovery' creates dehydrated device" , async ( { app, credentials, page } ) => {
63
+ await logIntoElement ( page , credentials ) ;
64
+
65
+ const settingsDialogLocator = await app . settings . openUserSettings ( "Encryption" ) ;
66
+ await settingsDialogLocator . getByRole ( "button" , { name : "Set up recovery" } ) . click ( ) ;
67
+
68
+ // First it displays an informative panel about the recovery key
69
+ await expect ( settingsDialogLocator . getByRole ( "heading" , { name : "Set up recovery" } ) ) . toBeVisible ( ) ;
70
+ await settingsDialogLocator . getByRole ( "button" , { name : "Continue" } ) . click ( ) ;
71
+
72
+ // Next, it displays the new recovery key. We click on the copy button.
73
+ await expect ( settingsDialogLocator . getByText ( "Save your recovery key somewhere safe" ) ) . toBeVisible ( ) ;
74
+ await settingsDialogLocator . getByRole ( "button" , { name : "Copy" } ) . click ( ) ;
75
+ const recoveryKey = await app . getClipboard ( ) ;
76
+ await settingsDialogLocator . getByRole ( "button" , { name : "Continue" } ) . click ( ) ;
77
+
78
+ await expect (
79
+ settingsDialogLocator . getByText ( "Enter your recovery key to confirm" , { exact : true } ) ,
80
+ ) . toBeVisible ( ) ;
81
+ await settingsDialogLocator . getByRole ( "textbox" ) . fill ( recoveryKey ) ;
82
+ await settingsDialogLocator . getByRole ( "button" , { name : "Finish set up" } ) . click ( ) ;
83
+
84
+ await app . settings . closeDialog ( ) ;
85
+
86
+ await expectDehydratedDeviceEnabled ( app ) ;
87
+ } ) ;
88
+
67
89
test ( "Reset recovery key during login re-creates dehydrated device" , async ( {
68
90
page,
69
91
homeserver,
@@ -109,3 +131,16 @@ async function getDehydratedDeviceIds(client: Client): Promise<string[]> {
109
131
) ;
110
132
} ) ;
111
133
}
134
+
135
+ /** Wait for our user to have a dehydrated device */
136
+ async function expectDehydratedDeviceEnabled ( app : ElementAppPage ) : Promise < void > {
137
+ // It might be nice to do this via the UI, but currently this info is not exposed via the UI.
138
+ //
139
+ // Note we might have to wait for the device list to be refreshed, so we wrap in `expect.poll`.
140
+ await expect
141
+ . poll ( async ( ) => {
142
+ const dehydratedDeviceIds = await getDehydratedDeviceIds ( app . client ) ;
143
+ return dehydratedDeviceIds . length ;
144
+ } )
145
+ . toEqual ( 1 ) ;
146
+ }
0 commit comments