You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MockClasses.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Strophe } from 'strophe.js';
  2. import Listenable from '../util/Listenable';
  3. /* eslint-disable no-empty-function */
  4. /**
  5. * Mock {@link ChatRoom}.
  6. */
  7. export class MockChatRoom {
  8. /**
  9. * {@link ChatRoom.addPresenceListener}.
  10. */
  11. addPresenceListener() {
  12. }
  13. }
  14. /**
  15. * Mock Strophe connection.
  16. */
  17. export class MockStropheConnection extends Listenable {
  18. /**
  19. * A constructor...
  20. */
  21. constructor() {
  22. super();
  23. this.sentIQs = [];
  24. }
  25. /**
  26. * XMPP service URL.
  27. *
  28. * @returns {string}
  29. */
  30. get service() {
  31. return 'wss://localhost/xmpp-websocket';
  32. }
  33. /**
  34. * {@see Strophe.Connection.connect}
  35. */
  36. connect(jid, pass, callback) {
  37. this._connectCb = callback;
  38. }
  39. /**
  40. * {@see Strophe.Connection.disconnect}
  41. */
  42. disconnect() {
  43. this.simulateConnectionState(Strophe.Status.DISCONNECTING);
  44. this.simulateConnectionState(Strophe.Status.DISCONNECTED);
  45. }
  46. /**
  47. * Simulates transition to the new connection status.
  48. *
  49. * @param {Strophe.Status} newState - The new connection status to set.
  50. * @returns {void}
  51. */
  52. simulateConnectionState(newState) {
  53. this._connectCb(newState);
  54. }
  55. /**
  56. * {@see Strophe.Connection.sendIQ}.
  57. */
  58. sendIQ(iq, resultCb) {
  59. this.sentIQs.push(iq);
  60. resultCb && resultCb();
  61. }
  62. }
  63. /* eslint-enable no-empty-function */