@@ -19,6 +19,7 @@ limitations under the License.
19
19
/// <reference types='cypress' />
20
20
21
21
import { login , logout , register } from "./actions/auth" ;
22
+ import { advanceClock , clearIDBStorage , exit , idle , reload , wait } from "./actions/browser" ;
22
23
import {
23
24
acceptCrossSigningRequest ,
24
25
enableDehydratedDevice ,
@@ -35,6 +36,12 @@ import {
35
36
inviteUser ,
36
37
openRoom ,
37
38
} from "./actions/room" ;
39
+ import {
40
+ sendMessage ,
41
+ verifyLastMessageIsTrusted ,
42
+ verifyLastMessageIsUTD ,
43
+ verifyMessageInTimeline ,
44
+ } from "./actions/timeline" ;
38
45
39
46
type JSONValue =
40
47
| string
@@ -76,7 +83,13 @@ function recurse() {
76
83
const data : JSONValue = resp . body . data ;
77
84
const action : string = resp . body . action ;
78
85
cy . log ( 'running action' , action , JSON . stringify ( data ) ) ;
79
- const result = runAction ( action , data ) ;
86
+ let result ;
87
+ try {
88
+ result = runAction ( action , data ) ;
89
+ } catch ( e ) {
90
+ // Don't keep running if we encounter an error!
91
+ return ;
92
+ }
80
93
if ( result ) {
81
94
sendResponse ( result ) ;
82
95
}
@@ -124,64 +137,34 @@ function runAction(action: string, data: JSONValue): string | undefined {
124
137
case "invite_user" :
125
138
return inviteUser ( data ) ;
126
139
127
- case 'idle' :
128
- cy . wait ( 5000 ) ;
129
- break ;
140
+ // Timeline
130
141
case 'send_message' :
131
- cy . get ( '.mx_SendMessageComposer div[contenteditable=true]' )
132
- . click ( )
133
- . type ( data [ 'message' ] )
134
- . type ( "{enter}" ) ;
135
- //cy.contains(data['message']).closest('mx_EventTile').should('have.class', 'mx_EventTile_receiptSent');
136
- return "message_sent" ;
142
+ return sendMessage ( data ) ;
137
143
case "verify_message_in_timeline" :
138
- cy . contains ( data [ "message" ] ) ;
139
- return "verified" ;
140
- case 'wait' : {
141
- const time = data [ "time" ] ? parseInt ( data [ "time" ] , 10 ) : 5000 ;
142
- cy . wait ( time ) ;
143
- return "wait_over" ;
144
- }
145
- case "advance_clock" : {
146
- cy . clock ( ) . tick ( data [ "milliseconds" ] ) ;
147
- return "advanced_clock" ;
148
- }
144
+ return verifyMessageInTimeline ( data ) ;
149
145
case "verify_last_message_is_utd" :
150
- // verifies that the last tile is an UTD
151
- cy . get ( ".mx_EventTile" ) . then ( ( elements ) => {
152
- const lastEventTile = Array . isArray ( elements ) ? elements [ elements . length - 1 ] : elements ;
153
- cy . get ( ".mx_UnknownBody" , { withinSubject : lastEventTile } ) ;
154
- } ) ;
155
- cy . get ( ".mx_UnknownBody" ) ;
156
- return "verified" ;
157
- case "verify_last_message_is_trusted" : {
158
- cy . get ( ".mx_EventTile" )
159
- . last ( )
160
- . find ( ".mx_EventTile_e2eIcon" ) . should ( "not.exist" ) ;
161
- return "verified" ;
162
- }
146
+ return verifyLastMessageIsUTD ( ) ;
147
+ case "verify_last_message_is_trusted" :
148
+ return verifyLastMessageIsTrusted ( ) ;
149
+
150
+ // Browser
151
+ case 'idle' :
152
+ idle ( ) ;
153
+ break ;
154
+ case 'wait' :
155
+ return wait ( data ) ;
156
+ case "advance_clock" :
157
+ return advanceClock ( data ) ;
163
158
case "clear_idb_storage" :
164
- cy . window ( ) . then ( ( window ) => {
165
- return window . indexedDB . databases ( ) . then ( databases => {
166
- const databaseNames : string [ ] = databases
167
- . map ( ( db ) => db . name )
168
- . filter ( ( name ) => name !== undefined ) as string [ ] ;
169
- for ( const name of databaseNames ) {
170
- cy . log ( "Deleting indexedDb database" , name ) ;
171
- window . indexedDB . deleteDatabase ( name ) ;
172
- }
173
- } ) ;
174
- } ) ;
175
- return "storage_cleared" ;
159
+ return clearIDBStorage ( ) ;
176
160
case "reload" :
177
- cy . visit ( "/" ) ;
178
- // cy.reload();
179
- return "reloaded" ;
161
+ return reload ( ) ;
180
162
case 'exit' :
181
- cy . log ( 'Client asked to exit, test complete or server teardown' ) ;
182
- return ;
163
+ exit ( ) ;
164
+ break ;
165
+
183
166
default :
184
167
cy . log ( 'WARNING: unknown action ' , action ) ;
185
- return ;
168
+ break ;
186
169
}
187
170
}
0 commit comments