2017-05-16 11:56:40 +02:00
|
|
|
(function (root, factory) {
|
2017-06-19 11:08:57 +02:00
|
|
|
define(["jasmine", "mock", "converse-core", "converse-roomslist", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, converse, roomslist, test_utils) {
|
2017-05-16 11:56:40 +02:00
|
|
|
var _ = converse.env._;
|
2017-05-23 20:42:12 +02:00
|
|
|
var $msg = converse.env.$msg;
|
2017-05-16 11:56:40 +02:00
|
|
|
|
|
|
|
describe("The converse-roomslist plugin", function () {
|
|
|
|
|
2017-05-23 14:39:35 +02:00
|
|
|
it("is shown under a list of open rooms in the \"Rooms\" panel", mock.initConverse(
|
2017-05-16 11:56:40 +02:00
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
|
|
|
},
|
|
|
|
function (_converse) {
|
2017-05-16 13:31:31 +02:00
|
|
|
test_utils.openControlBox().openRoomsPanel(_converse);
|
|
|
|
var controlbox = _converse.chatboxviews.get('controlbox');
|
|
|
|
|
|
|
|
var list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeTruthy();
|
|
|
|
|
2017-05-16 11:56:40 +02:00
|
|
|
test_utils.openChatRoom(
|
2017-05-16 13:31:31 +02:00
|
|
|
_converse, 'room', 'conference.shakespeare.lit', 'JC');
|
2017-05-16 11:56:40 +02:00
|
|
|
|
|
|
|
expect(_.isUndefined(_converse.rooms_list_view)).toBeFalsy();
|
|
|
|
var room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(1);
|
2017-05-16 13:31:31 +02:00
|
|
|
expect(room_els[0].innerText).toBe('room');
|
2017-05-16 11:56:40 +02:00
|
|
|
|
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(2);
|
2017-05-16 13:31:31 +02:00
|
|
|
|
|
|
|
var view = _converse.chatboxviews.get('room@conference.shakespeare.lit');
|
|
|
|
view.close();
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
expect(room_els[0].innerText).toBe('lounge');
|
|
|
|
list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeFalsy();
|
|
|
|
|
|
|
|
view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
view.close();
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(0);
|
|
|
|
|
|
|
|
list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeTruthy();
|
2017-05-16 11:56:40 +02:00
|
|
|
}
|
|
|
|
));
|
|
|
|
});
|
2017-05-23 14:39:35 +02:00
|
|
|
|
2017-05-23 20:42:12 +02:00
|
|
|
describe("An room shown in the rooms list", function () {
|
|
|
|
|
2017-05-23 14:39:35 +02:00
|
|
|
it("can be closed", mock.initConverse(
|
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
|
|
|
},
|
|
|
|
function (_converse) {
|
2017-05-23 20:42:12 +02:00
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.callFake(function () {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
expect(_converse.chatboxes.length).toBe(1);
|
|
|
|
test_utils.openChatRoom(
|
|
|
|
_converse, 'lounge', 'conference.shakespeare.lit', 'JC');
|
|
|
|
expect(_converse.chatboxes.length).toBe(2);
|
|
|
|
test_utils.openControlBox().openRoomsPanel(_converse);
|
|
|
|
var room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
var close_el = _converse.rooms_list_view.el.querySelector(".close-room");
|
|
|
|
close_el.click();
|
|
|
|
expect(window.confirm).toHaveBeenCalledWith(
|
|
|
|
'Are you sure you want to leave the room ""?');
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(0);
|
|
|
|
expect(_converse.chatboxes.length).toBe(1);
|
|
|
|
}));
|
2017-05-24 08:40:09 +02:00
|
|
|
|
|
|
|
it("shows unread messages directed at the user", mock.initConverse(
|
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
|
|
|
}, function (_converse) {
|
|
|
|
|
|
|
|
var room_jid = 'kitchen@conference.shakespeare.lit';
|
|
|
|
test_utils.openAndEnterChatRoom(
|
|
|
|
_converse, 'kitchen', 'conference.shakespeare.lit', 'romeo');
|
|
|
|
var view = _converse.chatboxviews.get(room_jid);
|
|
|
|
view.model.set({'minimized': true});
|
|
|
|
|
|
|
|
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var nick = mock.chatroom_names[0];
|
|
|
|
view.handleMUCMessage(
|
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('foo').tree());
|
|
|
|
|
|
|
|
// If the user isn't mentioned, the counter doesn't get incremented, but the text of the room is bold
|
|
|
|
var room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
|
|
|
|
expect(_.includes(room_el.classList, 'unread-msgs'));
|
|
|
|
|
|
|
|
// If the user is mentioned, the counter also gets updated
|
|
|
|
view.handleMUCMessage(
|
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('romeo: Your attention is required').tree()
|
|
|
|
);
|
2017-06-05 14:50:29 +02:00
|
|
|
var indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
2017-05-24 08:40:09 +02:00
|
|
|
expect(indicator_el.textContent).toBe('1');
|
2017-05-24 09:06:17 +02:00
|
|
|
|
|
|
|
view.handleMUCMessage(
|
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('romeo: and another thing...').tree()
|
|
|
|
);
|
2017-06-05 14:50:29 +02:00
|
|
|
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
2017-05-24 09:06:17 +02:00
|
|
|
expect(indicator_el.textContent).toBe('2');
|
|
|
|
|
|
|
|
// When the chat gets maximized again, the unread indicators are removed
|
|
|
|
view.model.set({'minimized': false});
|
2017-06-05 14:50:29 +02:00
|
|
|
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
2017-05-24 09:06:17 +02:00
|
|
|
expect(_.isNull(indicator_el));
|
|
|
|
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
|
|
|
|
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
|
2017-05-24 08:40:09 +02:00
|
|
|
}));
|
2017-05-23 14:39:35 +02:00
|
|
|
});
|
2017-05-16 11:56:40 +02:00
|
|
|
}));
|