|
@@ -404,5 +404,144 @@ describe('ChatRoom', () => {
|
404
|
404
|
'</message>');
|
405
|
405
|
});
|
406
|
406
|
});
|
407
|
|
-});
|
408
|
407
|
|
|
408
|
+ describe('onMessage - reaction', () => {
|
|
409
|
+ let room;
|
|
410
|
+ let emitterSpy;
|
|
411
|
+
|
|
412
|
+ beforeEach(() => {
|
|
413
|
+ const xmpp = {
|
|
414
|
+ moderator: new Moderator({
|
|
415
|
+ options: {}
|
|
416
|
+ }),
|
|
417
|
+ options: {},
|
|
418
|
+ addListener: () => {} // eslint-disable-line no-empty-function
|
|
419
|
+ };
|
|
420
|
+
|
|
421
|
+ room = new ChatRoom(
|
|
422
|
+ {} /* connection */,
|
|
423
|
+ 'jid',
|
|
424
|
+ 'password',
|
|
425
|
+ xmpp,
|
|
426
|
+ {} /* options */);
|
|
427
|
+ emitterSpy = spyOn(room.eventEmitter, 'emit');
|
|
428
|
+ });
|
|
429
|
+
|
|
430
|
+ it('parses reactions correctly', () => {
|
|
431
|
+ const msgStr = '' +
|
|
432
|
+ '<message to="jid" type="groupchat" xmlns="jabber:client">' +
|
|
433
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0">' +
|
|
434
|
+ '<reaction>👍</reaction>' +
|
|
435
|
+ '</reactions>' +
|
|
436
|
+ '<store xmlns="urn:xmpp:hints"/>' +
|
|
437
|
+ '</message>';
|
|
438
|
+ const msg = new DOMParser().parseFromString(msgStr, 'text/xml').documentElement;
|
|
439
|
+
|
|
440
|
+ room.onMessage(msg, 'fromjid');
|
|
441
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
442
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
443
|
+ XMPPEvents.REACTION_RECEIVED,
|
|
444
|
+ 'fromjid',
|
|
445
|
+ ['👍'],
|
|
446
|
+ 'mdgId123');
|
|
447
|
+ });
|
|
448
|
+ it('parses multiple reactions correctly', () => {
|
|
449
|
+ const msgStr = '' +
|
|
450
|
+ '<message to="jid" type="groupchat" xmlns="jabber:client">' +
|
|
451
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0">' +
|
|
452
|
+ '<reaction>👍</reaction>' +
|
|
453
|
+ '<reaction>👎</reaction>' +
|
|
454
|
+ '</reactions>' +
|
|
455
|
+ '<store xmlns="urn:xmpp:hints"/>' +
|
|
456
|
+ '</message>';
|
|
457
|
+ const msg = new DOMParser().parseFromString(msgStr, 'text/xml').documentElement;
|
|
458
|
+
|
|
459
|
+ room.onMessage(msg, 'fromjid');
|
|
460
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
461
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
462
|
+ XMPPEvents.REACTION_RECEIVED,
|
|
463
|
+ 'fromjid',
|
|
464
|
+ ['👍', '👎'],
|
|
465
|
+ 'mdgId123');
|
|
466
|
+ });
|
|
467
|
+ it('parses partially bogus reactions correctly', () => {
|
|
468
|
+ const msgStr = '' +
|
|
469
|
+ '<message to="jid" type="groupchat" xmlns="jabber:client">' +
|
|
470
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0">' +
|
|
471
|
+ '<reaction>👍 foo bar baz</reaction>' +
|
|
472
|
+ '</reactions>' +
|
|
473
|
+ '<store xmlns="urn:xmpp:hints"/>' +
|
|
474
|
+ '</message>';
|
|
475
|
+ const msg = new DOMParser().parseFromString(msgStr, 'text/xml').documentElement;
|
|
476
|
+
|
|
477
|
+ room.onMessage(msg, 'fromjid');
|
|
478
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
479
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
480
|
+ XMPPEvents.REACTION_RECEIVED,
|
|
481
|
+ 'fromjid',
|
|
482
|
+ ['👍'],
|
|
483
|
+ 'mdgId123');
|
|
484
|
+ });
|
|
485
|
+ it('parses bogus reactions correctly', () => {
|
|
486
|
+ const msgStr = '' +
|
|
487
|
+ '<message to="jid" type="groupchat" xmlns="jabber:client">' +
|
|
488
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0">' +
|
|
489
|
+ '<reaction>foo bar baz</reaction>' +
|
|
490
|
+ '</reactions>' +
|
|
491
|
+ '<store xmlns="urn:xmpp:hints"/>' +
|
|
492
|
+ '</message>';
|
|
493
|
+ const msg = new DOMParser().parseFromString(msgStr, 'text/xml').documentElement;
|
|
494
|
+
|
|
495
|
+ room.onMessage(msg, 'fromjid');
|
|
496
|
+ expect(emitterSpy.calls.count()).toEqual(0);
|
|
497
|
+ });
|
|
498
|
+ });
|
|
499
|
+
|
|
500
|
+ describe('sendReaction', () => {
|
|
501
|
+ let room;
|
|
502
|
+ let connectionSpy;
|
|
503
|
+
|
|
504
|
+ beforeEach(() => {
|
|
505
|
+ const xmpp = {
|
|
506
|
+ moderator: new Moderator({
|
|
507
|
+ options: {}
|
|
508
|
+ }),
|
|
509
|
+ options: {},
|
|
510
|
+ addListener: () => {} // eslint-disable-line no-empty-function
|
|
511
|
+ };
|
|
512
|
+
|
|
513
|
+ room = new ChatRoom(
|
|
514
|
+ // eslint-disable-next-line no-empty-function
|
|
515
|
+ { send: () => {} } /* connection */,
|
|
516
|
+ 'jid',
|
|
517
|
+ 'password',
|
|
518
|
+ xmpp,
|
|
519
|
+ {} /* options */);
|
|
520
|
+ connectionSpy = spyOn(room.connection, 'send');
|
|
521
|
+ });
|
|
522
|
+ it('sends a valid emoji reaction message', () => {
|
|
523
|
+ room.sendReaction('👍', 'mdgId123', 'participant1');
|
|
524
|
+ expect(connectionSpy.calls.argsFor(0).toString()).toBe(
|
|
525
|
+ '<message to="jid/participant1" type="chat" xmlns="jabber:client">' +
|
|
526
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0"><reaction>👍</reaction></reactions>' +
|
|
527
|
+ '<store xmlns="urn:xmpp:hints"/></message>');
|
|
528
|
+ });
|
|
529
|
+ it('sends only valid emoji reaction message', () => {
|
|
530
|
+ room.sendReaction('I like this 👍', 'mdgId123', 'participant1');
|
|
531
|
+ expect(connectionSpy.calls.argsFor(0).toString()).toBe(
|
|
532
|
+ '<message to="jid/participant1" type="chat" xmlns="jabber:client">' +
|
|
533
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0"><reaction>👍</reaction></reactions>' +
|
|
534
|
+ '<store xmlns="urn:xmpp:hints"/></message>');
|
|
535
|
+ });
|
|
536
|
+ it('sends only the first valid emoji reaction message', () => {
|
|
537
|
+ room.sendReaction('👍👎', 'mdgId123', 'participant1');
|
|
538
|
+ expect(connectionSpy.calls.argsFor(0).toString()).toBe(
|
|
539
|
+ '<message to="jid/participant1" type="chat" xmlns="jabber:client">' +
|
|
540
|
+ '<reactions id="mdgId123" xmlns="urn:xmpp:reactions:0"><reaction>👍</reaction></reactions>' +
|
|
541
|
+ '<store xmlns="urn:xmpp:hints"/></message>');
|
|
542
|
+ });
|
|
543
|
+ it('throws in case of invalid or no emoji', () => {
|
|
544
|
+ expect(() => room.sendReaction('foo bar baz', 'mdgId123', 'participant1')).toThrowError(/Invalid reaction/);
|
|
545
|
+ });
|
|
546
|
+ });
|
|
547
|
+});
|