autocomplete.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function (root, factory) {
  2. define([
  3. "jasmine",
  4. "mock",
  5. "test-utils"
  6. ], factory);
  7. } (this, function (jasmine, mock, test_utils) {
  8. "use strict";
  9. const _ = converse.env._;
  10. const $iq = converse.env.$iq;
  11. const $msg = converse.env.$msg;
  12. const $pres = converse.env.$pres;
  13. const Strophe = converse.env.Strophe;
  14. const u = converse.env.utils;
  15. const sizzle = converse.env.sizzle;
  16. return describe("A groupchat textarea", function () {
  17. it("autocompletes when the user presses tab",
  18. mock.initConverseWithPromises(
  19. null, ['rosterGroupsFetched'], {},
  20. function (done, _converse) {
  21. test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
  22. .then(() => {
  23. const view = _converse.chatboxviews.get('lounge@localhost');
  24. expect(view.model.occupants.length).toBe(1);
  25. const presence = $pres({
  26. 'to': 'dummy@localhost/resource',
  27. 'from': 'lounge@localhost/some1'
  28. })
  29. .c('x', {xmlns: Strophe.NS.MUC_USER})
  30. .c('item', {
  31. 'affiliation': 'none',
  32. 'jid': 'some1@localhost/resource',
  33. 'role': 'participant'
  34. });
  35. _converse.connection._dataRecv(test_utils.createRequest(presence));
  36. expect(view.model.occupants.length).toBe(2);
  37. const textarea = view.el.querySelector('textarea.chat-textarea');
  38. textarea.value = "hello som";
  39. // Press tab
  40. view.keyPressed({
  41. target: textarea,
  42. preventDefault: _.noop,
  43. keyCode: 9
  44. });
  45. expect(view.el.querySelector('.suggestion-box__results').hidden).toBeFalsy();
  46. done();
  47. }).catch(_.partial(console.error, _));
  48. }));
  49. });
  50. }));