Properly fix and test the /me command

This commit is contained in:
JC Brand 2017-02-15 21:03:02 +00:00
parent a033899946
commit 65fa39dd81
3 changed files with 61 additions and 2 deletions

View File

@ -16,6 +16,32 @@
return describe("Chatboxes", function() {
describe("A Chatbox", function () {
it("supports the /me command", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.openContactsPanel(_converse);
expect(_converse.chatboxes.length).toEqual(1);
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var message = '/me is tired';
var msg = $msg({
from: sender_jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
var view = _converse.chatboxviews.get(sender_jid);
expect(_.includes(view.$el.find('.chat-msg-author').text(), '**Max Frankfurter')).toBeTruthy();
expect(view.$el.find('.chat-msg-content').text()).toBe(' is tired');
message = '/me is as well';
test_utils.sendMessage(view, message);
expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well');
}));
it("is created when you click on a roster item", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();

View File

@ -362,6 +362,35 @@
expect(view.$el.find('.chat-message').hasClass('mentioned')).toBeTruthy();
}));
it("supports the /me command", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
var view = _converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var message = '/me is tired';
var nick = mock.chatroom_names[0],
msg = $msg({
from: 'lounge@localhost/'+nick,
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(message).tree();
_converse.chatboxes.onMessage(msg);
expect(_.includes(view.$el.find('.chat-msg-author').text(), '**Dyon van de Wege')).toBeTruthy();
expect(view.$el.find('.chat-msg-content').text()).toBe(' is tired');
message = '/me is as well';
msg = $msg({
from: 'lounge@localhost/dummy',
id: (new Date()).getTime(),
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(message).tree();
_converse.chatboxes.onMessage(msg);
expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well');
}));
it("can have spaces and special characters in its name", mock.initConverse(function (_converse) {
test_utils.openChatRoom(_converse, 'lounge & leisure', 'localhost', 'dummy');
var view = _converse.chatboxviews.get(

View File

@ -325,8 +325,12 @@
if ((match) && (match[1] === 'me')) {
text = text.replace(/^\/me/, '');
template = _converse.templates.action;
fullname = _converse.xmppstatus.get('fullname');
username = _.isNil(fullname)? _converse.bare_jid: fullname;
if (attrs.sender === 'me') {
fullname = _converse.xmppstatus.get('fullname');
username = _.isNil(fullname)? _converse.bare_jid: fullname;
} else {
username = attrs.fullname;
}
} else {
template = _converse.templates.message;
username = attrs.sender === 'me' && __('me') || fullname;