@@ -18,7 +18,7 @@ import React from "react";
1818import TestRenderer from "react-test-renderer" ;
1919import { jest } from "@jest/globals" ;
2020import { Room } from "matrix-js-sdk/src/models/room" ;
21- import { MatrixWidgetType } from "matrix-widget-api" ;
21+ import { ClientWidgetApi , MatrixWidgetType } from "matrix-widget-api" ;
2222import { mount , ReactWrapper } from "enzyme" ;
2323import { Optional } from "matrix-events-sdk" ;
2424
@@ -39,11 +39,14 @@ import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
3939import AppTile from "../../../../src/components/views/elements/AppTile" ;
4040import { Container , WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore" ;
4141import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer" ;
42+ import { ElementWidgetCapabilities } from "../../../../src/stores/widgets/ElementWidgetCapabilities" ;
43+ import { ElementWidget } from "../../../../src/stores/widgets/StopGapWidget" ;
44+ import { WidgetMessagingStore } from "../../../../src/stores/widgets/WidgetMessagingStore" ;
4245
4346describe ( "AppTile" , ( ) => {
4447 let cli ;
45- let r1 ;
46- let r2 ;
48+ let r1 : Room ;
49+ let r2 : Room ;
4750 const resizeNotifier = new ResizeNotifier ( ) ;
4851 let app1 : IApp ;
4952 let app2 : IApp ;
@@ -328,6 +331,10 @@ describe("AppTile", () => {
328331 moveToContainerSpy = jest . spyOn ( WidgetLayoutStore . instance , 'moveToContainer' ) ;
329332 } ) ;
330333
334+ it ( "requiresClient should be true" , ( ) => {
335+ expect ( wrapper . state ( 'requiresClient' ) ) . toBe ( true ) ;
336+ } ) ;
337+
331338 it ( "clicking 'minimise' should send the widget to the right" , ( ) => {
332339 const minimiseButton = wrapper . find ( '.mx_AppTileMenuBar_iconButton_minimise' ) ;
333340 minimiseButton . first ( ) . simulate ( 'click' ) ;
@@ -355,5 +362,35 @@ describe("AppTile", () => {
355362 expect ( moveToContainerSpy ) . toHaveBeenCalledWith ( r1 , app1 , Container . Top ) ;
356363 } ) ;
357364 } ) ;
365+
366+ describe ( "with an existing widgetApi holding requiresClient = false" , ( ) => {
367+ let wrapper : ReactWrapper ;
368+
369+ beforeEach ( ( ) => {
370+ const api = {
371+ hasCapability : ( capability : ElementWidgetCapabilities ) : boolean => {
372+ return ! ( capability === ElementWidgetCapabilities . RequiresClient ) ;
373+ } ,
374+ once : ( ) => { } ,
375+ } as unknown as ClientWidgetApi ;
376+
377+ const mockWidget = new ElementWidget ( app1 ) ;
378+ WidgetMessagingStore . instance . storeMessaging ( mockWidget , r1 . roomId , api ) ;
379+
380+ wrapper = mount ( (
381+ < MatrixClientContext . Provider value = { cli } >
382+ < AppTile
383+ key = { app1 . id }
384+ app = { app1 }
385+ room = { r1 }
386+ />
387+ </ MatrixClientContext . Provider >
388+ ) ) ;
389+ } ) ;
390+
391+ it ( "requiresClient should be false" , ( ) => {
392+ expect ( wrapper . state ( 'requiresClient' ) ) . toBe ( false ) ;
393+ } ) ;
394+ } ) ;
358395 } ) ;
359396} ) ;
0 commit comments