@@ -16,6 +16,8 @@ limitations under the License.
16
16
17
17
/// <reference types="cypress" />
18
18
19
+ import { IWidget } from "matrix-widget-api" ;
20
+
19
21
import { HomeserverInstance } from "../../plugins/utils/homeserver" ;
20
22
import { SettingLevel } from "../../../src/settings/SettingLevel" ;
21
23
@@ -190,4 +192,101 @@ describe("Room Header", () => {
190
192
} ) ;
191
193
} ) ;
192
194
} ) ;
195
+
196
+ describe ( "with a widget" , ( ) => {
197
+ const ROOM_NAME = "Test Room with a widget" ;
198
+ const WIDGET_ID = "fake-widget" ;
199
+ const WIDGET_HTML = `
200
+ <html lang="en">
201
+ <head>
202
+ <title>Fake Widget</title>
203
+ </head>
204
+ <body>
205
+ Hello World
206
+ </body>
207
+ </html>
208
+ ` ;
209
+
210
+ let widgetUrl : string ;
211
+ let roomId : string ;
212
+
213
+ beforeEach ( ( ) => {
214
+ cy . serveHtmlFile ( WIDGET_HTML ) . then ( ( url ) => {
215
+ widgetUrl = url ;
216
+ } ) ;
217
+
218
+ cy . createRoom ( { name : ROOM_NAME } ) . then ( ( id ) => {
219
+ roomId = id ;
220
+
221
+ // setup widget via state event
222
+ cy . getClient ( )
223
+ . then ( async ( matrixClient ) => {
224
+ const content : IWidget = {
225
+ id : WIDGET_ID ,
226
+ creatorUserId : "somebody" ,
227
+ type : "widget" ,
228
+ name : "widget" ,
229
+ url : widgetUrl ,
230
+ } ;
231
+ await matrixClient . sendStateEvent ( roomId , "im.vector.modular.widgets" , content , WIDGET_ID ) ;
232
+ } )
233
+ . as ( "widgetEventSent" ) ;
234
+
235
+ // set initial layout
236
+ cy . getClient ( )
237
+ . then ( async ( matrixClient ) => {
238
+ const content = {
239
+ widgets : {
240
+ [ WIDGET_ID ] : {
241
+ container : "top" ,
242
+ index : 1 ,
243
+ width : 100 ,
244
+ height : 0 ,
245
+ } ,
246
+ } ,
247
+ } ;
248
+ await matrixClient . sendStateEvent ( roomId , "io.element.widgets.layout" , content , "" ) ;
249
+ } )
250
+ . as ( "layoutEventSent" ) ;
251
+ } ) ;
252
+
253
+ cy . all ( [ cy . get < string > ( "@widgetEventSent" ) , cy . get < string > ( "@layoutEventSent" ) ] ) . then ( ( ) => {
254
+ // open the room
255
+ cy . viewRoomByName ( ROOM_NAME ) ;
256
+ } ) ;
257
+ } ) ;
258
+
259
+ it ( "should highlight the apps button" , ( ) => {
260
+ // Assert that AppsDrawer is rendered
261
+ cy . get ( ".mx_AppsDrawer" ) . should ( "exist" ) ;
262
+
263
+ cy . get ( ".mx_RoomHeader" ) . within ( ( ) => {
264
+ // Assert that "Hide Widgets" button is rendered and aria-checked is set to true
265
+ cy . findByRole ( "button" , { name : "Hide Widgets" } )
266
+ . should ( "exist" )
267
+ . should ( "have.attr" , "aria-checked" , "true" ) ;
268
+ } ) ;
269
+
270
+ cy . get ( ".mx_RoomHeader" ) . percySnapshotElement ( "Room header - with apps button (highlighted)" ) ;
271
+ } ) ;
272
+
273
+ it ( "should support hiding a widget" , ( ) => {
274
+ cy . get ( ".mx_AppsDrawer" ) . should ( "exist" ) ;
275
+
276
+ cy . get ( ".mx_RoomHeader" ) . within ( ( ) => {
277
+ // Click the apps button to hide AppsDrawer
278
+ cy . findByRole ( "button" , { name : "Hide Widgets" } ) . should ( "exist" ) . click ( ) ;
279
+
280
+ // Assert that "Show widgets" button is rendered and aria-checked is set to false
281
+ cy . findByRole ( "button" , { name : "Show Widgets" } )
282
+ . should ( "exist" )
283
+ . should ( "have.attr" , "aria-checked" , "false" ) ;
284
+ } ) ;
285
+
286
+ // Assert that AppsDrawer is not rendered
287
+ cy . get ( ".mx_AppsDrawer" ) . should ( "not.exist" ) ;
288
+
289
+ cy . get ( ".mx_RoomHeader" ) . percySnapshotElement ( "Room header - with apps button (not highlighted)" ) ;
290
+ } ) ;
291
+ } ) ;
193
292
} ) ;
0 commit comments