@@ -528,6 +528,48 @@ describe('MessageComposer', () => {
528
528
expect ( messageComposer . hasSubscriptions ) . toBe ( false ) ;
529
529
} ) ;
530
530
531
+ it ( 'should register draft subscriptions only once if done through registerSubscriptions' , ( ) => {
532
+ const { messageComposer } = setup ( {
533
+ config : { drafts : { enabled : true } } ,
534
+ } ) ;
535
+
536
+ const draftEventSubscriptionsSpy = vi . spyOn (
537
+ messageComposer ,
538
+ 'registerDraftEventSubscriptions' ,
539
+ ) ;
540
+
541
+ messageComposer . registerSubscriptions ( ) ;
542
+ messageComposer . registerSubscriptions ( ) ;
543
+
544
+ expect ( draftEventSubscriptionsSpy ) . toHaveBeenCalledOnce ( ) ;
545
+ } ) ;
546
+
547
+ it ( 'should allow multiple registrations of draft ws events if done through registerDraftEventSubscriptions' , ( ) => {
548
+ const { messageComposer } = setup ( {
549
+ config : { drafts : { enabled : true } } ,
550
+ } ) ;
551
+
552
+ const subscribeDraftUpdatedSpy = vi
553
+ // @ts -expect-error - we are testing private properties
554
+ . spyOn ( messageComposer , 'subscribeDraftUpdated' ) ;
555
+ const subscribeDraftDeletedSpy = vi
556
+ // @ts -expect-error - we are testing private properties
557
+ . spyOn ( messageComposer , 'subscribeDraftDeleted' ) ;
558
+
559
+ messageComposer . registerSubscriptions ( ) ;
560
+
561
+ expect ( subscribeDraftUpdatedSpy ) . toHaveBeenCalledOnce ( ) ;
562
+ expect ( subscribeDraftDeletedSpy ) . toHaveBeenCalledOnce ( ) ;
563
+
564
+ subscribeDraftUpdatedSpy . mockClear ( ) ;
565
+ subscribeDraftDeletedSpy . mockClear ( ) ;
566
+
567
+ messageComposer . registerDraftEventSubscriptions ( ) ;
568
+
569
+ expect ( subscribeDraftUpdatedSpy ) . toHaveBeenCalledOnce ( ) ;
570
+ expect ( subscribeDraftDeletedSpy ) . toHaveBeenCalledOnce ( ) ;
571
+ } ) ;
572
+
531
573
it ( 'should set quoted message' , ( ) => {
532
574
const { messageComposer } = setup ( ) ;
533
575
const quotedMessage = {
@@ -1302,37 +1344,26 @@ describe('MessageComposer', () => {
1302
1344
config : { drafts : { enabled : false } } ,
1303
1345
} ) ;
1304
1346
1305
- const unsubscribeDraftUpdated = vi . fn ( ) ;
1306
- const unsubscribeDraftDeleted = vi . fn ( ) ;
1347
+ const unsubscribeDraftEvents = vi . fn ( ) ;
1307
1348
1308
- // @ts -expect-error - we are testing private properties
1309
- const subscribeDraftUpdatedSpy = vi
1310
- . spyOn ( messageComposer , 'subscribeDraftUpdated' )
1311
- . mockImplementation ( ( ) => unsubscribeDraftUpdated ) ;
1312
- // @ts -expect-error - we are testing private properties
1313
- const subscribeDraftDeletedSpy = vi
1314
- . spyOn ( messageComposer , 'subscribeDraftDeleted' )
1315
- . mockImplementation ( ( ) => unsubscribeDraftDeleted ) ;
1349
+ const registerDraftEventSubscriptionsSpy = vi
1350
+ . spyOn ( messageComposer , 'registerDraftEventSubscriptions' )
1351
+ . mockImplementation ( ( ) => unsubscribeDraftEvents ) ;
1316
1352
1317
1353
messageComposer . registerSubscriptions ( ) ;
1318
1354
1319
- expect ( subscribeDraftUpdatedSpy ) . not . toHaveBeenCalled ( ) ;
1320
- expect ( subscribeDraftDeletedSpy ) . not . toHaveBeenCalled ( ) ;
1355
+ expect ( registerDraftEventSubscriptionsSpy ) . not . toHaveBeenCalled ( ) ;
1321
1356
1322
1357
messageComposer . updateConfig ( { drafts : { enabled : true } } ) ;
1323
1358
1324
- expect ( subscribeDraftUpdatedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1325
- expect ( subscribeDraftDeletedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1359
+ expect ( registerDraftEventSubscriptionsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1326
1360
1327
- subscribeDraftUpdatedSpy . mockClear ( ) ;
1328
- subscribeDraftDeletedSpy . mockClear ( ) ;
1361
+ registerDraftEventSubscriptionsSpy . mockClear ( ) ;
1329
1362
1330
1363
messageComposer . updateConfig ( { drafts : { enabled : false } } ) ;
1331
1364
1332
- expect ( unsubscribeDraftUpdated ) . toHaveBeenCalledTimes ( 1 ) ;
1333
- expect ( unsubscribeDraftDeleted ) . toHaveBeenCalledTimes ( 1 ) ;
1334
- expect ( subscribeDraftUpdatedSpy ) . not . toHaveBeenCalled ( ) ;
1335
- expect ( subscribeDraftDeletedSpy ) . not . toHaveBeenCalled ( ) ;
1365
+ expect ( unsubscribeDraftEvents ) . toHaveBeenCalledTimes ( 1 ) ;
1366
+ expect ( registerDraftEventSubscriptionsSpy ) . not . toHaveBeenCalled ( ) ;
1336
1367
} ) ;
1337
1368
} ) ;
1338
1369
} ) ;
0 commit comments