mockup.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*global converse */
  2. (function (root, factory) {
  3. define(["jquery", "mock", "test_utils"], factory);
  4. } (this, function ($, mock, test_utils) {
  5. var $msg = converse_api.env.$msg;
  6. test_utils.clearBrowserStorage();
  7. return describe("Live Mockup", $.proxy(function(mock, test_utils) {
  8. describe("Click the links below to view the different elements", function () {
  9. beforeEach(function () {
  10. test_utils.initConverse();
  11. test_utils.createContacts('all');
  12. });
  13. it("Show a chat room", function () {
  14. test_utils.openChatRoom('lounge', 'localhost', 'dummy');
  15. var view = converse.chatboxviews.get('lounge@localhost');
  16. if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
  17. var text = 'This is a sent message';
  18. view.$el.find('.chat-textarea').text(text);
  19. view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
  20. var message = $msg({
  21. from: 'lounge@localhost/dummy',
  22. to: 'dummy@localhost.com',
  23. type: 'groupchat',
  24. id: view.model.messages.at(0).get('msgid')
  25. }).c('body').t(text);
  26. view.onChatRoomMessage(message.nodeTree);
  27. var nick = mock.chatroom_names[0];
  28. text = 'This is a received message';
  29. message = $msg({
  30. from: 'lounge@localhost/'+nick,
  31. id: '1',
  32. to: 'dummy@localhost',
  33. type: 'groupchat'
  34. }).c('body').t(text);
  35. view.onChatRoomMessage(message.nodeTree);
  36. });
  37. it("Show the control box", function () {
  38. test_utils.openControlBox();
  39. test_utils.openContactsPanel();
  40. });
  41. it("Show a headlines box", function () {
  42. converse.connection._dataRecv(
  43. test_utils.createRequest(
  44. $msg({
  45. 'type': 'headline',
  46. 'from': 'notify.example.com',
  47. 'to': 'dummy@localhost',
  48. 'xml:lang': 'en'
  49. })
  50. .c('subject').t('MAIL').up()
  51. .c('body').t('You got mail.').up()
  52. )
  53. );
  54. });
  55. xit("Show a private chat box", function () {
  56. var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
  57. var chatbox = test_utils.openChatBoxFor(contact_jid);
  58. var view = converse.chatboxviews.get(contact_jid);
  59. var message = 'This message is sent from this chatbox';
  60. test_utils.sendMessage(view, message);
  61. message = 'This is a received message';
  62. var msg = $msg({
  63. from: contact_jid,
  64. to: converse.connection.jid,
  65. type: 'chat',
  66. id: (new Date()).getTime()
  67. }).c('body').t(message).up()
  68. .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
  69. converse.chatboxes.onMessage(msg);
  70. });
  71. });
  72. }, window, mock, test_utils));
  73. }));