2013-05-11 14:20:07 +02:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jquery", "jasmine", "mock", "test-utils" ], factory);
|
|
|
|
} (this, function ($, jasmine, mock, test_utils) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var _ = converse.env._;
|
|
|
|
var $pres = converse.env.$pres;
|
|
|
|
var $iq = converse.env.$iq;
|
|
|
|
var $msg = converse.env.$msg;
|
|
|
|
var Strophe = converse.env.Strophe;
|
2017-07-12 09:55:43 +02:00
|
|
|
var Promise = converse.env.Promise;
|
2018-01-03 13:55:57 +01:00
|
|
|
var moment = converse.env.moment;
|
2018-01-04 13:51:40 +01:00
|
|
|
var sizzle = converse.env.sizzle;
|
2018-01-03 20:02:05 +01:00
|
|
|
var u = converse.env.utils;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
return describe("ChatRooms", function () {
|
2016-06-03 10:22:31 +02:00
|
|
|
describe("The \"rooms\" API", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-04-30 15:24:37 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
|
|
|
|
.then(() => test_utils.openAndEnterChatRoom(_converse, 'leisure', 'localhost', 'dummy'))
|
|
|
|
.then(() => test_utils.openAndEnterChatRoom(_converse, 'news', 'localhost', 'dummy'))
|
|
|
|
.then(() => {
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('lounge@localhost').el)).toBeTruthy();
|
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
|
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
// XXX: bit of a cheat here. We want `cleanup()` to be
|
|
|
|
// called on the room. Either it's this or faking
|
|
|
|
// `sendPresence`.
|
|
|
|
_converse.connection.connected = false;
|
|
|
|
|
|
|
|
_converse.api.rooms.close('lounge@localhost');
|
|
|
|
expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
|
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
_converse.api.rooms.close(['leisure@localhost', 'news@localhost']);
|
|
|
|
expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
|
|
|
expect(_converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
|
|
|
|
expect(_converse.chatboxviews.get('news@localhost')).toBeUndefined();
|
2017-12-06 22:10:54 +01:00
|
|
|
return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
2018-04-30 15:24:37 +02:00
|
|
|
})
|
|
|
|
.then(() => test_utils.openAndEnterChatRoom(_converse, 'leisure', 'localhost', 'dummy'))
|
|
|
|
.then(() => {
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('lounge@localhost').el)).toBeTruthy();
|
|
|
|
expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
|
2017-12-06 22:10:54 +01:00
|
|
|
_converse.api.rooms.close();
|
|
|
|
expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
|
|
|
expect(_converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
|
|
|
|
done();
|
2018-04-30 15:24:37 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-03 10:22:31 +02:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
it("has a method 'get' which returns a wrapped chat room (if it exists)",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-10 13:25:40 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group .group-toggle').length;
|
|
|
|
}, 300).then(function () {
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var jid = 'lounge@localhost';
|
|
|
|
var room = _converse.api.rooms.get(jid);
|
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2018-03-11 13:56:53 +01:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
var chatroomview = _converse.chatboxviews.get(jid);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(chatroomview.is_chatroom).toBeTruthy();
|
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
chatroomview.close();
|
|
|
|
|
|
|
|
// Test with mixed case
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'Leisure', 'localhost', 'dummy').then(function () {
|
|
|
|
jid = 'Leisure@localhost';
|
|
|
|
room = _converse.api.rooms.get(jid);
|
|
|
|
expect(room instanceof Object).toBeTruthy();
|
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
jid = 'leisure@localhost';
|
|
|
|
room = _converse.api.rooms.get(jid);
|
|
|
|
expect(room instanceof Object).toBeTruthy();
|
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
jid = 'leiSure@localhost';
|
|
|
|
room = _converse.api.rooms.get(jid);
|
|
|
|
expect(room instanceof Object).toBeTruthy();
|
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
chatroomview.close();
|
|
|
|
|
|
|
|
// Non-existing room
|
|
|
|
jid = 'lounge2@localhost';
|
|
|
|
room = _converse.api.rooms.get(jid);
|
|
|
|
expect(typeof room === 'undefined').toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-06-03 10:22:31 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-03 10:22:31 +02:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
it("has a method 'open' which opens (optionally configures) and returns a wrapped chat box",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-02-27 22:09:17 +01:00
|
|
|
// Mock 'getRoomFeatures', otherwise the room won't be
|
|
|
|
// displayed as it waits first for the features to be returned
|
|
|
|
// (when it's a new room being created).
|
2018-04-08 19:44:53 +02:00
|
|
|
spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
|
2017-02-27 22:09:17 +01:00
|
|
|
var deferred = new $.Deferred();
|
|
|
|
deferred.resolve();
|
|
|
|
return deferred.promise();
|
|
|
|
});
|
|
|
|
|
2017-12-17 16:03:28 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group .group-toggle').length;
|
2017-07-12 09:55:43 +02:00
|
|
|
}, 300).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
var jid = 'lounge@localhost';
|
|
|
|
var room = _converse.api.rooms.open(jid);
|
2017-07-12 09:55:43 +02:00
|
|
|
// Test on chat room that's not yet open
|
2016-06-03 10:22:31 +02:00
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
var chatroomview = _converse.chatboxviews.get(jid);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(chatroomview.is_chatroom).toBeTruthy();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2016-06-03 10:22:31 +02:00
|
|
|
// Test again, now that the room exists.
|
2016-12-20 10:30:20 +01:00
|
|
|
room = _converse.api.rooms.open(jid);
|
2016-06-03 10:22:31 +02:00
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
chatroomview = _converse.chatboxviews.get(jid);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(chatroomview.is_chatroom).toBeTruthy();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2018-01-04 13:51:40 +01:00
|
|
|
chatroomview.close();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2016-06-03 10:22:31 +02:00
|
|
|
// Test with mixed case in JID
|
|
|
|
jid = 'Leisure@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
room = _converse.api.rooms.open(jid);
|
2016-06-03 10:22:31 +02:00
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2016-06-03 10:22:31 +02:00
|
|
|
|
|
|
|
jid = 'leisure@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
room = _converse.api.rooms.open(jid);
|
2016-06-03 10:22:31 +02:00
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2016-06-03 10:22:31 +02:00
|
|
|
|
|
|
|
jid = 'leiSure@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
room = _converse.api.rooms.open(jid);
|
2016-06-03 10:22:31 +02:00
|
|
|
expect(room instanceof Object).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatroomview.el)).toBeTruthy();
|
2016-06-03 10:22:31 +02:00
|
|
|
chatroomview.close();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.muc_instant_rooms = false;
|
2018-01-04 13:51:40 +01:00
|
|
|
var sent_IQ, IQ_id, sent_IQ_els = [];
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2016-12-02 19:12:40 +01:00
|
|
|
sent_IQ = iq;
|
2018-01-04 13:51:40 +01:00
|
|
|
sent_IQ_els.push(iq.nodeTree);
|
2016-12-02 19:12:40 +01:00
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
// Test with configuration
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.rooms.open('room@conference.example.org', {
|
2016-12-02 19:12:40 +01:00
|
|
|
'nick': 'some1',
|
|
|
|
'auto_configure': true,
|
|
|
|
'roomconfig': {
|
|
|
|
'changesubject': false,
|
|
|
|
'membersonly': true,
|
|
|
|
'persistentroom': true,
|
|
|
|
'publicroom': true,
|
|
|
|
'roomdesc': 'Welcome to this room',
|
|
|
|
'whois': 'anyone'
|
|
|
|
}
|
|
|
|
});
|
2018-01-04 13:51:40 +01:00
|
|
|
chatroomview = _converse.chatboxviews.get('room@conference.example.org');
|
2016-12-05 07:03:44 +01:00
|
|
|
|
|
|
|
// We pretend this is a new room, so no disco info is returned.
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'room@conference.example.org',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'error'
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2016-12-05 07:03:44 +01:00
|
|
|
|
2016-12-02 19:12:40 +01:00
|
|
|
/* <presence xmlns="jabber:client" to="dummy@localhost/pda" from="room@conference.example.org/yo">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/pda" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* <status code="201"/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
from:'room@conference.example.org/some1',
|
|
|
|
to:'dummy@localhost/pda'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
affiliation: 'owner',
|
|
|
|
jid: 'dummy@localhost/pda',
|
|
|
|
role: 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status', {code:'110'}).up()
|
|
|
|
.c('status', {code:'201'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2016-12-02 19:12:40 +01:00
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='room@conference.example.org' type='get' xmlns='jabber:client' id='"+IQ_id+
|
|
|
|
"'><query xmlns='http://jabber.org/protocol/muc#owner'/></iq>"
|
|
|
|
);
|
2018-01-04 13:51:40 +01:00
|
|
|
var node = Strophe.xmlHtmlNode(
|
2016-12-02 19:12:40 +01:00
|
|
|
'<iq xmlns="jabber:client"'+
|
|
|
|
' type="result"'+
|
|
|
|
' to="dummy@localhost/pda"'+
|
|
|
|
' from="room@conference.example.org" id="'+IQ_id+'">'+
|
|
|
|
' <query xmlns="http://jabber.org/protocol/muc#owner">'+
|
|
|
|
' <x xmlns="jabber:x:data" type="form">'+
|
|
|
|
' <title>Configuration for room@conference.example.org</title>'+
|
|
|
|
' <instructions>Complete and submit this form to configure the room.</instructions>'+
|
|
|
|
' <field var="FORM_TYPE" type="hidden">'+
|
|
|
|
' <value>http://jabber.org/protocol/muc#roomconfig</value>'+
|
|
|
|
' </field>'+
|
|
|
|
' <field type="text-single" var="muc#roomconfig_roomname" label="Name">'+
|
|
|
|
' <value>Room</value>'+
|
|
|
|
' </field>'+
|
|
|
|
' <field type="text-single" var="muc#roomconfig_roomdesc" label="Description"><value/></field>'+
|
|
|
|
' <field type="boolean" var="muc#roomconfig_persistentroom" label="Make Room Persistent?"/>'+
|
|
|
|
' <field type="boolean" var="muc#roomconfig_publicroom" label="Make Room Publicly Searchable?"><value>1</value></field>'+
|
|
|
|
' <field type="boolean" var="muc#roomconfig_changesubject" label="Allow Occupants to Change Subject?"/>'+
|
|
|
|
' <field type="list-single" var="muc#roomconfig_whois" label="Who May Discover Real JIDs?"><option label="Moderators Only">'+
|
|
|
|
' <value>moderators</value></option><option label="Anyone"><value>anyone</value></option>'+
|
|
|
|
' </field>'+
|
|
|
|
' <field type="text-private" var="muc#roomconfig_roomsecret" label="Password"><value/></field>'+
|
|
|
|
' <field type="boolean" var="muc#roomconfig_moderatedroom" label="Make Room Moderated?"/>'+
|
|
|
|
' <field type="boolean" var="muc#roomconfig_membersonly" label="Make Room Members-Only?"/>'+
|
|
|
|
' <field type="text-single" var="muc#roomconfig_historylength" label="Maximum Number of History Messages Returned by Room">'+
|
|
|
|
' <value>20</value></field>'+
|
|
|
|
' </x>'+
|
|
|
|
' </query>'+
|
2018-01-04 13:51:40 +01:00
|
|
|
' </iq>');
|
|
|
|
|
2018-03-29 10:16:41 +02:00
|
|
|
spyOn(chatroomview.model, 'sendConfiguration').and.callThrough();
|
2018-01-04 13:51:40 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(node.firstElementChild));
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2017-12-17 16:03:28 +01:00
|
|
|
return test_utils.waitUntil(function () {
|
2018-03-29 10:16:41 +02:00
|
|
|
return chatroomview.model.sendConfiguration.calls.count() === 1;
|
2017-07-12 09:55:43 +02:00
|
|
|
}, 300).then(function () {
|
2018-01-04 13:51:40 +01:00
|
|
|
var sent_stanza = sent_IQ_els.pop();
|
|
|
|
while (sent_stanza.getAttribute('type') !== 'set') {
|
|
|
|
sent_stanza = sent_IQ_els.pop();
|
|
|
|
}
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_roomname"] value', sent_stanza).pop().textContent).toBe('Room');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_roomdesc"] value', sent_stanza).pop().textContent).toBe('Welcome to this room');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_persistentroom"] value', sent_stanza).pop().textContent).toBe('1');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_publicroom"] value ', sent_stanza).pop().textContent).toBe('1');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_changesubject"] value', sent_stanza).pop().textContent).toBe('0');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_whois"] value ', sent_stanza).pop().textContent).toBe('anyone');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_membersonly"] value', sent_stanza).pop().textContent).toBe('1');
|
|
|
|
expect(sizzle('field[var="muc#roomconfig_historylength"] value', sent_stanza).pop().textContent).toBe('20');
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2016-12-02 19:12:40 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-03 10:22:31 +02:00
|
|
|
});
|
|
|
|
|
2017-02-14 17:55:32 +01:00
|
|
|
describe("An instant chat room", function () {
|
2018-01-10 13:25:40 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will be created when muc_instant_rooms is set to true",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-05-07 14:31:02 +02:00
|
|
|
var IQ_stanzas = _converse.connection.IQ_stanzas;
|
2017-02-14 17:55:32 +01:00
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2018-01-10 13:25:40 +01:00
|
|
|
if (iq.nodeTree.getAttribute('to') === 'lounge@localhost') {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
} else {
|
|
|
|
sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
}
|
2017-02-14 17:55:32 +01:00
|
|
|
});
|
2018-01-10 13:25:40 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
|
|
|
|
// We pretend this is a new room, so no disco info is returned.
|
|
|
|
//
|
2017-02-14 17:55:32 +01:00
|
|
|
/* <iq from="jordie.langen@chat.example.org/converse.js-11659299" to="myroom@conference.chat.example.org" type="get">
|
|
|
|
* <query xmlns="http://jabber.org/protocol/disco#info"/>
|
|
|
|
* </iq>
|
|
|
|
* <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
|
|
|
|
* <error type="cancel">
|
|
|
|
* <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
|
|
|
* </error>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var features_stanza = $iq({
|
2018-01-10 13:25:40 +01:00
|
|
|
'from': 'lounge@localhost',
|
2017-02-14 17:55:32 +01:00
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'error'
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
|
|
|
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'join').and.callThrough();
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(view, 'submitNickname').and.callThrough();
|
2017-02-14 17:55:32 +01:00
|
|
|
|
|
|
|
/* <iq to="myroom@conference.chat.example.org"
|
|
|
|
* from="jordie.langen@chat.example.org/converse.js-11659299"
|
|
|
|
* type="get">
|
|
|
|
* <query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
* node="x-roomuser-item"/>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-05-07 14:31:02 +02:00
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
|
|
|
return iq.nodeTree.querySelector('query[node="x-roomuser-item"]');
|
|
|
|
}).length > 0;
|
2017-07-12 09:55:43 +02:00
|
|
|
}, 300).then(function () {
|
2018-05-07 14:31:02 +02:00
|
|
|
const iq = _.filter(IQ_stanzas, function (iq) {
|
|
|
|
return iq.nodeTree.querySelector(`query[node="x-roomuser-item"]`);
|
|
|
|
}).pop();
|
|
|
|
|
|
|
|
const id = iq.nodeTree.getAttribute('id');
|
|
|
|
expect(iq.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' from='dummy@localhost/resource' "+
|
|
|
|
"type='get' xmlns='jabber:client' id='"+id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/disco#info' node='x-roomuser-item'/></iq>");
|
|
|
|
|
2018-01-10 13:25:40 +01:00
|
|
|
/* <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
|
2017-07-12 09:55:43 +02:00
|
|
|
* <error type="cancel">
|
|
|
|
* <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
|
|
|
* </error>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var stanza = $iq({
|
|
|
|
'type': 'error',
|
2018-05-07 14:31:02 +02:00
|
|
|
'id': id,
|
2017-07-12 09:55:43 +02:00
|
|
|
'from': view.model.get('jid'),
|
|
|
|
'to': _converse.connection.jid
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
var input = view.el.querySelector('input[name="nick"]');
|
2017-12-06 22:10:54 +01:00
|
|
|
input.value = 'nicky';
|
|
|
|
view.el.querySelector('input[type=submit]').click();
|
|
|
|
expect(view.submitNickname).toHaveBeenCalled();
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(view.join).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// The user has just entered the room (because join was called)
|
|
|
|
// and receives their own presence from the server.
|
|
|
|
// See example 24:
|
|
|
|
// http://xmpp.org/extensions/xep-0045.html#enter-pres
|
|
|
|
//
|
|
|
|
/* <presence xmlns="jabber:client" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org/jc">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item jid="jordie.langen@chat.example.org/converse.js-11659299" affiliation="owner" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* <status code="201"/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
to:'dummy@localhost/resource',
|
|
|
|
from:'lounge@localhost/thirdwitch',
|
|
|
|
id:'5025e055-036c-4bc5-a227-706e7e352053'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'owner',
|
|
|
|
jid: 'dummy@localhost/resource',
|
|
|
|
role: 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).up()
|
|
|
|
.c('status').attrs({code:'201'}).nodeTree;
|
2017-02-14 17:55:32 +01:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-01-04 13:51:40 +01:00
|
|
|
var info_text = view.el.querySelector('.chat-content .chat-info').textContent;
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(info_text).toBe('A new room has been created');
|
|
|
|
|
|
|
|
// An instant room is created by saving the default configuratoin.
|
|
|
|
//
|
|
|
|
/* <iq to="myroom@conference.chat.example.org" type="set" xmlns="jabber:client" id="5025e055-036c-4bc5-a227-706e7e352053:sendIQ">
|
2018-01-04 13:51:40 +01:00
|
|
|
* <query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#owner'><x xmlns='jabber:x:data' type='submit'/>"+
|
|
|
|
"</query></iq>");
|
|
|
|
done();
|
|
|
|
});
|
2017-02-14 17:55:32 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Chat Room", function () {
|
2014-01-19 06:02:18 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows join/leave messages when users enter or exit a room",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-02-24 11:54:54 +01:00
|
|
|
test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1');
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
2017-02-24 11:54:54 +01:00
|
|
|
|
|
|
|
/* We don't show join/leave messages for existing occupants. We
|
|
|
|
* know about them because we receive their presences before we
|
|
|
|
* receive our own.
|
|
|
|
*/
|
2018-04-08 19:44:53 +02:00
|
|
|
var presence = $pres({
|
2017-02-24 11:54:54 +01:00
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/oldguy'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'oldguy@localhost/_converse.js-290929789',
|
2018-01-03 13:04:06 +01:00
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(0);
|
|
|
|
|
|
|
|
/* <presence to="dummy@localhost/_converse.js-29092160"
|
|
|
|
* from="coven@chat.shakespeare.lit/some1">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence></body>
|
|
|
|
*/
|
2018-04-08 19:44:53 +02:00
|
|
|
presence = $pres({
|
2018-01-03 13:04:06 +01:00
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'owner',
|
|
|
|
'jid': 'dummy@localhost/_converse.js-29092160',
|
|
|
|
'role': 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status', {code: '110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(2);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
|
|
|
|
// Add another entrant, otherwise the above message will be
|
|
|
|
// collapsed if "newguy" leaves immediately again
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newgirl'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newgirl@localhost/_converse.js-213098781',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("newgirl has entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
|
|
|
|
// Don't show duplicate join messages
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-290918392',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
|
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'
|
|
|
|
* type='unavailable'>
|
|
|
|
* <status>Disconnected: Replaced by new connection</status>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* role='none'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
type: 'unavailable',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('status', 'Disconnected: Replaced by new connection').up()
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'none'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(4);
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe(
|
|
|
|
'newguy has left the room. '+
|
|
|
|
'"Disconnected: Replaced by new connection"');
|
|
|
|
|
|
|
|
// When the user immediately joins again, we collapse the
|
|
|
|
// multiple join/leave messages.
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(4);
|
|
|
|
var $msg_el = $chat_content.find('div.chat-info:last');
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($msg_el.html()).toBe("newguy has left and re-entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
expect($msg_el.data('leavejoin')).toBe('"newguy"');
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
type: 'unavailable',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'none'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(4);
|
|
|
|
$msg_el = $chat_content.find('div.chat-info:last');
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($msg_el.html()).toBe('newguy has left the room');
|
2018-01-03 13:04:06 +01:00
|
|
|
expect($msg_el.data('leave')).toBe('"newguy"');
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/nomorenicks'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'nomorenicks@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-290918392',
|
|
|
|
type: 'unavailable',
|
|
|
|
from: 'coven@chat.shakespeare.lit/nomorenicks'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'nomorenicks@localhost/_converse.js-290929789',
|
|
|
|
'role': 'none'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered and left the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/nomorenicks'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'nomorenicks@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the room");
|
2018-01-03 13:04:06 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2018-01-03 13:55:57 +01:00
|
|
|
it("shows a new day indicator if a join/leave message is received on a new day",
|
2018-01-03 13:04:06 +01:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
var chat_content = view.el.querySelector('.chat-content');
|
|
|
|
var $chat_content = $(chat_content);
|
2018-04-27 17:59:41 +02:00
|
|
|
var indicator = chat_content.querySelector('.date-separator');
|
|
|
|
expect(indicator).not.toBe(null);
|
|
|
|
expect(indicator.getAttribute('class')).toEqual('message date-separator');
|
|
|
|
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
|
|
|
|
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
|
2018-04-08 19:44:53 +02:00
|
|
|
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(1);
|
|
|
|
expect(chat_content.querySelector('div.chat-info').textContent).toBe(
|
|
|
|
"dummy has entered the room"
|
|
|
|
);
|
2017-02-28 05:49:01 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
var baseTime = new Date();
|
|
|
|
jasmine.clock().install();
|
|
|
|
jasmine.clock().mockDate(baseTime);
|
|
|
|
var ONE_DAY_LATER = 86400000;
|
|
|
|
jasmine.clock().tick(ONE_DAY_LATER);
|
|
|
|
|
|
|
|
/* <presence to="dummy@localhost/_converse.js-29092160"
|
|
|
|
* from="coven@chat.shakespeare.lit/some1">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence></body>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
2017-12-15 17:24:30 +01:00
|
|
|
.c('item', {
|
2018-04-08 19:44:53 +02:00
|
|
|
'affiliation': 'owner',
|
2018-01-03 13:55:57 +01:00
|
|
|
'jid': 'some1@localhost/_converse.js-290929789',
|
2018-04-08 19:44:53 +02:00
|
|
|
'role': 'moderator'
|
2017-12-15 17:24:30 +01:00
|
|
|
});
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-01-03 13:55:57 +01:00
|
|
|
|
2018-04-27 17:59:41 +02:00
|
|
|
indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]');
|
|
|
|
expect(indicator).not.toBe(null);
|
|
|
|
|
|
|
|
expect(indicator.getAttribute('class')).toEqual('message date-separator');
|
|
|
|
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
|
|
|
|
expect(indicator.querySelector('time').getAttribute('class')).toEqual('separator-text');
|
|
|
|
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
|
2018-05-24 09:09:26 +02:00
|
|
|
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
|
2018-04-08 19:44:53 +02:00
|
|
|
expect(chat_content.querySelector('div.chat-info:last-child').textContent).toBe(
|
|
|
|
"some1 has entered the room"
|
|
|
|
);
|
2017-12-15 17:24:30 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
jasmine.clock().tick(ONE_DAY_LATER);
|
2018-01-03 13:55:57 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
// Test a user leaving a chat room
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
type: 'unavailable',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
})
|
|
|
|
.c('status', 'Disconnected: Replaced by new connection').up()
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
2018-05-24 09:09:26 +02:00
|
|
|
'affiliation': 'owner',
|
2018-04-08 19:44:53 +02:00
|
|
|
'jid': 'some1@localhost/_converse.js-290929789',
|
2018-05-24 09:09:26 +02:00
|
|
|
'role': 'moderator'
|
2018-04-08 19:44:53 +02:00
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-01-03 13:55:57 +01:00
|
|
|
|
2018-04-27 17:59:41 +02:00
|
|
|
indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]');
|
|
|
|
|
|
|
|
expect(indicator).not.toBe(null);
|
|
|
|
expect(indicator.getAttribute('class')).toEqual('message date-separator');
|
|
|
|
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
|
|
|
|
|
|
|
|
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
|
2018-05-24 09:09:26 +02:00
|
|
|
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(3);
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($(chat_content).find('div.chat-info:last').html()).toBe(
|
|
|
|
'some1 has left the room. '+
|
|
|
|
'"Disconnected: Replaced by new connection"');
|
2017-12-15 17:24:30 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
jasmine.clock().tick(ONE_DAY_LATER);
|
|
|
|
|
|
|
|
var stanza = Strophe.xmlHtmlNode(
|
|
|
|
'<message xmlns="jabber:client"' +
|
|
|
|
' to="dummy@localhost/_converse.js-290929789"' +
|
|
|
|
' type="groupchat"' +
|
|
|
|
' from="coven@chat.shakespeare.lit/some1">'+
|
|
|
|
' <body>hello world</body>'+
|
|
|
|
' <delay xmlns="urn:xmpp:delay" stamp="'+moment().format()+'" from="some1@localhost"/>'+
|
|
|
|
'</message>').firstChild;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
2017-12-15 17:24:30 +01:00
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
2018-04-08 19:44:53 +02:00
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
2017-12-15 17:24:30 +01:00
|
|
|
});
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-12-15 17:24:30 +01:00
|
|
|
|
2018-06-30 15:25:25 +02:00
|
|
|
let time = chat_content.querySelectorAll('time.separator-text');
|
|
|
|
expect(time.length).toEqual(4);
|
2018-04-08 19:44:53 +02:00
|
|
|
|
2018-04-27 17:59:41 +02:00
|
|
|
var $indicator = $chat_content.find('.date-separator:eq(3)');
|
|
|
|
expect($indicator.attr('class')).toEqual('message date-separator');
|
|
|
|
expect($indicator.data('isodate')).toEqual(moment().startOf('day').format());
|
|
|
|
expect($indicator.find('time').text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
|
2018-05-24 09:09:26 +02:00
|
|
|
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(4);
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the room");
|
|
|
|
|
|
|
|
jasmine.clock().tick(ONE_DAY_LATER);
|
|
|
|
|
|
|
|
stanza = Strophe.xmlHtmlNode(
|
|
|
|
'<message xmlns="jabber:client"' +
|
|
|
|
' to="dummy@localhost/_converse.js-290929789"' +
|
|
|
|
' type="groupchat"' +
|
|
|
|
' from="coven@chat.shakespeare.lit/some1">'+
|
|
|
|
' <body>hello world</body>'+
|
|
|
|
' <delay xmlns="urn:xmpp:delay" stamp="'+moment().format()+'" from="some1@localhost"/>'+
|
|
|
|
'</message>').firstChild;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2017-12-15 17:24:30 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
jasmine.clock().tick(ONE_DAY_LATER);
|
|
|
|
|
|
|
|
// Test a user leaving a chat room
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
type: 'unavailable',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('status', 'Disconnected: Replaced by new connection').up()
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'none'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
|
2018-06-30 15:25:25 +02:00
|
|
|
time = chat_content.querySelectorAll('time.separator-text');
|
|
|
|
expect(time.length).toEqual(6);
|
2018-04-08 19:44:53 +02:00
|
|
|
|
2018-04-27 17:59:41 +02:00
|
|
|
$indicator = $chat_content.find('.date-separator:eq(5)');
|
|
|
|
expect($indicator.attr('class')).toEqual('message date-separator');
|
|
|
|
expect($indicator.data('isodate')).toEqual(moment().startOf('day').format());
|
|
|
|
|
|
|
|
expect($indicator.find('time').text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
|
2018-05-24 09:09:26 +02:00
|
|
|
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(5);
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe(
|
|
|
|
'newguy has left the room. '+
|
|
|
|
'"Disconnected: Replaced by new connection"');
|
|
|
|
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
done();
|
|
|
|
return;
|
|
|
|
});
|
2017-02-24 11:54:54 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows its description in the chat heading",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-02-18 18:15:16 +01:00
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2017-02-18 18:15:16 +01:00
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2018-03-11 13:56:53 +01:00
|
|
|
_converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2017-02-18 18:15:16 +01:00
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'coven@chat.shakespeare.lit',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'result'
|
|
|
|
})
|
|
|
|
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'name': 'A Dark Cave',
|
|
|
|
'type': 'text'
|
|
|
|
}).up()
|
|
|
|
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('feature', {'var': 'muc_passwordprotected'}).up()
|
|
|
|
.c('feature', {'var': 'muc_hidden'}).up()
|
|
|
|
.c('feature', {'var': 'muc_temporary'}).up()
|
|
|
|
.c('feature', {'var': 'muc_open'}).up()
|
|
|
|
.c('feature', {'var': 'muc_unmoderated'}).up()
|
|
|
|
.c('feature', {'var': 'muc_nonanonymous'}).up()
|
|
|
|
.c('feature', {'var': 'urn:xmpp:mam:0'}).up()
|
|
|
|
.c('x', { 'xmlns':'jabber:x:data', 'type':'result'})
|
|
|
|
.c('field', {'var':'FORM_TYPE', 'type':'hidden'})
|
|
|
|
.c('value').t('http://jabber.org/protocol/muc#roominfo').up().up()
|
|
|
|
.c('field', {'type':'text-single', 'var':'muc#roominfo_description', 'label':'Description'})
|
|
|
|
.c('value').t('This is the description').up().up()
|
|
|
|
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
|
|
|
|
.c('value').t(0);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2018-06-04 19:53:33 +02:00
|
|
|
test_utils.waitUntil(() => _.get(view.el.querySelector('.chatroom-description'), 'textContent'))
|
|
|
|
.then(function () {
|
2018-02-07 17:30:44 +01:00
|
|
|
expect($(view.el.querySelector('.chatroom-description')).text()).toBe('This is the description');
|
|
|
|
done();
|
|
|
|
});
|
2017-02-18 18:15:16 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will specially mark messages in which you are mentioned",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-02-15 21:30:32 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-01-03 20:02:05 +01:00
|
|
|
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
|
2017-07-12 09:55:43 +02:00
|
|
|
var message = 'dummy: Your attention is required';
|
|
|
|
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();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($(view.el).find('.chat-msg').hasClass('mentioned')).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-02-15 21:30:32 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("supports the /me command",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
|
2017-12-03 12:21:57 +01:00
|
|
|
.then(function () {
|
2018-05-08 19:24:50 +02:00
|
|
|
return test_utils.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'))
|
2017-12-03 12:21:57 +01:00
|
|
|
}).then(function () {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
}).then(function () {
|
2017-07-12 09:55:43 +02:00
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-01-03 20:02:05 +01:00
|
|
|
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
|
2017-07-12 09:55:43 +02:00
|
|
|
var message = '/me is tired';
|
|
|
|
var nick = mock.chatroom_names[0],
|
|
|
|
msg = $msg({
|
2018-04-17 15:17:39 +02:00
|
|
|
'from': 'lounge@localhost/'+nick,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': 'dummy@localhost',
|
|
|
|
'type': 'groupchat'
|
2017-07-12 09:55:43 +02:00
|
|
|
}).c('body').t(message).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(_.includes($(view.el).find('.chat-msg-author').text(), '**Dyon van de Wege')).toBeTruthy();
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($(view.el).find('.chat-msg-text').text()).toBe(' is tired');
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
message = '/me is as well';
|
2017-02-15 22:03:02 +01:00
|
|
|
msg = $msg({
|
2018-05-01 11:46:30 +02:00
|
|
|
from: 'lounge@localhost/Max Mustermann',
|
2017-02-15 22:03:02 +01:00
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t(message).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(_.includes($(view.el).find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($(view.el).find('.chat-msg-text:last').text()).toBe(' is as well');
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-02-15 22:03:02 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be configured if you're its owner",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-04 19:06:11 +01:00
|
|
|
var view;
|
|
|
|
var sent_IQ, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2016-12-04 19:06:11 +01:00
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-05 07:03:44 +01:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
|
|
|
|
view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
2016-12-04 19:06:11 +01:00
|
|
|
|
2018-03-29 11:56:24 +02:00
|
|
|
spyOn(view.model, 'saveAffiliationAndRole').and.callThrough();
|
2016-12-02 18:41:05 +01:00
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
// We pretend this is a new room, so no disco info is returned.
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'coven@chat.shakespeare.lit',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'error'
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2018-02-07 17:30:44 +01:00
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
/* <presence to="dummy@localhost/_converse.js-29092160"
|
2018-03-29 11:56:24 +02:00
|
|
|
* from="coven@chat.shakespeare.lit/some1">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence></body>
|
|
|
|
*/
|
2018-02-08 09:49:05 +01:00
|
|
|
var presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'owner',
|
|
|
|
'jid': 'dummy@localhost/_converse.js-29092160',
|
|
|
|
'role': 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status', {code: '110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.saveAffiliationAndRole).toHaveBeenCalled();
|
2018-02-08 09:49:05 +01:00
|
|
|
expect($(view.el.querySelector('.toggle-chatbox-button')).is(':visible')).toBeTruthy();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return !_.isNull(view.el.querySelector('.configure-chatroom-button'));
|
|
|
|
}, 300).then(function () {
|
|
|
|
expect($(view.el.querySelector('.configure-chatroom-button')).is(':visible')).toBeTruthy();
|
|
|
|
|
|
|
|
view.el.querySelector('.configure-chatroom-button').click();
|
|
|
|
|
|
|
|
/* Check that an IQ is sent out, asking for the
|
|
|
|
* configuration form.
|
|
|
|
* See: // http://xmpp.org/extensions/xep-0045.html#example-163
|
|
|
|
*
|
|
|
|
* <iq from='crone1@shakespeare.lit/desktop'
|
|
|
|
* id='config1'
|
|
|
|
* to='coven@chat.shakespeare.lit'
|
|
|
|
* type='get'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/muc#owner'/>
|
|
|
|
* </iq>
|
2017-04-05 11:01:31 +02:00
|
|
|
*/
|
2018-02-08 09:49:05 +01:00
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#owner'/>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* Server responds with the configuration form.
|
|
|
|
* See: // http://xmpp.org/extensions/xep-0045.html#example-165
|
|
|
|
*/
|
|
|
|
var config_stanza = $iq({from: 'coven@chat.shakespeare.lit',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'result'})
|
|
|
|
.c('query', { 'xmlns': 'http://jabber.org/protocol/muc#owner'})
|
|
|
|
.c('x', { 'xmlns': 'jabber:x:data', 'type': 'form'})
|
|
|
|
.c('title').t('Configuration for "coven" Room').up()
|
|
|
|
.c('instructions').t('Complete this form to modify the configuration of your room.').up()
|
|
|
|
.c('field', {'type': 'hidden', 'var': 'FORM_TYPE'})
|
|
|
|
.c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Natural-Language Room Name',
|
|
|
|
'type': 'text-single',
|
|
|
|
'var': 'muc#roomconfig_roomname'})
|
|
|
|
.c('value').t('A Dark Cave').up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Short Description of Room',
|
|
|
|
'type': 'text-single',
|
|
|
|
'var': 'muc#roomconfig_roomdesc'})
|
|
|
|
.c('value').t('The place for all good witches!').up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Enable Public Logging?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_enablelogging'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Allow Occupants to Change Subject?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_changesubject'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Allow Occupants to Invite Others?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_allowinvites'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Who Can Send Private Messages?',
|
|
|
|
'type': 'list-single',
|
|
|
|
'var': 'muc#roomconfig_allowpm'})
|
|
|
|
.c('value').t('anyone').up()
|
|
|
|
.c('option', {'label': 'Anyone'})
|
|
|
|
.c('value').t('anyone').up().up()
|
|
|
|
.c('option', {'label': 'Anyone with Voice'})
|
|
|
|
.c('value').t('participants').up().up()
|
|
|
|
.c('option', {'label': 'Moderators Only'})
|
|
|
|
.c('value').t('moderators').up().up()
|
|
|
|
.c('option', {'label': 'Nobody'})
|
|
|
|
.c('value').t('none').up().up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Roles for which Presence is Broadcasted',
|
|
|
|
'type': 'list-multi',
|
|
|
|
'var': 'muc#roomconfig_presencebroadcast'})
|
|
|
|
.c('value').t('moderator').up()
|
|
|
|
.c('value').t('participant').up()
|
|
|
|
.c('value').t('visitor').up()
|
|
|
|
.c('option', {'label': 'Moderator'})
|
|
|
|
.c('value').t('moderator').up().up()
|
|
|
|
.c('option', {'label': 'Participant'})
|
|
|
|
.c('value').t('participant').up().up()
|
|
|
|
.c('option', {'label': 'Visitor'})
|
|
|
|
.c('value').t('visitor').up().up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Roles and Affiliations that May Retrieve Member List',
|
|
|
|
'type': 'list-multi',
|
|
|
|
'var': 'muc#roomconfig_getmemberlist'})
|
|
|
|
.c('value').t('moderator').up()
|
|
|
|
.c('value').t('participant').up()
|
|
|
|
.c('value').t('visitor').up()
|
|
|
|
.c('option', {'label': 'Moderator'})
|
|
|
|
.c('value').t('moderator').up().up()
|
|
|
|
.c('option', {'label': 'Participant'})
|
|
|
|
.c('value').t('participant').up().up()
|
|
|
|
.c('option', {'label': 'Visitor'})
|
|
|
|
.c('value').t('visitor').up().up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Make Room Publicly Searchable?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_publicroom'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Make Room Publicly Searchable?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_publicroom'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Make Room Persistent?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_persistentroom'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Make Room Moderated?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_moderatedroom'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Make Room Members Only?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_membersonly'})
|
|
|
|
.c('value').t(0).up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Password Required for Entry?',
|
|
|
|
'type': 'boolean',
|
|
|
|
'var': 'muc#roomconfig_passwordprotectedroom'})
|
|
|
|
.c('value').t(1).up().up()
|
|
|
|
.c('field', {'type': 'fixed'})
|
|
|
|
.c('value').t('If a password is required to enter this room,'+
|
|
|
|
'you must specify the password below.').up().up()
|
|
|
|
.c('field', {
|
|
|
|
'label': 'Password',
|
|
|
|
'type': 'text-private',
|
|
|
|
'var': 'muc#roomconfig_roomsecret'})
|
|
|
|
.c('value').t('cauldronburn');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(config_stanza));
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-02-07 17:30:44 +01:00
|
|
|
test_utils.waitUntil(function () {
|
2018-02-08 09:49:05 +01:00
|
|
|
return $(view.el.querySelector('form.chatroom-form')).length;
|
2018-02-07 17:30:44 +01:00
|
|
|
}, 300).then(function () {
|
2018-02-08 09:49:05 +01:00
|
|
|
expect($(view.el.querySelector('form.chatroom-form')).length).toBe(1);
|
|
|
|
expect(view.el.querySelectorAll('form.chatroom-form fieldset').length).toBe(2);
|
|
|
|
var $membersonly = $(view.el.querySelector('input[name="muc#roomconfig_membersonly"]'));
|
|
|
|
expect($membersonly.length).toBe(1);
|
|
|
|
expect($membersonly.attr('type')).toBe('checkbox');
|
|
|
|
$membersonly.prop('checked', true);
|
|
|
|
|
|
|
|
var $moderated = $(view.el.querySelector('input[name="muc#roomconfig_moderatedroom"]'));
|
|
|
|
expect($moderated.length).toBe(1);
|
|
|
|
expect($moderated.attr('type')).toBe('checkbox');
|
|
|
|
$moderated.prop('checked', true);
|
|
|
|
|
|
|
|
var $password = $(view.el.querySelector('input[name="muc#roomconfig_roomsecret"]'));
|
|
|
|
expect($password.length).toBe(1);
|
|
|
|
expect($password.attr('type')).toBe('password');
|
|
|
|
|
|
|
|
var $allowpm = $(view.el.querySelector('select[name="muc#roomconfig_allowpm"]'));
|
|
|
|
expect($allowpm.length).toBe(1);
|
|
|
|
$allowpm.val('moderators');
|
|
|
|
|
|
|
|
var $presencebroadcast = $(view.el.querySelector('select[name="muc#roomconfig_presencebroadcast"]'));
|
|
|
|
expect($presencebroadcast.length).toBe(1);
|
|
|
|
$presencebroadcast.val(['moderator']);
|
|
|
|
|
|
|
|
view.el.querySelector('input[type="submit"]').click();
|
|
|
|
|
|
|
|
var $sent_stanza = $(sent_IQ.toLocaleString());
|
|
|
|
expect($sent_stanza.find('field[var="muc#roomconfig_membersonly"] value').text()).toBe('1');
|
|
|
|
expect($sent_stanza.find('field[var="muc#roomconfig_moderatedroom"] value').text()).toBe('1');
|
|
|
|
expect($sent_stanza.find('field[var="muc#roomconfig_allowpm"] value').text()).toBe('moderators');
|
|
|
|
expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator');
|
|
|
|
done();
|
2018-02-07 17:30:44 +01:00
|
|
|
});
|
2017-11-05 18:47:30 +01:00
|
|
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
2016-12-02 18:41:05 +01:00
|
|
|
}));
|
|
|
|
|
2018-05-24 09:09:26 +02:00
|
|
|
it("shows all members even if they're not currently present in the room",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function() {
|
|
|
|
var name;
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost'),
|
2017-12-14 18:43:00 +01:00
|
|
|
occupants = view.el.querySelector('.occupant-list');
|
|
|
|
var presence, role, jid, model;
|
2017-07-12 09:55:43 +02:00
|
|
|
for (var i=0; i<mock.chatroom_names.length; i++) {
|
|
|
|
name = mock.chatroom_names[i];
|
|
|
|
role = mock.chatroom_roles[name].role;
|
|
|
|
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
|
2018-01-03 13:55:57 +01:00
|
|
|
jid =
|
2017-07-12 09:55:43 +02:00
|
|
|
presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:'lounge@localhost/'+name
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: mock.chatroom_roles[name].affiliation,
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
role: role
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-12-14 18:43:00 +01:00
|
|
|
expect(occupants.querySelectorAll('li').length).toBe(2+i);
|
|
|
|
model = view.occupantsview.model.where({'nick': name})[0];
|
|
|
|
var index = view.occupantsview.model.indexOf(model);
|
2018-05-09 12:28:34 +02:00
|
|
|
expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(mock.chatroom_names[i]);
|
2017-07-12 09:55:43 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 09:09:26 +02:00
|
|
|
// Test users leaving the room
|
|
|
|
// http://xmpp.org/extensions/xep-0045.html#exit
|
|
|
|
for (i=mock.chatroom_names.length-1; i>-1; i--) {
|
|
|
|
name = mock.chatroom_names[i];
|
|
|
|
role = mock.chatroom_roles[name].role;
|
|
|
|
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
|
|
|
|
presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:'lounge@localhost/'+name,
|
|
|
|
type: 'unavailable'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: mock.chatroom_roles[name].affiliation,
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
role: 'none'
|
|
|
|
}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect(occupants.querySelectorAll('li').length).toBe(7);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
}).catch(_.partial(console.error, _));
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("shows users currently present in the room",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function() {
|
|
|
|
var name;
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost'),
|
|
|
|
occupants = view.el.querySelector('.occupant-list');
|
|
|
|
var presence, role, jid, model;
|
|
|
|
for (var i=0; i<mock.chatroom_names.length; i++) {
|
|
|
|
name = mock.chatroom_names[i];
|
|
|
|
role = mock.chatroom_roles[name].role;
|
|
|
|
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
|
|
|
|
jid =
|
|
|
|
presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:'lounge@localhost/'+name
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'none',
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
role: role
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect(occupants.querySelectorAll('li').length).toBe(2+i);
|
|
|
|
model = view.occupantsview.model.where({'nick': name})[0];
|
|
|
|
var index = view.occupantsview.model.indexOf(model);
|
|
|
|
expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(mock.chatroom_names[i]);
|
|
|
|
}
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
// Test users leaving the room
|
|
|
|
// http://xmpp.org/extensions/xep-0045.html#exit
|
|
|
|
for (i=mock.chatroom_names.length-1; i>-1; i--) {
|
|
|
|
name = mock.chatroom_names[i];
|
|
|
|
role = mock.chatroom_roles[name].role;
|
|
|
|
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
|
|
|
|
presence = $pres({
|
2015-03-01 11:58:07 +01:00
|
|
|
to:'dummy@localhost/pda',
|
2017-07-12 09:55:43 +02:00
|
|
|
from:'lounge@localhost/'+name,
|
|
|
|
type: 'unavailable'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: mock.chatroom_roles[name].affiliation,
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
role: 'none'
|
|
|
|
}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-12-14 18:43:00 +01:00
|
|
|
expect(occupants.querySelectorAll('li').length).toBe(i+1);
|
2017-07-12 09:55:43 +02:00
|
|
|
}
|
|
|
|
done();
|
2018-05-09 12:28:34 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-07-12 09:55:43 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("escapes occupant nicknames when rendering them, to avoid JS-injection attacks",
|
|
|
|
mock.initConverseWithPromises(null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
/* <presence xmlns="jabber:client" to="jc@chat.example.org/converse.js-17184538"
|
|
|
|
* from="oo@conference.chat.example.org/<img src="x" onerror="alert(123)"/>">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item jid="jc@chat.example.org/converse.js-17184538" affiliation="owner" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence>"
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:"lounge@localhost/<img src="x" onerror="alert(123)"/>"
|
2015-03-01 11:58:07 +01:00
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
2017-07-12 09:55:43 +02:00
|
|
|
jid: 'someone@localhost',
|
|
|
|
role: 'moderator',
|
2015-03-01 11:58:07 +01:00
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
2015-03-01 13:28:24 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-07-12 09:55:43 +02:00
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-05-09 12:28:34 +02:00
|
|
|
var occupants = view.el.querySelector('.occupant-list').querySelectorAll('li .occupant-nick');
|
2017-12-14 18:43:00 +01:00
|
|
|
expect(occupants.length).toBe(2);
|
2018-05-09 12:28:34 +02:00
|
|
|
expect($(occupants).first().text().trim()).toBe("<img src="x" onerror="alert(123)"/>");
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-02-13 09:23:42 +01:00
|
|
|
}));
|
2015-03-01 11:58:07 +01:00
|
|
|
|
2017-12-14 18:43:00 +01:00
|
|
|
it("indicates moderators and visitors by means of a special css class and tooltip",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-05-09 12:28:34 +02:00
|
|
|
|
|
|
|
var occupants = view.el.querySelector('.occupant-list').querySelectorAll('li');
|
|
|
|
expect(occupants.length).toBe(1);
|
|
|
|
expect($(occupants).first().find('.occupant-nick').text().trim()).toBe("dummy");
|
|
|
|
expect($(occupants).first().find('.badge').length).toBe(1);
|
|
|
|
expect($(occupants).first().find('.badge').first().text()).toBe('Member');
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
var presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:'lounge@localhost/moderatorman'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'admin',
|
|
|
|
jid: contact_jid,
|
|
|
|
role: 'moderator',
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
2015-03-01 11:58:07 +01:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-05-09 12:28:34 +02:00
|
|
|
occupants = view.el.querySelector('.occupant-list').querySelectorAll('li');
|
2017-12-14 18:43:00 +01:00
|
|
|
expect(occupants.length).toBe(2);
|
2018-05-09 12:28:34 +02:00
|
|
|
expect($(occupants).first().find('.occupant-nick').text().trim()).toBe("moderatorman");
|
|
|
|
expect($(occupants).last().find('.occupant-nick').text().trim()).toBe("dummy");
|
|
|
|
expect($(occupants).first().find('.badge').length).toBe(2);
|
|
|
|
expect($(occupants).first().find('.badge').first().text()).toBe('Admin');
|
|
|
|
expect($(occupants).first().find('.badge').last().text()).toBe('Moderator');
|
|
|
|
|
2017-12-14 18:43:00 +01:00
|
|
|
expect($(occupants).first().attr('title')).toBe(
|
|
|
|
contact_jid + ' This user is a moderator. Click to mention moderatorman in your message.'
|
|
|
|
);
|
|
|
|
|
|
|
|
contact_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
presence = $pres({
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
from:'lounge@localhost/visitorwoman'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
jid: contact_jid,
|
|
|
|
role: 'visitor',
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
|
|
|
|
occupants = view.el.querySelector('.occupant-list').querySelectorAll('li');
|
2018-05-09 12:28:34 +02:00
|
|
|
expect($(occupants).last().find('.occupant-nick').text().trim()).toBe("visitorwoman");
|
|
|
|
expect($(occupants).last().find('.badge').length).toBe(1);
|
|
|
|
expect($(occupants).last().find('.badge').last().text()).toBe('Visitor');
|
2017-12-14 18:43:00 +01:00
|
|
|
expect($(occupants).last().attr('title')).toBe(
|
|
|
|
contact_jid + ' This user can NOT send messages in this room. Click to mention visitorwoman in your message.'
|
|
|
|
);
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
2018-05-09 12:28:34 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:34:36 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will use the user's reserved nickname, if it exists",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-05-07 14:31:02 +02:00
|
|
|
var IQ_stanzas = _converse.connection.IQ_stanzas;
|
2016-07-20 01:59:52 +02:00
|
|
|
var sent_IQ, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2018-01-10 13:25:40 +01:00
|
|
|
if (iq.nodeTree.getAttribute('to') === 'lounge@localhost') {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
} else {
|
|
|
|
sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
}
|
2016-07-20 01:59:52 +02:00
|
|
|
});
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
2016-12-05 07:03:44 +01:00
|
|
|
|
|
|
|
// We pretend this is a new room, so no disco info is returned.
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'lounge@localhost',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'error'
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2016-12-05 07:03:44 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'join').and.callThrough();
|
2016-07-20 01:59:52 +02:00
|
|
|
|
|
|
|
/* <iq from='hag66@shakespeare.lit/pda'
|
|
|
|
* id='getnick1'
|
|
|
|
* to='coven@chat.shakespeare.lit'
|
|
|
|
* type='get'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'
|
|
|
|
* node='x-roomuser-item'/>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-05-07 14:31:02 +02:00
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
|
|
|
return iq.nodeTree.querySelector('query[node="x-roomuser-item"]');
|
|
|
|
}).length > 0;
|
2017-07-12 09:55:43 +02:00
|
|
|
}, 300).then(function () {
|
2018-05-07 14:31:02 +02:00
|
|
|
const iq = _.filter(IQ_stanzas, function (iq) {
|
|
|
|
return iq.nodeTree.querySelector(`query[node="x-roomuser-item"]`);
|
|
|
|
}).pop();
|
|
|
|
const id = iq.nodeTree.getAttribute('id');
|
|
|
|
expect(iq.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' from='dummy@localhost/resource' "+
|
|
|
|
"type='get' xmlns='jabber:client' id='"+id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/disco#info' node='x-roomuser-item'/></iq>");
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
/* <iq from='coven@chat.shakespeare.lit'
|
|
|
|
* id='getnick1'
|
|
|
|
* to='hag66@shakespeare.lit/pda'
|
|
|
|
* type='result'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'
|
|
|
|
* node='x-roomuser-item'>
|
|
|
|
* <identity
|
|
|
|
* category='conference'
|
|
|
|
* name='thirdwitch'
|
|
|
|
* type='text'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var stanza = $iq({
|
|
|
|
'type': 'result',
|
|
|
|
'id': IQ_id,
|
|
|
|
'from': view.model.get('jid'),
|
|
|
|
'to': _converse.connection.jid
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'})
|
|
|
|
.c('identity', {'category': 'conference', 'name': 'thirdwitch', 'type': 'text'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
expect(view.join).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// The user has just entered the room (because join was called)
|
|
|
|
// and receives their own presence from the server.
|
|
|
|
// See example 24:
|
|
|
|
// http://xmpp.org/extensions/xep-0045.html#enter-pres
|
|
|
|
var presence = $pres({
|
|
|
|
to:'dummy@localhost/resource',
|
|
|
|
from:'lounge@localhost/thirdwitch',
|
|
|
|
id:'DC352437-C019-40EC-B590-AF29E879AF97'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'member',
|
|
|
|
jid: 'dummy@localhost/resource',
|
2017-12-22 13:02:24 +01:00
|
|
|
role: 'participant'
|
2017-07-12 09:55:43 +02:00
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).up()
|
|
|
|
.c('status').attrs({code:'210'}).nodeTree;
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-04-08 19:44:53 +02:00
|
|
|
var info_text = $(view.el).find('.chat-content .chat-info:first').text();
|
2017-09-24 20:36:39 +02:00
|
|
|
expect(info_text).toBe('Your nickname has been automatically set to thirdwitch');
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-07-20 01:59:52 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("allows the user to invite their roster contacts to enter the chat room",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
2017-02-14 11:19:01 +01:00
|
|
|
test_utils.createContacts(_converse, 'current'); // We need roster contacts, so that we have someone to invite
|
|
|
|
// Since we don't actually fetch roster contacts, we need to
|
|
|
|
// cheat here and emit the event.
|
|
|
|
_converse.emit('rosterContactsFetched');
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'prompt').and.callFake(function () {
|
2017-02-14 11:19:01 +01:00
|
|
|
return "Please join!";
|
2014-08-31 22:48:26 +02:00
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2017-02-27 18:50:55 +01:00
|
|
|
|
|
|
|
// XXX: cheating a lttle bit, normally this'll be set after
|
|
|
|
// receiving the features for the room.
|
|
|
|
view.model.set('open', 'true');
|
|
|
|
|
2018-03-29 11:56:24 +02:00
|
|
|
spyOn(view.model, 'directInvite').and.callThrough();
|
2017-02-14 11:19:01 +01:00
|
|
|
var $input;
|
2018-01-03 20:02:05 +01:00
|
|
|
$(view.el).find('.chat-area').remove();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
2018-03-26 15:38:03 +02:00
|
|
|
return $(view.el).find('input.invited-contact').length;
|
2017-07-12 09:55:43 +02:00
|
|
|
}, 300).then(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
var $input = $(view.el).find('input.invited-contact');
|
2016-04-07 12:35:07 +02:00
|
|
|
expect($input.attr('placeholder')).toBe('Invite');
|
2014-08-31 22:48:26 +02:00
|
|
|
$input.val("Felix");
|
2018-03-26 15:38:03 +02:00
|
|
|
var evt = new Event('input');
|
2017-02-14 13:48:55 +01:00
|
|
|
$input[0].dispatchEvent(evt);
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2017-02-14 11:19:01 +01:00
|
|
|
var sent_stanza;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
2017-02-14 11:19:01 +01:00
|
|
|
sent_stanza = stanza;
|
|
|
|
});
|
|
|
|
var $hint = $input.siblings('ul').children('li');
|
2014-08-31 22:48:26 +02:00
|
|
|
expect($input.val()).toBe('Felix');
|
2017-02-14 11:19:01 +01:00
|
|
|
expect($hint[0].textContent).toBe('Felix Amsel');
|
|
|
|
expect($hint.length).toBe(1);
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2017-02-14 13:48:55 +01:00
|
|
|
if (typeof(Event) === 'function') {
|
|
|
|
// Not working on PhantomJS
|
|
|
|
evt = new Event('mousedown', {'bubbles': true});
|
|
|
|
evt.button = 0; // For some reason awesomplete wants this
|
|
|
|
$hint[0].dispatchEvent(evt);
|
|
|
|
expect(window.prompt).toHaveBeenCalled();
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.directInvite).toHaveBeenCalled();
|
2017-02-14 13:48:55 +01:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<message from='dummy@localhost/resource' to='felix.amsel@localhost' id='" +
|
|
|
|
sent_stanza.nodeTree.getAttribute('id') +
|
|
|
|
"' xmlns='jabber:client'>"+
|
|
|
|
"<x xmlns='jabber:x:conference' jid='lounge@localhost' reason='Please join!'/>"+
|
|
|
|
"</message>"
|
|
|
|
);
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2014-08-31 22:48:26 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-08-31 19:25:54 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be joined automatically, based upon a received invite",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current'); // We need roster contacts, who can invite us
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'confirm').and.callFake(function () {
|
2014-09-02 20:01:49 +02:00
|
|
|
return true;
|
|
|
|
});
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
view.close(); // Hack, otherwise we have to mock stanzas.
|
|
|
|
|
|
|
|
var name = mock.cur_names[0];
|
|
|
|
var from_jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var room_jid = 'lounge@localhost';
|
|
|
|
var reason = "Please join this chat room";
|
2018-03-02 12:36:08 +01:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(_converse.chatboxes.models.length).toBe(1);
|
|
|
|
expect(_converse.chatboxes.models[0].id).toBe("controlbox");
|
2018-03-02 12:36:08 +01:00
|
|
|
|
|
|
|
var stanza = Strophe.xmlHtmlNode(
|
|
|
|
'<message xmlns="jabber:client" to="'+_converse.bare_jid+'" from="'+from_jid+'" id="9bceb415-f34b-4fa4-80d5-c0d076a24231">'+
|
|
|
|
'<x xmlns="jabber:x:conference" jid="'+room_jid+'" reason="'+reason+'"/>'+
|
|
|
|
'</message>').firstChild;
|
|
|
|
_converse.onDirectMUCInvitation(stanza);
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalledWith(
|
|
|
|
name + ' has invited you to join a chat room: '+ room_jid +
|
|
|
|
', and left the following reason: "'+reason+'"');
|
|
|
|
expect(_converse.chatboxes.models.length).toBe(2);
|
|
|
|
expect(_converse.chatboxes.models[0].id).toBe('controlbox');
|
|
|
|
expect(_converse.chatboxes.models[1].id).toBe(room_jid);
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-09-02 20:01:49 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows received groupchat messages",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-05-01 09:47:45 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
|
|
|
|
|
|
|
|
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
|
|
|
|
var nick = mock.chatroom_names[0];
|
|
|
|
|
|
|
|
view.model.occupants.create({
|
|
|
|
'nick': nick,
|
|
|
|
'muc_jid': `${view.model.get('jid')}/${nick}`
|
|
|
|
});
|
|
|
|
|
|
|
|
var text = 'This is a received message';
|
|
|
|
var message = $msg({
|
|
|
|
from: 'lounge@localhost/'+nick,
|
|
|
|
id: '1',
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t(text);
|
|
|
|
view.model.onMessage(message.nodeTree);
|
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
|
|
|
expect($chat_content.find('.chat-msg').length).toBe(1);
|
|
|
|
expect($chat_content.find('.chat-msg-text').text()).toBe(text);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-12-16 18:19:25 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows sent groupchat messages",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-01-03 20:02:05 +01:00
|
|
|
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
|
2017-07-12 09:55:43 +02:00
|
|
|
var text = 'This is a sent message';
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
textarea.value = text;
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('messageSend', text);
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($chat_content.find('.chat-msg').length).toBe(1);
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
// Let's check that if we receive the same message again, it's
|
|
|
|
// not shown.
|
|
|
|
var message = $msg({
|
|
|
|
from: 'lounge@localhost/dummy',
|
|
|
|
to: 'dummy@localhost.com',
|
|
|
|
type: 'groupchat',
|
|
|
|
id: view.model.messages.at(0).get('msgid')
|
|
|
|
}).c('body').t(text);
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(message.nodeTree);
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($chat_content.find('.chat-msg').length).toBe(1);
|
|
|
|
expect($chat_content.find('.chat-msg-text').last().text()).toBe(text);
|
2017-07-12 09:55:43 +02:00
|
|
|
// We don't emit an event if it's our own message
|
|
|
|
expect(_converse.emit.calls.count(), 1);
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-25 11:22:27 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will cause the chat area to be scrolled down only if it was at the bottom already",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-05-28 10:55:03 +02:00
|
|
|
var message = 'This message is received while the chat area is scrolled up';
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'scrollDown').and.callThrough();
|
|
|
|
/* Create enough messages so that there's a
|
|
|
|
* scrollbar.
|
|
|
|
*/
|
|
|
|
for (var i=0; i<20; i++) {
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(
|
2017-07-12 09:55:43 +02:00
|
|
|
$msg({
|
|
|
|
from: 'lounge@localhost/someone',
|
|
|
|
to: 'dummy@localhost.com',
|
|
|
|
type: 'groupchat',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
}).c('body').t('Message: '+i).tree());
|
|
|
|
}
|
|
|
|
// Give enough time for `markScrolled` to have been called
|
|
|
|
setTimeout(function () {
|
2018-01-02 21:44:46 +01:00
|
|
|
view.content.scrollTop = 0;
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(
|
2017-07-12 09:55:43 +02:00
|
|
|
$msg({
|
|
|
|
from: 'lounge@localhost/someone',
|
|
|
|
to: 'dummy@localhost.com',
|
|
|
|
type: 'groupchat',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
}).c('body').t(message).tree());
|
|
|
|
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
2018-04-27 16:58:49 +02:00
|
|
|
var msg_txt = $chat_content.find('.chat-msg:last').find('.chat-msg-text').text();
|
2017-07-12 09:55:43 +02:00
|
|
|
expect(msg_txt).toEqual(message);
|
2018-01-02 21:44:46 +01:00
|
|
|
expect(view.content.scrollTop).toBe(0);
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
}, 500);
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-28 10:55:03 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows received chatroom subject messages",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'jdev', 'conference.jabber.org', 'jc').then(function () {
|
|
|
|
var text = 'Jabber/XMPP Development | RFCs and Extensions: http://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
|
|
|
|
var stanza = Strophe.xmlHtmlNode(
|
|
|
|
'<message xmlns="jabber:client" to="jc@opkode.com/_converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm">'+
|
|
|
|
' <subject>'+text+'</subject>'+
|
|
|
|
' <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>'+
|
|
|
|
' <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>'+
|
|
|
|
'</message>').firstChild;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
var view = _converse.chatboxviews.get('jdev@conference.jabber.org');
|
2018-03-11 13:56:53 +01:00
|
|
|
var chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect($(chat_content).find('.chat-event:last').text()).toBe('Topic set by ralphm');
|
|
|
|
expect($(chat_content).find('.chat-topic:last').text()).toBe(text);
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-14 23:20:59 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("escapes the subject before rendering it, to avoid JS-injection attacks",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'jdev', 'conference.jabber.org', 'jc').then(function () {
|
|
|
|
spyOn(window, 'alert');
|
|
|
|
var subject = '<img src="x" onerror="alert(\'XSS\');"/>';
|
|
|
|
var view = _converse.chatboxviews.get('jdev@conference.jabber.org');
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.set({'subject': {
|
|
|
|
'text': subject,
|
|
|
|
'author': 'ralphm'
|
|
|
|
}});
|
2018-03-11 13:56:53 +01:00
|
|
|
var chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect($(chat_content).find('.chat-event:last').text()).toBe('Topic set by ralphm');
|
|
|
|
expect($(chat_content).find('.chat-topic:last').text()).toBe(subject);
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-02-13 09:23:42 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("informs users if their nicknames has been changed.",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-09-06 12:25:37 +02:00
|
|
|
/* The service then sends two presence stanzas to the full JID
|
|
|
|
* of each occupant (including the occupant who is changing his
|
|
|
|
* or her room nickname), one of type "unavailable" for the old
|
|
|
|
* nickname and one indicating availability for the new
|
|
|
|
* nickname.
|
|
|
|
*
|
|
|
|
* See: http://xmpp.org/extensions/xep-0045.html#changenick
|
|
|
|
*
|
|
|
|
* <presence
|
|
|
|
* from='coven@localhost/thirdwitch'
|
|
|
|
* id='DC352437-C019-40EC-B590-AF29E879AF98'
|
|
|
|
* to='hag66@shakespeare.lit/pda'
|
|
|
|
* type='unavailable'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* nick='oldhag'
|
2017-12-22 13:02:24 +01:00
|
|
|
* role='participant'/>
|
2014-09-06 12:25:37 +02:00
|
|
|
* <status code='303'/>
|
|
|
|
* <status code='110'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
2015-03-01 11:22:37 +01:00
|
|
|
*
|
2014-09-06 12:25:37 +02:00
|
|
|
* <presence
|
|
|
|
* from='coven@localhost/oldhag'
|
|
|
|
* id='5B4F27A4-25ED-43F7-A699-382C6B4AFC67'
|
|
|
|
* to='hag66@shakespeare.lit/pda'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
2017-12-22 13:02:24 +01:00
|
|
|
* role='participant'/>
|
2014-09-06 12:25:37 +02:00
|
|
|
* <status code='110'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
2017-09-24 20:36:39 +02:00
|
|
|
var __ = _converse.__;
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'oldnick').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
2015-03-01 11:22:37 +01:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
var $occupants = $(view.el.querySelector('.occupant-list'));
|
2017-07-12 09:55:43 +02:00
|
|
|
expect($occupants.children().length).toBe(1);
|
2018-05-09 12:28:34 +02:00
|
|
|
expect($occupants.children().first(0).find('.occupant-nick').text().trim()).toBe("oldnick");
|
2016-07-19 15:24:22 +02:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(1);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($chat_content.find('div.chat-info:first').html()).toBe("oldnick has entered the room");
|
2014-09-06 12:25:37 +02:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
var presence = $pres().attrs({
|
2017-07-12 09:55:43 +02:00
|
|
|
from:'lounge@localhost/oldnick',
|
|
|
|
id:'DC352437-C019-40EC-B590-AF29E879AF98',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'unavailable'
|
|
|
|
})
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'member',
|
|
|
|
jid: 'dummy@localhost/pda',
|
|
|
|
nick: 'newnick',
|
2017-12-22 13:02:24 +01:00
|
|
|
role: 'participant'
|
2017-07-12 09:55:43 +02:00
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'303'}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
2015-03-01 11:22:37 +01:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(2);
|
2017-07-12 09:55:43 +02:00
|
|
|
expect($chat_content.find('div.chat-info').last().html()).toBe(
|
2017-09-24 20:36:39 +02:00
|
|
|
__(_converse.muc.new_nickname_messages["303"], "newnick")
|
|
|
|
);
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
$occupants = $(view.el.querySelector('.occupant-list'));
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($occupants.children().length).toBe(1);
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
presence = $pres().attrs({
|
|
|
|
from:'lounge@localhost/newnick',
|
|
|
|
id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67',
|
|
|
|
to:'dummy@localhost/pda'
|
|
|
|
})
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'member',
|
|
|
|
jid: 'dummy@localhost/pda',
|
2017-12-22 13:02:24 +01:00
|
|
|
role: 'participant'
|
2017-07-12 09:55:43 +02:00
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'}).nodeTree;
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-05-24 09:09:26 +02:00
|
|
|
// XXX: currently we still have an additional "has entered the room"
|
|
|
|
// notification for the new nickname. Ideally we'd not have
|
|
|
|
// that, but that's probably not possible without some
|
|
|
|
// significant refactoring.
|
|
|
|
expect($chat_content.find('div.chat-info').length).toBe(3);
|
2018-04-08 19:44:53 +02:00
|
|
|
expect($chat_content.find('div.chat-info').get(1).textContent).toBe(
|
2017-09-24 20:36:39 +02:00
|
|
|
__(_converse.muc.new_nickname_messages["303"], "newnick")
|
|
|
|
);
|
2018-01-03 20:02:05 +01:00
|
|
|
$occupants = $(view.el.querySelector('.occupant-list'));
|
2017-07-12 09:55:43 +02:00
|
|
|
expect($occupants.children().length).toBe(1);
|
2018-05-09 15:02:10 +02:00
|
|
|
expect($occupants.children().find('.occupant-nick').first(0).text()).toBe("newnick");
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-09-06 12:46:24 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("queries for the room information before attempting to join the user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-05 07:03:44 +01:00
|
|
|
var sent_IQ, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2016-12-05 07:03:44 +01:00
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
|
2016-12-05 07:03:44 +01:00
|
|
|
|
|
|
|
// Check that the room queried for the feautures.
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq from='dummy@localhost/resource' to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/disco#info'/>"+
|
|
|
|
"</iq>");
|
|
|
|
|
2018-06-30 13:46:56 +02:00
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
spyOn(view.model, 'parseRoomFeatures').and.callThrough();
|
2016-12-05 07:03:44 +01:00
|
|
|
/* <iq from='coven@chat.shakespeare.lit'
|
|
|
|
* id='ik3vs715'
|
|
|
|
* to='hag66@shakespeare.lit/pda'
|
|
|
|
* type='result'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'>
|
|
|
|
* <identity
|
|
|
|
* category='conference'
|
|
|
|
* name='A Dark Cave'
|
|
|
|
* type='text'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/muc'/>
|
|
|
|
* <feature var='muc_passwordprotected'/>
|
|
|
|
* <feature var='muc_hidden'/>
|
|
|
|
* <feature var='muc_temporary'/>
|
|
|
|
* <feature var='muc_open'/>
|
|
|
|
* <feature var='muc_unmoderated'/>
|
|
|
|
* <feature var='muc_nonanonymous'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'coven@chat.shakespeare.lit',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'result'
|
|
|
|
})
|
|
|
|
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'name': 'A Dark Cave',
|
|
|
|
'type': 'text'
|
|
|
|
}).up()
|
|
|
|
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
2016-12-05 11:50:01 +01:00
|
|
|
.c('feature', {'var': 'muc_passwordprotected'}).up()
|
|
|
|
.c('feature', {'var': 'muc_hidden'}).up()
|
|
|
|
.c('feature', {'var': 'muc_temporary'}).up()
|
|
|
|
.c('feature', {'var': 'muc_open'}).up()
|
|
|
|
.c('feature', {'var': 'muc_unmoderated'}).up()
|
|
|
|
.c('feature', {'var': 'muc_nonanonymous'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2018-06-30 13:46:56 +02:00
|
|
|
test_utils.waitUntil(() => view.model.parseRoomFeatures.calls.count(), 300)
|
|
|
|
.then(() => {
|
|
|
|
expect(view.model.get('features_fetched')).toBeTruthy();
|
|
|
|
expect(view.model.get('passwordprotected')).toBe(true);
|
|
|
|
expect(view.model.get('hidden')).toBe(true);
|
|
|
|
expect(view.model.get('temporary')).toBe(true);
|
|
|
|
expect(view.model.get('open')).toBe(true);
|
|
|
|
expect(view.model.get('unmoderated')).toBe(true);
|
|
|
|
expect(view.model.get('nonanonymous')).toBe(true);
|
|
|
|
done();
|
|
|
|
});
|
2016-12-05 07:03:44 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("updates the shown features when the room configuration has changed",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-03-19 19:23:02 +01:00
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'room', 'conference.example.org', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('room@conference.example.org');
|
|
|
|
view.model.set({
|
|
|
|
'passwordprotected': false,
|
|
|
|
'unsecured': true,
|
|
|
|
'hidden': false,
|
|
|
|
'public': true,
|
|
|
|
'membersonly': false,
|
|
|
|
'open': true,
|
|
|
|
'persistent': false,
|
|
|
|
'temporary': true,
|
|
|
|
'nonanonymous': true,
|
|
|
|
'semianonymous': false,
|
|
|
|
'moderated': false,
|
|
|
|
'unmoderated': true
|
|
|
|
});
|
|
|
|
expect(view.model.get('persistent')).toBe(false);
|
|
|
|
expect(view.model.get('temporary')).toBe(true);
|
|
|
|
view.model.set({'persistent': true});
|
|
|
|
expect(view.model.get('persistent')).toBe(true);
|
|
|
|
expect(view.model.get('temporary')).toBe(false);
|
|
|
|
|
|
|
|
expect(view.model.get('unsecured')).toBe(true);
|
|
|
|
expect(view.model.get('passwordprotected')).toBe(false);
|
|
|
|
view.model.set({'passwordprotected': true});
|
|
|
|
expect(view.model.get('unsecured')).toBe(false);
|
|
|
|
expect(view.model.get('passwordprotected')).toBe(true);
|
|
|
|
|
|
|
|
expect(view.model.get('unmoderated')).toBe(true);
|
|
|
|
expect(view.model.get('moderated')).toBe(false);
|
|
|
|
view.model.set({'moderated': true});
|
|
|
|
expect(view.model.get('unmoderated')).toBe(false);
|
|
|
|
expect(view.model.get('moderated')).toBe(true);
|
|
|
|
|
|
|
|
expect(view.model.get('nonanonymous')).toBe(true);
|
|
|
|
expect(view.model.get('semianonymous')).toBe(false);
|
|
|
|
view.model.set({'nonanonymous': false});
|
|
|
|
expect(view.model.get('nonanonymous')).toBe(false);
|
|
|
|
expect(view.model.get('semianonymous')).toBe(true);
|
|
|
|
|
|
|
|
expect(view.model.get('open')).toBe(true);
|
|
|
|
expect(view.model.get('membersonly')).toBe(false);
|
|
|
|
view.model.set({'membersonly': true});
|
|
|
|
expect(view.model.get('open')).toBe(false);
|
|
|
|
expect(view.model.get('membersonly')).toBe(true);
|
|
|
|
done();
|
2018-05-22 16:44:58 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-03-19 19:23:02 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("indicates when a room is no longer anonymous",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-05 07:03:44 +01:00
|
|
|
var sent_IQ, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2016-12-05 07:03:44 +01:00
|
|
|
|
2017-12-22 22:24:22 +01:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'some1').then(function () {
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-05 07:03:44 +01:00
|
|
|
|
2017-12-22 22:24:22 +01:00
|
|
|
// We pretend this is a new room, so no disco info is returned.
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'coven@chat.shakespeare.lit',
|
|
|
|
'id': IQ_id,
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'error'
|
|
|
|
}).c('error', {'type': 'cancel'})
|
|
|
|
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
|
|
|
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
/* <message xmlns="jabber:client"
|
|
|
|
* type="groupchat"
|
|
|
|
* to="dummy@localhost/_converse.js-27854181"
|
|
|
|
* from="coven@chat.shakespeare.lit">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <status code="104"/>
|
|
|
|
* <status code="172"/>
|
|
|
|
* </x>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
var message = $msg({
|
|
|
|
type:'groupchat',
|
|
|
|
to: 'dummy@localhost/_converse.js-27854181',
|
|
|
|
from: 'coven@chat.shakespeare.lit'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('status', {code: '104'}).up()
|
|
|
|
.c('status', {code: '172'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(message));
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_body = $(view.el.querySelector('.chatroom-body'));
|
2017-12-24 16:46:49 +01:00
|
|
|
expect($chat_body.find('.message:last').text()).toBe('This room is now no longer anonymous');
|
2017-12-22 22:24:22 +01:00
|
|
|
done();
|
|
|
|
});
|
2016-12-02 18:41:05 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("informs users if they have been kicked out of the chat room",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-09-06 12:46:24 +02:00
|
|
|
/* <presence
|
|
|
|
* from='harfleur@chat.shakespeare.lit/pistol'
|
|
|
|
* to='pistol@shakespeare.lit/harfleur'
|
|
|
|
* type='unavailable'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='none' role='none'>
|
2016-12-03 17:39:59 +01:00
|
|
|
* <actor nick='Fluellen'/>
|
|
|
|
* <reason>Avaunt, you cullion!</reason>
|
2014-09-06 12:46:24 +02:00
|
|
|
* </item>
|
2016-12-03 17:39:59 +01:00
|
|
|
* <status code='110'/>
|
2014-09-06 12:46:24 +02:00
|
|
|
* <status code='307'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
2017-07-12 09:55:43 +02:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var presence = $pres().attrs({
|
|
|
|
from:'lounge@localhost/dummy',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'unavailable'
|
|
|
|
})
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'none',
|
|
|
|
jid: 'dummy@localhost/pda',
|
|
|
|
role: 'none'
|
|
|
|
})
|
|
|
|
.c('actor').attrs({nick: 'Fluellen'}).up()
|
|
|
|
.c('reason').t('Avaunt, you cullion!').up()
|
|
|
|
.up()
|
|
|
|
.c('status').attrs({code:'110'}).up()
|
|
|
|
.c('status').attrs({code:'307'}).nodeTree;
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-07-12 09:55:43 +02:00
|
|
|
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-01-03 20:02:05 +01:00
|
|
|
expect($(view.el.querySelector('.chat-area')).is(':visible')).toBeFalsy();
|
|
|
|
expect($(view.el.querySelector('.occupants')).is(':visible')).toBeFalsy();
|
|
|
|
var $chat_body = $(view.el.querySelector('.chatroom-body'));
|
2017-07-12 09:55:43 +02:00
|
|
|
expect($chat_body.find('.disconnect-msg').text()).toBe(
|
|
|
|
'You have been kicked from this room'+
|
|
|
|
'This action was done by Fluellen.'+
|
|
|
|
'The reason given is: "Avaunt, you cullion!".'
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-09-06 12:25:37 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be saved to, and retrieved from, browserStorage",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
2013-05-11 14:20:07 +02:00
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
|
|
// will be empty.
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var newchatboxes = new _converse.ChatBoxes();
|
2013-05-11 14:20:07 +02:00
|
|
|
expect(newchatboxes.length).toEqual(0);
|
2014-06-30 19:21:16 +02:00
|
|
|
// The chatboxes will then be fetched from browserStorage inside the
|
2013-05-11 14:20:07 +02:00
|
|
|
// onConnected method
|
|
|
|
newchatboxes.onConnected();
|
2015-03-04 22:27:11 +01:00
|
|
|
expect(newchatboxes.length).toEqual(2);
|
2014-06-30 19:21:16 +02:00
|
|
|
// Check that the chatrooms retrieved from browserStorage
|
2013-05-11 14:20:07 +02:00
|
|
|
// have the same attributes values as the original ones.
|
2015-10-25 18:49:35 +01:00
|
|
|
var attrs = ['id', 'box_id', 'visible'];
|
|
|
|
var new_attrs, old_attrs;
|
|
|
|
for (var i=0; i<attrs.length; i++) {
|
2017-01-26 15:49:02 +01:00
|
|
|
new_attrs = _.map(_.map(newchatboxes.models, 'attributes'), attrs[i]);
|
2016-12-20 10:30:20 +01:00
|
|
|
old_attrs = _.map(_.map(_converse.chatboxes.models, 'attributes'), attrs[i]);
|
2014-04-18 17:42:11 +02:00
|
|
|
// FIXME: should have have to sort here? Order must
|
|
|
|
// probably be the same...
|
|
|
|
// This should be fixed once the controlbox always opens
|
|
|
|
// only on the right.
|
|
|
|
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
|
2013-05-11 14:20:07 +02:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.render();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-08-29 12:29:16 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost'),
|
|
|
|
trimmed_chatboxes = _converse.minimized_chats;
|
2017-08-29 12:29:16 +02:00
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
spyOn(view, 'minimize').and.callThrough();
|
|
|
|
spyOn(view, 'maximize').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
view.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
|
|
|
|
expect(view.minimize).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
|
|
|
|
expect(u.isVisible(view.el)).toBeFalsy();
|
|
|
|
expect(view.model.get('minimized')).toBeTruthy();
|
|
|
|
expect(view.minimize).toHaveBeenCalled();
|
|
|
|
var trimmedview = trimmed_chatboxes.get(view.model.get('id'));
|
|
|
|
trimmedview.el.querySelector("a.restore-chat").click();
|
|
|
|
expect(view.maximize).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
|
|
|
|
expect(view.model.get('minimized')).toBeFalsy();
|
|
|
|
expect(_converse.emit.calls.count(), 3);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-03-14 20:35:43 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2018-02-08 09:49:05 +01:00
|
|
|
spyOn(view, 'close').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
2018-04-08 19:44:53 +02:00
|
|
|
spyOn(view.model, 'leave');
|
2018-02-08 09:49:05 +01:00
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
view.el.querySelector('.close-chatbox-button').click();
|
|
|
|
expect(view.close).toHaveBeenCalled();
|
2018-04-08 19:44:53 +02:00
|
|
|
expect(view.model.leave).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2018-02-08 09:49:05 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2016-05-28 10:55:03 +02:00
|
|
|
|
|
|
|
|
2015-10-12 16:23:05 +02:00
|
|
|
describe("Each chat room can take special commands", function () {
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
it("/help to show the available commands",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
|
|
|
var textarea = view.el.querySelector('.chat-textarea');
|
2018-01-03 20:02:05 +01:00
|
|
|
textarea.value = '/help This is the room subject';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
2018-04-27 13:47:44 +02:00
|
|
|
const info_messages = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(info_messages.length).toBe(17);
|
|
|
|
expect(info_messages.pop().textContent).toBe('/voice: Allow muted user to post messages');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/topic: Set room subject (alias for /subject)');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/subject: Set room subject');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/revoke: Revoke user\'s membership');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/owner: Grant ownership of this room');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/op: Grant moderator role to user');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/nick: Change your nickname');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/mute: Remove user\'s ability to post messages');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/member: Grant membership to a user');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/me: Write in 3rd person');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/kick: Kick user from room');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/help: Show this menu');
|
2017-12-14 14:23:14 +01:00
|
|
|
expect(info_messages.pop().textContent).toBe('/deop: Change user role to participant');
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(info_messages.pop().textContent).toBe('/clear: Remove messages');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/ban: Ban user from room');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/admin: Change user\'s affiliation to admin');
|
|
|
|
done();
|
2017-02-01 18:36:20 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
it("/topic to set the room topic",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_stanza;
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
2018-04-24 11:08:26 +02:00
|
|
|
spyOn(view, 'clearMessages');
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
|
|
sent_stanza = stanza;
|
|
|
|
});
|
|
|
|
// Check the alias /topic
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
textarea.value = '/topic This is the room subject';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.textContent).toBe('This is the room subject');
|
|
|
|
|
|
|
|
// Check /subject
|
2018-01-03 20:02:05 +01:00
|
|
|
textarea.value = '/subject This is a new subject';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(sent_stanza.textContent).toBe('This is a new subject');
|
|
|
|
expect(sent_stanza.outerHTML).toBe(
|
|
|
|
'<message to="lounge@localhost" from="dummy@localhost/resource" type="groupchat" xmlns="jabber:client">'+
|
|
|
|
'<subject xmlns="jabber:client">This is a new subject</subject>'+
|
|
|
|
'</message>');
|
|
|
|
|
|
|
|
// Check case insensitivity
|
2018-01-03 20:02:05 +01:00
|
|
|
textarea.value = '/Subject This is yet another subject';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(sent_stanza.textContent).toBe('This is yet another subject');
|
|
|
|
expect(sent_stanza.outerHTML).toBe(
|
|
|
|
'<message to="lounge@localhost" from="dummy@localhost/resource" type="groupchat" xmlns="jabber:client">'+
|
|
|
|
'<subject xmlns="jabber:client">This is yet another subject</subject>'+
|
|
|
|
'</message>');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-10-12 16:23:05 +02:00
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
it("/clear to clear messages",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
2018-04-24 11:08:26 +02:00
|
|
|
spyOn(view, 'clearMessages');
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/clear';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
2018-04-24 11:08:26 +02:00
|
|
|
expect(view.clearMessages).toHaveBeenCalled();
|
2017-12-06 22:10:54 +01:00
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-12-08 08:28:20 +01:00
|
|
|
}));
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
it("/owner to make a user an owner",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
2018-03-29 11:56:24 +02:00
|
|
|
spyOn(view.model, 'setAffiliation').and.callThrough();
|
2018-04-06 13:56:14 +02:00
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(view, 'validateRoleChangeCommand').and.callThrough();
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/owner';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(view.validateRoleChangeCommand).toHaveBeenCalled();
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage).toHaveBeenCalledWith(
|
2017-12-06 22:10:54 +01:00
|
|
|
"Error: the \"owner\" command takes two arguments, the user's nickname and optionally a reason.",
|
|
|
|
true
|
|
|
|
);
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.setAffiliation).not.toHaveBeenCalled();
|
2017-12-06 22:10:54 +01:00
|
|
|
|
|
|
|
// Call now with the correct amount of arguments.
|
|
|
|
// XXX: Calling onMessageSubmitted directly, trying
|
|
|
|
// again via triggering Event doesn't work for some weird
|
|
|
|
// reason.
|
|
|
|
view.onMessageSubmitted('/owner annoyingGuy@localhost You\'re responsible');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage.calls.count()).toBe(1);
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.setAffiliation).toHaveBeenCalled();
|
2017-12-06 22:10:54 +01:00
|
|
|
// Check that the member list now gets updated
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='owner' jid='annoyingGuy@localhost'>"+
|
|
|
|
"<reason>You're responsible</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-12-06 22:10:54 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("/ban to ban a user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
2018-03-29 11:56:24 +02:00
|
|
|
spyOn(view.model, 'setAffiliation').and.callThrough();
|
2018-04-06 13:56:14 +02:00
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(view, 'validateRoleChangeCommand').and.callThrough();
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/ban';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(view.validateRoleChangeCommand).toHaveBeenCalled();
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage).toHaveBeenCalledWith(
|
2017-12-06 22:10:54 +01:00
|
|
|
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.",
|
|
|
|
true
|
|
|
|
);
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.setAffiliation).not.toHaveBeenCalled();
|
2017-12-06 22:10:54 +01:00
|
|
|
// Call now with the correct amount of arguments.
|
|
|
|
// XXX: Calling onMessageSubmitted directly, trying
|
|
|
|
// again via triggering Event doesn't work for some weird
|
|
|
|
// reason.
|
|
|
|
view.onMessageSubmitted('/ban annoyingGuy@localhost You\'re annoying');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage.calls.count()).toBe(1);
|
2018-03-29 11:56:24 +02:00
|
|
|
expect(view.model.setAffiliation).toHaveBeenCalled();
|
2017-12-06 22:10:54 +01:00
|
|
|
// Check that the member list now gets updated
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='outcast' jid='annoyingGuy@localhost'>"+
|
|
|
|
"<reason>You're annoying</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-12-06 22:10:54 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("/kick to kick a user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
|
|
|
spyOn(view, 'modifyRole').and.callThrough();
|
2018-04-06 13:56:14 +02:00
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(view, 'validateRoleChangeCommand').and.callThrough();
|
2018-01-03 20:02:05 +01:00
|
|
|
|
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/kick';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(view.validateRoleChangeCommand).toHaveBeenCalled();
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage).toHaveBeenCalledWith(
|
2017-12-06 22:10:54 +01:00
|
|
|
"Error: the \"kick\" command takes two arguments, the user's nickname and optionally a reason.",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
expect(view.modifyRole).not.toHaveBeenCalled();
|
|
|
|
// Call now with the correct amount of arguments.
|
|
|
|
// XXX: Calling onMessageSubmitted directly, trying
|
|
|
|
// again via triggering Event doesn't work for some weird
|
|
|
|
// reason.
|
|
|
|
view.onMessageSubmitted('/kick annoyingGuy You\'re annoying');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage.calls.count()).toBe(1);
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.modifyRole).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item nick='annoyingGuy' role='none'>"+
|
|
|
|
"<reason>You're annoying</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='harfleur@chat.shakespeare.lit/pistol'
|
|
|
|
* to='gower@shakespeare.lit/cell'
|
|
|
|
* type='unavailable'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='none' role='none'/>
|
|
|
|
* <status code='307'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
2017-12-07 07:05:37 +01:00
|
|
|
var presence = $pres({
|
2017-12-06 22:10:54 +01:00
|
|
|
'from': 'lounge@localhost/annoyingGuy',
|
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'unavailable'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'role': 'none'
|
|
|
|
}).up()
|
|
|
|
.c('status', {'code': '307'});
|
2017-12-07 07:05:37 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(
|
2018-04-27 17:59:41 +02:00
|
|
|
view.el.querySelectorAll('.chat-info')[2].textContent).toBe(
|
2017-12-06 22:10:54 +01:00
|
|
|
"annoyingGuy has been kicked out");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-12-06 22:10:54 +01:00
|
|
|
}));
|
|
|
|
|
2017-12-14 14:23:14 +01:00
|
|
|
|
|
|
|
it("/op and /deop to make a user a moderator or not",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
|
|
|
spyOn(view, 'modifyRole').and.callThrough();
|
2018-04-06 13:56:14 +02:00
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
|
|
|
spyOn(view, 'showChatEvent').and.callThrough();
|
2017-12-14 14:23:14 +01:00
|
|
|
spyOn(view, 'validateRoleChangeCommand').and.callThrough();
|
|
|
|
|
|
|
|
// New user enters the room
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* id='27C55F89-1C6A-459A-9EB5-77690145D624'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member' role='moderator'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
'from': 'lounge@localhost/trustworthyguy',
|
|
|
|
'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'trustworthyguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
var info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(info_msgs.pop().textContent).toBe("trustworthyguy has entered the room");
|
2017-12-14 14:23:14 +01:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/op';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-12-14 14:23:14 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(view.validateRoleChangeCommand).toHaveBeenCalled();
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage).toHaveBeenCalledWith(
|
2017-12-14 14:23:14 +01:00
|
|
|
"Error: the \"op\" command takes two arguments, the user's nickname and optionally a reason.",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(view.modifyRole).not.toHaveBeenCalled();
|
|
|
|
// Call now with the correct amount of arguments.
|
|
|
|
// XXX: Calling onMessageSubmitted directly, trying
|
|
|
|
// again via triggering Event doesn't work for some weird
|
|
|
|
// reason.
|
|
|
|
view.onMessageSubmitted('/op trustworthyguy You\'re trustworthy');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage.calls.count()).toBe(1);
|
2017-12-14 14:23:14 +01:00
|
|
|
expect(view.modifyRole).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item nick='trustworthyguy' role='moderator'>"+
|
|
|
|
"<reason>You're trustworthy</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* role='moderator'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
presence = $pres({
|
|
|
|
'from': 'lounge@localhost/trustworthyguy',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'trustworthyguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'moderator'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(info_msgs.pop().textContent).toBe("trustworthyguy is now a moderator");
|
2017-12-14 14:23:14 +01:00
|
|
|
|
|
|
|
view.onMessageSubmitted('/deop trustworthyguy Perhaps not');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showChatEvent.calls.count()).toBe(1);
|
2017-12-14 14:23:14 +01:00
|
|
|
expect(view.modifyRole).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item nick='trustworthyguy' role='participant'>"+
|
|
|
|
"<reason>Perhaps not</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* role='participant'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
presence = $pres({
|
|
|
|
'from': 'lounge@localhost/trustworthyguy',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
}).c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'trustworthyguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(info_msgs.pop().textContent).toBe("trustworthyguy is no longer a moderator");
|
2017-12-14 14:23:14 +01:00
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2017-12-14 14:23:14 +01:00
|
|
|
}));
|
|
|
|
|
2017-12-14 14:07:39 +01:00
|
|
|
it("/mute and /voice to mute and unmute a user",
|
2017-12-06 22:10:54 +01:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
|
|
|
var sent_IQ, IQ_id;
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_IQ = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
|
|
|
spyOn(view, 'modifyRole').and.callThrough();
|
2018-04-06 13:56:14 +02:00
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
|
|
|
spyOn(view, 'showChatEvent').and.callThrough();
|
2017-12-06 22:10:54 +01:00
|
|
|
spyOn(view, 'validateRoleChangeCommand').and.callThrough();
|
2017-12-07 07:05:37 +01:00
|
|
|
|
|
|
|
// New user enters the room
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* id='27C55F89-1C6A-459A-9EB5-77690145D624'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member' role='participant'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
'from': 'lounge@localhost/annoyingGuy',
|
|
|
|
'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'annoyingguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
var info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(info_msgs.pop().textContent).toBe("annoyingGuy has entered the room");
|
2017-12-07 07:05:37 +01:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
var textarea = view.el.querySelector('.chat-textarea')
|
|
|
|
textarea.value = '/mute';
|
|
|
|
view.keyPressed({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
|
|
|
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
|
|
|
expect(view.validateRoleChangeCommand).toHaveBeenCalled();
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage).toHaveBeenCalledWith(
|
2017-12-06 22:10:54 +01:00
|
|
|
"Error: the \"mute\" command takes two arguments, the user's nickname and optionally a reason.",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
expect(view.modifyRole).not.toHaveBeenCalled();
|
|
|
|
// Call now with the correct amount of arguments.
|
|
|
|
// XXX: Calling onMessageSubmitted directly, trying
|
|
|
|
// again via triggering Event doesn't work for some weird
|
|
|
|
// reason.
|
|
|
|
view.onMessageSubmitted('/mute annoyingGuy You\'re annoying');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showErrorMessage.calls.count()).toBe(1);
|
2017-12-06 22:10:54 +01:00
|
|
|
expect(view.modifyRole).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item nick='annoyingGuy' role='visitor'>"+
|
|
|
|
"<reason>You're annoying</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
2017-12-07 07:05:37 +01:00
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* role='visitor'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
presence = $pres({
|
|
|
|
'from': 'lounge@localhost/annoyingGuy',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'annoyingguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'visitor'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(info_msgs.pop().textContent).toBe("annoyingGuy has been muted");
|
2017-12-14 14:07:39 +01:00
|
|
|
|
|
|
|
view.onMessageSubmitted('/voice annoyingGuy Now you can talk again');
|
|
|
|
expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.showChatEvent.calls.count()).toBe(1);
|
2017-12-14 14:07:39 +01:00
|
|
|
expect(view.modifyRole).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
"<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item nick='annoyingGuy' role='participant'>"+
|
|
|
|
"<reason>Now you can talk again</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit/pda'
|
|
|
|
* role='visitor'/>
|
|
|
|
* </x>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
presence = $pres({
|
|
|
|
'from': 'lounge@localhost/annoyingGuy',
|
|
|
|
'to': 'dummy@localhost/desktop'
|
|
|
|
})
|
|
|
|
.c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item', {
|
|
|
|
'jid': 'annoyingguy@localhost',
|
|
|
|
'affiliation': 'member',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(info_msgs.pop().textContent).toBe("annoyingGuy has been given a voice again");
|
2017-12-06 22:10:54 +01:00
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("When attempting to enter a chatroom", function () {
|
2016-11-21 13:55:19 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the room requires a password",
|
|
|
|
mock.initConverseWithPromises(
|
2018-03-11 13:56:53 +01:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
2018-04-08 19:44:53 +02:00
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'renderPasswordForm').and.callThrough();
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'auth'})
|
2018-04-08 19:44:53 +02:00
|
|
|
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'});
|
2018-03-11 13:56:53 +01:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
|
|
|
|
var $chat_body = $(view.el).find('.chatroom-body');
|
|
|
|
expect(view.renderPasswordForm).toHaveBeenCalled();
|
|
|
|
expect($chat_body.find('form.chatroom-form').length).toBe(1);
|
|
|
|
expect($chat_body.find('legend').text()).toBe('This chatroom requires a password');
|
|
|
|
|
|
|
|
// Let's submit the form
|
|
|
|
spyOn(view, 'join');
|
|
|
|
var input_el = view.el.querySelector('[name="password"]');
|
|
|
|
input_el.value = 'secret';
|
|
|
|
view.el.querySelector('input[type=submit]').click();
|
|
|
|
expect(view.join).toHaveBeenCalledWith('dummy', 'secret');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the room is members-only and the user not included",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'auth'})
|
|
|
|
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe('You are not on the member list of this room.');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the user has been banned",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'auth'})
|
|
|
|
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe('You have been banned from this room.');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'cancel'})
|
|
|
|
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body form.chatroom-form label:first').text()).toBe('Please choose your nickname');
|
|
|
|
|
|
|
|
var $input = $(view.el).find('.chatroom-body form.chatroom-form input:first');
|
|
|
|
$input.val('nicky');
|
|
|
|
view.el.querySelector('input[type=submit]').click();
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-08-11 14:00:52 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
/* <presence
|
|
|
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
|
|
|
* id='n13mt3l'
|
|
|
|
* to='hag66@shakespeare.lit/pda'
|
|
|
|
* type='error'>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc'/>
|
|
|
|
* <error by='coven@chat.shakespeare.lit' type='cancel'>
|
|
|
|
* <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
|
|
|
* </error>
|
|
|
|
* </presence>
|
|
|
|
*/
|
|
|
|
_converse.muc_nickname_from_jid = true;
|
2016-08-11 14:00:52 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
var attrs = {
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
2018-03-11 13:56:53 +01:00
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'
|
|
|
|
};
|
2018-04-08 19:44:53 +02:00
|
|
|
attrs.id = new Date().getTime();
|
2018-03-11 13:56:53 +01:00
|
|
|
var presence = $pres().attrs(attrs)
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
2018-04-08 19:44:53 +02:00
|
|
|
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
|
|
|
spyOn(view, 'join').and.callThrough();
|
|
|
|
|
|
|
|
// Simulate repeatedly that there's already someone in the room
|
|
|
|
// with that nickname
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(view.join).toHaveBeenCalledWith('dummy-2');
|
2016-08-11 14:00:52 +02:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
attrs.from = 'problematic@muc.localhost/dummy-2';
|
|
|
|
attrs.id = new Date().getTime();
|
2018-03-11 13:56:53 +01:00
|
|
|
presence = $pres().attrs(attrs)
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
2018-04-08 19:44:53 +02:00
|
|
|
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2016-08-11 14:00:52 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(view.join).toHaveBeenCalledWith('dummy-3');
|
2016-08-11 14:00:52 +02:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
attrs.from = 'problematic@muc.localhost/dummy-3';
|
|
|
|
attrs.id = new Date().getTime();
|
2018-03-11 13:56:53 +01:00
|
|
|
presence = $pres().attrs(attrs)
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
2018-04-08 19:44:53 +02:00
|
|
|
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(view.join).toHaveBeenCalledWith('dummy-4');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the user is not allowed to have created the room",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'cancel'})
|
|
|
|
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe('You are not allowed to create new rooms.');
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the user's nickname doesn't conform to room policy",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'cancel'})
|
|
|
|
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe("Your nickname doesn't conform to this room's policies.");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the room doesn't yet exist",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
2018-03-11 13:56:53 +01:00
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'cancel'})
|
|
|
|
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe("This room does not (yet) exist.");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-05-11 14:20:07 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show an error message if the room has reached its maximum number of occupants",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
|
|
|
|
.then(function () {
|
|
|
|
var presence = $pres().attrs({
|
2018-04-08 19:44:53 +02:00
|
|
|
from:'problematic@muc.localhost/dummy',
|
2018-03-11 13:56:53 +01:00
|
|
|
id:'n13mt3l',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'error'})
|
|
|
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('error').attrs({by:'lounge@localhost', type:'cancel'})
|
|
|
|
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
|
|
|
var view = _converse.chatboxviews.get('problematic@muc.localhost');
|
|
|
|
spyOn(view, 'showErrorMessage').and.callThrough();
|
2018-04-08 19:44:53 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-03-11 13:56:53 +01:00
|
|
|
expect($(view.el).find('.chatroom-body p:last').text()).toBe("This room has reached its maximum number of occupants.");
|
|
|
|
done();
|
2018-04-24 11:07:32 +02:00
|
|
|
}).catch(_.partial(console.error, _));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2016-12-05 11:50:01 +01:00
|
|
|
|
|
|
|
describe("Someone being invited to a chat room", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will first be added to the member list if the chat room is members only",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-05-12 19:37:44 +02:00
|
|
|
var muc_iq;
|
2016-12-06 19:34:54 +01:00
|
|
|
var sent_IQs = [], IQ_ids = [];
|
2018-06-30 13:46:56 +02:00
|
|
|
var invitee_jid, sent_stanza, sent_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2016-12-06 19:34:54 +01:00
|
|
|
sent_IQs.push(iq);
|
|
|
|
IQ_ids.push(sendIQ.bind(this)(iq, callback, errback));
|
2016-12-05 11:50:01 +01:00
|
|
|
});
|
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'dummy'});
|
2016-12-05 11:50:01 +01:00
|
|
|
|
2018-06-30 13:46:56 +02:00
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
spyOn(view.model, 'parseRoomFeatures').and.callThrough();
|
|
|
|
|
2016-12-05 11:50:01 +01:00
|
|
|
// State that the chat is members-only via the features IQ
|
|
|
|
var features_stanza = $iq({
|
|
|
|
from: 'coven@chat.shakespeare.lit',
|
2016-12-06 19:34:54 +01:00
|
|
|
'id': IQ_ids.pop(),
|
2016-12-05 11:50:01 +01:00
|
|
|
'to': 'dummy@localhost/desktop',
|
|
|
|
'type': 'result'
|
|
|
|
})
|
|
|
|
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'name': 'A Dark Cave',
|
|
|
|
'type': 'text'
|
|
|
|
}).up()
|
|
|
|
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
|
|
|
.c('feature', {'var': 'muc_hidden'}).up()
|
|
|
|
.c('feature', {'var': 'muc_temporary'}).up()
|
|
|
|
.c('feature', {'var': 'muc_membersonly'}).up();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
|
2016-12-05 11:50:01 +01:00
|
|
|
|
2018-06-30 13:46:56 +02:00
|
|
|
test_utils.waitUntil(() => view.model.parseRoomFeatures.calls.count(), 300)
|
|
|
|
.then(() => {
|
|
|
|
expect(view.model.get('membersonly')).toBeTruthy();
|
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
|
|
if (stanza.nodeTree && stanza.nodeTree.nodeName === 'message') {
|
|
|
|
sent_id = stanza.nodeTree.getAttribute('id');
|
|
|
|
sent_stanza = stanza;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var name = mock.cur_names[0];
|
|
|
|
invitee_jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var reason = "Please join this chat room";
|
|
|
|
view.model.directInvite(invitee_jid, reason);
|
|
|
|
|
|
|
|
// Check in reverse order that we requested all three lists
|
|
|
|
// (member, owner and admin).
|
|
|
|
var admin_iq_id = IQ_ids.pop();
|
|
|
|
var owner_iq_id = IQ_ids.pop();
|
|
|
|
var member_iq_id = IQ_ids.pop();
|
|
|
|
|
|
|
|
expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
"<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+admin_iq_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='admin'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
"<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+owner_iq_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='owner'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
"<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+member_iq_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='member'/>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>");
|
|
|
|
|
|
|
|
/* Now the service sends the member list to the user
|
|
|
|
*
|
|
|
|
* <iq from='coven@chat.shakespeare.lit'
|
|
|
|
* id='member3'
|
|
|
|
* to='crone1@shakespeare.lit/desktop'
|
|
|
|
* type='result'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/muc#admin'>
|
|
|
|
* <item affiliation='member'
|
|
|
|
* jid='hag66@shakespeare.lit'
|
|
|
|
* nick='thirdwitch'
|
|
|
|
* role='participant'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var member_list_stanza = $iq({
|
|
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
|
|
'id': member_iq_id,
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
'type': 'result'
|
|
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'member',
|
|
|
|
'jid': 'hag66@shakespeare.lit',
|
|
|
|
'nick': 'thirdwitch',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(member_list_stanza));
|
|
|
|
|
|
|
|
var admin_list_stanza = $iq({
|
|
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
|
|
'id': admin_iq_id,
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
'type': 'result'
|
|
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'admin',
|
|
|
|
'jid': 'wiccarocks@shakespeare.lit',
|
|
|
|
'nick': 'secondwitch'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(admin_list_stanza));
|
|
|
|
|
|
|
|
var owner_list_stanza = $iq({
|
|
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
|
|
'id': owner_iq_id,
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
'type': 'result'
|
|
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'owner',
|
|
|
|
'jid': 'crone1@shakespeare.lit',
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(owner_list_stanza));
|
|
|
|
return test_utils.waitUntil(() => IQ_ids.length, 300);
|
|
|
|
}).then(() => {
|
2017-07-12 09:55:43 +02:00
|
|
|
// Check that the member list now gets updated
|
2018-05-12 19:37:44 +02:00
|
|
|
expect(muc_iq.toLocaleString()).toBe("<iq to='coven@chat.shakespeare.lit' type='set' xmlns='jabber:client' id='"+muc_iq.nodeTree.getAttribute('id')+"'>"+
|
2017-07-12 09:55:43 +02:00
|
|
|
"<query xmlns='http://jabber.org/protocol/muc#admin'>"+
|
|
|
|
"<item affiliation='member' jid='"+invitee_jid+"'>"+
|
|
|
|
"<reason>Please join this chat room</reason>"+
|
|
|
|
"</item>"+
|
|
|
|
"</query>"+
|
2018-05-12 19:37:44 +02:00
|
|
|
"</iq>");
|
|
|
|
// Finally check that the user gets invited.
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
|
|
|
"<message from='dummy@localhost/resource' to='"+invitee_jid+"' id='"+sent_id+"' xmlns='jabber:client'>"+
|
|
|
|
"<x xmlns='jabber:x:conference' jid='coven@chat.shakespeare.lit' reason='Please join this chat room'/>"+
|
|
|
|
"</message>");
|
|
|
|
done();
|
2017-07-12 09:55:43 +02:00
|
|
|
});
|
2016-12-05 11:50:01 +01:00
|
|
|
}));
|
|
|
|
});
|
2016-12-08 13:44:18 +01:00
|
|
|
|
|
|
|
describe("The affiliations delta", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be computed in various ways",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'dummy');
|
|
|
|
var roomview = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
2016-12-08 13:44:18 +01:00
|
|
|
|
|
|
|
var exclude_existing = false;
|
|
|
|
var remove_absentees = false;
|
|
|
|
var new_list = [];
|
|
|
|
var old_list = [];
|
2018-03-29 11:56:24 +02:00
|
|
|
var delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(0);
|
|
|
|
|
|
|
|
new_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
|
|
|
|
old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(0);
|
|
|
|
|
|
|
|
// When remove_absentees is false, then affiliations in the old
|
|
|
|
// list which are not in the new one won't be removed.
|
|
|
|
old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
|
|
|
|
{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(0);
|
|
|
|
|
|
|
|
// With exclude_existing set to false, any changed affiliations
|
|
|
|
// will be included in the delta (i.e. existing affiliations
|
|
|
|
// are included in the comparison).
|
|
|
|
old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(1);
|
|
|
|
expect(delta[0].jid).toBe('wiccarocks@shakespeare.lit');
|
|
|
|
expect(delta[0].affiliation).toBe('member');
|
|
|
|
|
|
|
|
// To also remove affiliations from the old list which are not
|
|
|
|
// in the new list, we set remove_absentees to true
|
|
|
|
remove_absentees = true;
|
|
|
|
old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
|
|
|
|
{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(1);
|
|
|
|
expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
|
|
|
|
expect(delta[0].affiliation).toBe('none');
|
|
|
|
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, [], old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(2);
|
|
|
|
expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
|
|
|
|
expect(delta[0].affiliation).toBe('none');
|
|
|
|
expect(delta[1].jid).toBe('wiccarocks@shakespeare.lit');
|
|
|
|
expect(delta[1].affiliation).toBe('none');
|
|
|
|
|
|
|
|
// To only add a user if they don't already have an
|
|
|
|
// affiliation, we set 'exclude_existing' to true
|
|
|
|
exclude_existing = true;
|
|
|
|
old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
|
2018-03-29 11:56:24 +02:00
|
|
|
delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
|
2016-12-08 13:44:18 +01:00
|
|
|
expect(delta.length).toBe(0);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-12-08 13:44:18 +01:00
|
|
|
}));
|
|
|
|
});
|
2017-06-05 14:50:29 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
describe("The \"Chatrooms\" section", function () {
|
2017-06-05 21:42:25 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
it("contains a link to a modal through which a new chatroom can be created",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
2018-05-30 16:38:51 +02:00
|
|
|
roomspanel.el.querySelector('.show-add-muc-modal').click();
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.closeControlBox(_converse);
|
|
|
|
const modal = roomspanel.add_room_modal;
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(modal.el);
|
|
|
|
}, 1000).then(function () {
|
2018-04-08 19:44:53 +02:00
|
|
|
spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
|
2018-03-11 13:56:53 +01:00
|
|
|
var deferred = new $.Deferred();
|
|
|
|
deferred.resolve();
|
|
|
|
return deferred.promise();
|
|
|
|
});
|
|
|
|
roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2017-06-05 21:42:25 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
modal.el.querySelector('input[name="chatroom"]').value = 'lounce@muc.localhost';
|
|
|
|
modal.el.querySelector('form input[type="submit"]').click();
|
|
|
|
expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
|
|
|
|
done();
|
|
|
|
}).catch(_.partial(console.error, _));
|
2017-06-05 21:42:25 +02:00
|
|
|
}));
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
it("contains a link to a modal which can list rooms publically available on the server",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
|
2018-03-02 11:59:25 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
var sent_stanza, IQ_id;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
test_utils.openControlBox();
|
2018-03-11 13:56:53 +01:00
|
|
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
2018-05-30 16:38:51 +02:00
|
|
|
roomspanel.el.querySelector('.show-list-muc-modal').click();
|
2018-03-11 13:56:53 +01:00
|
|
|
test_utils.closeControlBox(_converse);
|
|
|
|
const modal = roomspanel.list_rooms_modal;
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(modal.el);
|
|
|
|
}, 1000).then(function () {
|
2018-04-08 19:44:53 +02:00
|
|
|
spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
|
2018-03-11 13:56:53 +01:00
|
|
|
var deferred = new $.Deferred();
|
|
|
|
deferred.resolve();
|
|
|
|
return deferred.promise();
|
|
|
|
});
|
|
|
|
roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
|
|
|
|
// See: http://xmpp.org/extensions/xep-0045.html#disco-rooms
|
|
|
|
expect(modal.el.querySelectorAll('.available-chatrooms li').length).toBe(0);
|
2018-01-03 13:55:57 +01:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
const input = modal.el.querySelector('input[name="server"]').value = 'chat.shakespear.lit';
|
|
|
|
modal.el.querySelector('input[type="submit"]').click();
|
|
|
|
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq to='chat.shakespear.lit' from='dummy@localhost/resource' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<query xmlns='http://jabber.org/protocol/disco#items'/>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
|
|
|
|
var iq = $iq({
|
|
|
|
from:'muc.localhost',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
id: IQ_id,
|
|
|
|
type:'result'
|
|
|
|
}).c('query')
|
|
|
|
.c('item', { jid:'heath@chat.shakespeare.lit', name:'A Lonely Heath'}).up()
|
|
|
|
.c('item', { jid:'coven@chat.shakespeare.lit', name:'A Dark Cave'}).up()
|
|
|
|
.c('item', { jid:'forres@chat.shakespeare.lit', name:'The Palace'}).up()
|
|
|
|
.c('item', { jid:'inverness@chat.shakespeare.lit', name:'Macbeth's Castle'}).nodeTree;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(iq));
|
|
|
|
|
|
|
|
expect(modal.el.querySelectorAll('.available-chatrooms li').length).toBe(5);
|
|
|
|
|
|
|
|
const rooms = modal.el.querySelectorAll('.available-chatrooms li');
|
|
|
|
expect(rooms[0].textContent.trim()).toBe("Rooms found:");
|
|
|
|
expect(rooms[1].textContent.trim()).toBe("A Lonely Heath");
|
|
|
|
expect(rooms[2].textContent.trim()).toBe("A Dark Cave");
|
|
|
|
expect(rooms[3].textContent.trim()).toBe("The Palace");
|
|
|
|
expect(rooms[4].textContent.trim()).toBe("Macbeth's Castle");
|
|
|
|
|
|
|
|
rooms[4].querySelector('.open-room').click();
|
|
|
|
expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
|
|
|
|
var view = _converse.chatboxviews.get('inverness@chat.shakespeare.lit');
|
|
|
|
expect(view.el.querySelector('.chat-head-chatroom').textContent.trim()).toBe("Macbeth's Castle");
|
|
|
|
done();
|
|
|
|
}).catch(_.partial(console.error, _));
|
|
|
|
}));
|
2017-06-05 21:42:25 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the number of unread mentions received",
|
|
|
|
mock.initConverseWithPromises(
|
2018-03-11 13:56:53 +01:00
|
|
|
null, ['rosterGroupsFetched'], {'allow_bookmarks': false},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
2018-03-11 13:56:53 +01:00
|
|
|
// XXX: we set `allow_bookmarks` to false, so that the rooms
|
|
|
|
// list gets rendered. Otherwise we would have to mock
|
|
|
|
// the bookmark stanza exchange.
|
|
|
|
|
|
|
|
test_utils.openControlBox();
|
|
|
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
|
|
|
expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(0);
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-06-05 14:50:29 +02:00
|
|
|
var room_jid = 'kitchen@conference.shakespeare.lit';
|
|
|
|
test_utils.openAndEnterChatRoom(
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse, 'kitchen', 'conference.shakespeare.lit', 'fires').then(function () {
|
2017-06-07 00:55:25 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(0);
|
2017-06-05 14:50:29 +02:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
var view = _converse.chatboxviews.get(room_jid);
|
|
|
|
view.model.set({'minimized': true});
|
2017-06-05 14:50:29 +02:00
|
|
|
|
2017-07-12 09:55:43 +02:00
|
|
|
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var message = 'fires: Your attention is required';
|
2018-04-30 15:24:37 +02:00
|
|
|
var nick = mock.chatroom_names[0];
|
|
|
|
|
|
|
|
view.model.onMessage($msg({
|
2017-07-12 09:55:43 +02:00
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
2018-04-30 15:24:37 +02:00
|
|
|
}).c('body').t(message).tree());
|
2017-06-05 14:50:29 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelector('.msgs-indicator').textContent).toBe('1');
|
2017-06-07 00:55:25 +02:00
|
|
|
|
2018-04-30 15:24:37 +02:00
|
|
|
view.model.onMessage($msg({
|
|
|
|
'from': room_jid+'/'+nick,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': 'dummy@localhost',
|
|
|
|
'type': 'groupchat'
|
|
|
|
}).c('body').t(message).tree());
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelector('.msgs-indicator').textContent).toBe('2');
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
view.model.set({'minimized': false});
|
|
|
|
|
|
|
|
expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
|
|
|
|
expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(0);
|
|
|
|
done();
|
2017-07-12 09:55:43 +02:00
|
|
|
});
|
2017-06-05 14:50:29 +02:00
|
|
|
}));
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
describe("A Chat Status Notification", function () {
|
|
|
|
|
|
|
|
describe("A composing notification", function () {
|
|
|
|
|
|
|
|
it("will be shown if received",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(
|
|
|
|
_converse, 'coven', 'chat.shakespeare.lit', 'some1').then(function () {
|
|
|
|
|
|
|
|
var room_jid = 'coven@chat.shakespeare.lit';
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
|
|
|
|
|
|
|
/* <presence to="dummy@localhost/_converse.js-29092160"
|
|
|
|
* from="coven@chat.shakespeare.lit/some1">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence></body>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'owner',
|
|
|
|
'jid': 'dummy@localhost/_converse.js-29092160',
|
|
|
|
'role': 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status', {code: '110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(2);
|
|
|
|
expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the room");
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("some1 is now a moderator");
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the room");
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/nomorenicks'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'nomorenicks@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(4);
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the room");
|
|
|
|
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
|
|
|
|
|
|
|
// <composing> state
|
|
|
|
var msg = $msg({
|
|
|
|
from: room_jid+'/newguy',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-17 15:17:39 +02:00
|
|
|
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
// Check that the notification appears inside the chatbox in the DOM
|
|
|
|
var events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(4);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('some1 is now a moderator');
|
|
|
|
expect(events[2].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[3].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
var notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(1);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
|
|
|
|
const timeout_functions = [];
|
|
|
|
spyOn(window, 'setTimeout').and.callFake(function (func, delay) {
|
|
|
|
timeout_functions.push(func);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check that it doesn't appear twice
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/newguy',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(4);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('some1 is now a moderator');
|
|
|
|
expect(events[2].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[3].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(1);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
|
|
|
|
expect(timeout_functions.length).toBe(1);
|
|
|
|
|
|
|
|
// <composing> state for a different occupant
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/nomorenicks',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(4);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('some1 is now a moderator');
|
|
|
|
expect(events[2].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[3].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(2);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
expect(notifications[1].textContent).toEqual('nomorenicks is typing');
|
|
|
|
expect(timeout_functions.length).toBe(2);
|
|
|
|
|
|
|
|
// Check that new messages appear under the chat state
|
|
|
|
// notifications
|
|
|
|
msg = $msg({
|
|
|
|
from: 'lounge@localhost/some1',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('hello world').tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
var messages = view.el.querySelectorAll('.message');
|
|
|
|
expect(messages.length).toBe(8);
|
2018-04-27 16:58:49 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelector('.chat-msg .chat-msg-text').textContent).toBe('hello world');
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
// Test that the composing notifications get removed
|
|
|
|
// via timeout.
|
|
|
|
timeout_functions[0]();
|
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(4);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('some1 is now a moderator');
|
|
|
|
expect(events[2].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[3].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(1);
|
|
|
|
expect(notifications[0].textContent).toEqual('nomorenicks is typing');
|
|
|
|
|
|
|
|
timeout_functions[1]();
|
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(4);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('some1 is now a moderator');
|
|
|
|
expect(events[2].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[3].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("A paused notification", function () {
|
|
|
|
it("will be shown if received",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1');
|
|
|
|
var room_jid = 'coven@chat.shakespeare.lit';
|
|
|
|
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
var $chat_content = $(view.el).find('.chat-content');
|
|
|
|
|
|
|
|
/* <presence to="dummy@localhost/_converse.js-29092160"
|
|
|
|
* from="coven@chat.shakespeare.lit/some1">
|
|
|
|
* <x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
* <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
|
|
|
|
* <status code="110"/>
|
|
|
|
* </x>
|
|
|
|
* </presence></body>
|
|
|
|
*/
|
|
|
|
var presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1'
|
|
|
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'owner',
|
|
|
|
'jid': 'dummy@localhost/_converse.js-29092160',
|
|
|
|
'role': 'moderator'
|
|
|
|
}).up()
|
|
|
|
.c('status', {code: '110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the room");
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'newguy@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(2);
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the room");
|
|
|
|
|
|
|
|
presence = $pres({
|
|
|
|
to: 'dummy@localhost/_converse.js-29092160',
|
|
|
|
from: 'coven@chat.shakespeare.lit/nomorenicks'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': 'nomorenicks@localhost/_converse.js-290929789',
|
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
|
|
|
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the room");
|
|
|
|
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
|
|
|
|
|
|
|
// <composing> state
|
|
|
|
var msg = $msg({
|
|
|
|
from: room_jid+'/newguy',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
// Check that the notification appears inside the chatbox in the DOM
|
|
|
|
var events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[2].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
var notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(1);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
|
|
|
|
// Check that it doesn't appear twice
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/newguy',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
|
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[2].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(1);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
|
|
|
|
// <composing> state for a different occupant
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/nomorenicks',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[2].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(2);
|
|
|
|
expect(notifications[0].textContent).toEqual('newguy is typing');
|
|
|
|
expect(notifications[1].textContent).toEqual('nomorenicks is typing');
|
|
|
|
|
|
|
|
// <paused> state from occupant who typed first
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/newguy',
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2018-04-06 13:56:14 +02:00
|
|
|
events = view.el.querySelectorAll('.chat-event');
|
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[0].textContent).toEqual('some1 has entered the room');
|
|
|
|
expect(events[1].textContent).toEqual('newguy has entered the room');
|
|
|
|
expect(events[2].textContent).toEqual('nomorenicks has entered the room');
|
|
|
|
|
|
|
|
notifications = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(notifications.length).toBe(2);
|
|
|
|
expect(notifications[0].textContent).toEqual('nomorenicks is typing');
|
|
|
|
expect(notifications[1].textContent).toEqual('newguy has stopped typing');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2017-06-05 14:50:29 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2013-05-11 14:20:07 +02:00
|
|
|
}));
|