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-07-10 21:14:48 +02:00
|
|
|
var Promise = converse.env.Promise;
|
2017-05-16 11:56:40 +02:00
|
|
|
|
|
|
|
describe("The converse-roomslist plugin", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("is shown under a list of open rooms in the \"Rooms\" panel", mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'],
|
2018-03-14 20:01:33 +01:00
|
|
|
{ allow_bookmarks: false // Makes testing easier, otherwise we
|
2017-05-16 11:56:40 +02:00
|
|
|
// have to mock stanza traffic.
|
|
|
|
},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
2018-03-14 20:01:33 +01:00
|
|
|
test_utils.openControlBox();
|
2017-05-16 13:31:31 +02:00
|
|
|
var controlbox = _converse.chatboxviews.get('controlbox');
|
|
|
|
|
|
|
|
var list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeTruthy();
|
|
|
|
|
2018-03-14 20:01:33 +01:00
|
|
|
test_utils.openChatRoom(_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);
|
2018-03-14 20:01:33 +01:00
|
|
|
expect(room_els[0].innerText).toBe('room@conference.shakespeare.lit');
|
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);
|
2018-03-14 20:01:33 +01:00
|
|
|
expect(room_els[0].innerText).toBe('lounge@localhost');
|
2017-05-16 13:31:31 +02:00
|
|
|
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-07-11 10:41:11 +02:00
|
|
|
done();
|
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-07-11 10:41:11 +02:00
|
|
|
it("can be closed", mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'],
|
2017-05-23 14:39:35 +02:00
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
|
|
|
},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _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);
|
|
|
|
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(
|
2018-03-14 20:01:33 +01:00
|
|
|
'Are you sure you want to leave the room lounge@conference.shakespeare.lit?');
|
2017-05-23 20:42:12 +02:00
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(0);
|
|
|
|
expect(_converse.chatboxes.length).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-23 20:42:12 +02:00
|
|
|
}));
|
2017-05-24 08:40:09 +02:00
|
|
|
|
2017-07-10 21:14:48 +02:00
|
|
|
it("shows unread messages directed at the user", mock.initConverseWithAsync(
|
2017-05-24 08:40:09 +02:00
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
2017-07-10 21:14:48 +02:00
|
|
|
}, function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return !_.isUndefined(_converse.rooms_list_view)
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var room_jid = 'kitchen@conference.shakespeare.lit';
|
|
|
|
test_utils.openAndEnterChatRoom(
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse, 'kitchen', 'conference.shakespeare.lit', 'romeo').then(function () {
|
|
|
|
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
var indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
|
|
|
expect(indicator_el.textContent).toBe('1');
|
|
|
|
|
|
|
|
view.handleMUCMessage(
|
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('romeo: and another thing...').tree()
|
|
|
|
);
|
|
|
|
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
|
|
|
expect(indicator_el.textContent).toBe('2');
|
|
|
|
|
|
|
|
// When the chat gets maximized again, the unread indicators are removed
|
|
|
|
view.model.set({'minimized': false});
|
|
|
|
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
|
|
|
expect(_.isNull(indicator_el));
|
|
|
|
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
|
|
|
|
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
|
|
|
|
done();
|
|
|
|
});
|
2017-07-10 21:14:48 +02:00
|
|
|
});
|
2017-05-24 08:40:09 +02:00
|
|
|
}));
|
2017-05-23 14:39:35 +02:00
|
|
|
});
|
2017-05-16 11:56:40 +02:00
|
|
|
}));
|