2017-05-16 11:56:40 +02:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2019-10-09 16:01:38 +02:00
|
|
|
const { Strophe, $iq, $msg, $pres, sizzle, _ } = converse.env;
|
2018-12-15 19:30:20 +01:00
|
|
|
const u = converse.env.utils;
|
2017-05-16 11:56:40 +02:00
|
|
|
|
|
|
|
|
2018-12-15 19:30:20 +01:00
|
|
|
describe("A list of open groupchats", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is shown in controlbox", mock.initConverse(
|
2019-07-11 12:30:51 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'],
|
2018-10-23 03:41:38 +02:00
|
|
|
{ allow_bookmarks: false // Makes testing easier, otherwise we
|
2019-07-11 22:50:30 +02:00
|
|
|
// have to mock stanza traffic.
|
2018-10-23 03:41:38 +02:00
|
|
|
}, async function (done, _converse) {
|
2017-05-16 13:31:31 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
const controlbox = _converse.chatboxviews.get('controlbox');
|
|
|
|
let list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeTruthy();
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
await test_utils.openChatRoom(_converse, 'room', 'conference.shakespeare.lit', 'JC');
|
2019-07-29 10:19:05 +02:00
|
|
|
expect(_converse.rooms_list_view === undefined).toBeFalsy();
|
2019-06-27 11:27:05 +02:00
|
|
|
|
|
|
|
const lview = _converse.rooms_list_view
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
|
2019-06-27 11:27:05 +02:00
|
|
|
let room_els = lview.el.querySelectorAll(".open-room");
|
2018-10-23 03:41:38 +02:00
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
expect(room_els[0].innerText).toBe('room@conference.shakespeare.lit');
|
2019-06-27 11:27:05 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
|
2018-10-23 03:41:38 +02:00
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(2);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
let 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);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(room_els[0].innerText).toBe('lounge@montague.lit');
|
2018-10-23 03:41:38 +02:00
|
|
|
list = controlbox.el.querySelector('div.rooms-list-container');
|
2019-07-11 22:50:30 +02:00
|
|
|
u.waitUntil(() => _.includes(list.classList, 'hidden'));
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
view = _converse.chatboxviews.get('lounge@montague.lit');
|
2018-10-23 03:41:38 +02:00
|
|
|
view.close();
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(0);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeTruthy();
|
|
|
|
done();
|
2017-05-16 11:56:40 +02:00
|
|
|
}
|
|
|
|
));
|
2018-12-15 19:30:20 +01:00
|
|
|
|
|
|
|
it("uses bookmarks to determine groupchat names",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-07-11 12:30:51 +02:00
|
|
|
{'connection': ['send']},
|
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'],
|
|
|
|
{'view_mode': 'fullscreen'},
|
2018-12-15 19:30:20 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-07-03 14:18:46 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
|
2018-12-15 19:30:20 +01:00
|
|
|
let stanza = $pres({
|
2019-06-03 07:58:51 +02:00
|
|
|
to: 'romeo@montague.lit/orchard',
|
|
|
|
from: 'lounge@montague.lit/newguy'
|
2018-12-15 19:30:20 +01:00
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': 'newguy@montague.lit/_converse.js-290929789',
|
2018-12-15 19:30:20 +01:00
|
|
|
'role': 'participant'
|
|
|
|
}).tree();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
spyOn(_converse.Bookmarks.prototype, 'fetchBookmarks').and.callThrough();
|
|
|
|
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type':'pep'}],
|
|
|
|
[`${Strophe.NS.PUBSUB}#publish-options`]
|
|
|
|
);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
const call = await u.waitUntil(() =>
|
2018-12-15 19:30:20 +01:00
|
|
|
_.filter(
|
|
|
|
_converse.connection.send.calls.all(),
|
|
|
|
c => sizzle('items[node="storage:bookmarks"]', c.args[0]).length
|
|
|
|
).pop()
|
|
|
|
);
|
|
|
|
expect(Strophe.serialize(call.args[0])).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${call.args[0].getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
2018-12-15 19:30:20 +01:00
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
'<items node="storage:bookmarks"/>'+
|
|
|
|
'</pubsub>'+
|
|
|
|
'</iq>');
|
|
|
|
|
|
|
|
stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':call.args[0].getAttribute('id')})
|
|
|
|
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
|
|
|
.c('items', {'node': 'storage:bookmarks'})
|
|
|
|
.c('item', {'id': 'current'})
|
|
|
|
.c('storage', {'xmlns': 'storage:bookmarks'})
|
|
|
|
.c('conference', {
|
|
|
|
'name': 'Bookmarked Lounge',
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': 'lounge@montague.lit'
|
2018-12-15 19:30:20 +01:00
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
await _converse.api.waitUntil('roomsListInitialized');
|
|
|
|
const controlbox = _converse.chatboxviews.get('controlbox');
|
|
|
|
const list = controlbox.el.querySelector('div.rooms-list-container');
|
|
|
|
expect(_.includes(list.classList, 'hidden')).toBeFalsy();
|
|
|
|
const items = list.querySelectorAll('.list-item');
|
|
|
|
expect(items.length).toBe(1);
|
|
|
|
expect(items[0].textContent.trim()).toBe('Bookmarked Lounge');
|
|
|
|
expect(_converse.bookmarks.fetchBookmarks).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}));
|
2017-05-16 11:56:40 +02:00
|
|
|
});
|
2017-05-23 14:39:35 +02:00
|
|
|
|
2018-07-02 23:29:57 +02:00
|
|
|
describe("A groupchat shown in the groupchats list", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is highlighted if its currently open", mock.initConverse(
|
2019-07-11 22:50:30 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'],
|
2018-12-04 12:52:25 +01:00
|
|
|
{ view_mode: 'fullscreen',
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
|
2018-11-22 12:15:35 +01:00
|
|
|
}, async function (done, _converse) {
|
2018-07-02 23:29:57 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
await _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
|
2019-06-27 11:27:05 +02:00
|
|
|
const lview = _converse.rooms_list_view
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
|
2019-06-27 11:27:05 +02:00
|
|
|
let room_els = lview.el.querySelectorAll(".available-chatroom");
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(room_els.length).toBe(1);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
let item = room_els[0];
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(u.hasClass('open', item)).toBe(true);
|
|
|
|
expect(item.textContent.trim()).toBe('coven@chat.shakespeare.lit');
|
|
|
|
await _converse.api.rooms.open('balcony@chat.shakespeare.lit', {'nick': 'some1'});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
|
2019-06-27 11:27:05 +02:00
|
|
|
room_els = lview.el.querySelectorAll(".open-room");
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(room_els.length).toBe(2);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-27 11:27:05 +02:00
|
|
|
room_els = lview.el.querySelectorAll(".available-chatroom.open");
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
item = room_els[0];
|
|
|
|
expect(item.textContent.trim()).toBe('balcony@chat.shakespeare.lit');
|
2018-12-04 12:52:25 +01:00
|
|
|
const conv_el = document.querySelector('#conversejs');
|
|
|
|
conv_el.parentElement.removeChild(conv_el);
|
2018-11-22 12:15:35 +01:00
|
|
|
done();
|
2018-07-02 23:29:57 +02:00
|
|
|
}));
|
2018-06-04 19:53:33 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("has an info icon which opens a details modal when clicked", mock.initConverse(
|
2019-07-11 12:30:51 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'],
|
2018-06-04 19:53:33 +02:00
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we
|
|
|
|
// have to mock stanza traffic.
|
2018-10-13 23:25:01 +02:00
|
|
|
}, async function (done, _converse) {
|
2018-06-04 19:53:33 +02:00
|
|
|
|
2018-09-13 10:51:56 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const room_jid = 'coven@chat.shakespeare.lit';
|
2018-06-04 19:53:33 +02:00
|
|
|
test_utils.openControlBox();
|
2018-10-13 23:25:01 +02:00
|
|
|
await _converse.api.rooms.open(room_jid, {'nick': 'some1'});
|
|
|
|
const view = _converse.chatboxviews.get(room_jid);
|
2019-09-04 21:21:16 +02:00
|
|
|
|
|
|
|
const selector = `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`;
|
|
|
|
const features_query = await u.waitUntil(() => IQ_stanzas.filter(iq => iq.querySelector(selector)).pop());
|
2018-10-13 23:25:01 +02:00
|
|
|
const features_stanza = $iq({
|
|
|
|
'from': 'coven@chat.shakespeare.lit',
|
2019-09-04 21:21:16 +02:00
|
|
|
'id': features_query.getAttribute('id'),
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit/desktop',
|
2018-10-13 23:25:01 +02:00
|
|
|
'type': 'result'
|
|
|
|
})
|
|
|
|
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'conference',
|
|
|
|
'name': 'A Dark Cave',
|
|
|
|
'type': 'text'
|
2018-06-04 19:53:33 +02:00
|
|
|
}).up()
|
2018-10-13 23:25:01 +02:00
|
|
|
.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));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)
|
2018-10-13 23:25:01 +02:00
|
|
|
let presence = $pres({
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
from: 'coven@chat.shakespeare.lit/some1',
|
|
|
|
id: 'DC352437-C019-40EC-B590-AF29E879AF97'
|
|
|
|
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
|
|
|
.c('item').attrs({
|
|
|
|
affiliation: 'member',
|
|
|
|
jid: _converse.bare_jid,
|
|
|
|
role: 'participant'
|
|
|
|
}).up()
|
|
|
|
.c('status').attrs({code:'110'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".open-room").length, 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
const room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
const info_el = _converse.rooms_list_view.el.querySelector(".room-info");
|
|
|
|
info_el.click();
|
|
|
|
|
|
|
|
const modal = view.model.room_details_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
let els = modal.el.querySelectorAll('p.room-info');
|
|
|
|
expect(els[0].textContent).toBe("Name: A Dark Cave")
|
|
|
|
expect(els[1].textContent).toBe("Groupchat address (JID): coven@chat.shakespeare.lit")
|
|
|
|
expect(els[2].textContent).toBe("Description: This is the description")
|
|
|
|
expect(els[3].textContent).toBe("Online users: 1")
|
|
|
|
const features_list = modal.el.querySelector('.features-list');
|
|
|
|
expect(features_list.textContent.replace(/(\n|\s{2,})/g, '')).toBe(
|
|
|
|
'Password protected - This groupchat requires a password before entry'+
|
|
|
|
'Hidden - This groupchat is not publicly searchable'+
|
|
|
|
'Open - Anyone can join this groupchat'+
|
|
|
|
'Temporary - This groupchat will disappear once the last person leaves'+
|
2019-02-19 23:08:05 +01:00
|
|
|
'Not anonymous - All other groupchat participants can see your XMPP address'+
|
2018-10-13 23:25:01 +02:00
|
|
|
'Not moderated - Participants entering this groupchat can write right away'
|
|
|
|
);
|
|
|
|
presence = $pres({
|
2019-06-03 07:58:51 +02:00
|
|
|
to: 'romeo@montague.lit/_converse.js-29092160',
|
2018-10-13 23:25:01 +02:00
|
|
|
from: 'coven@chat.shakespeare.lit/newguy'
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': 'newguy@montague.lit/_converse.js-290929789',
|
2018-10-13 23:25:01 +02:00
|
|
|
'role': 'participant'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
|
|
|
|
|
|
|
els = modal.el.querySelectorAll('p.room-info');
|
|
|
|
expect(els[3].textContent).toBe("Online users: 2")
|
|
|
|
|
|
|
|
view.model.set({'subject': {'author': 'someone', 'text': 'Hatching dark plots'}});
|
|
|
|
els = modal.el.querySelectorAll('p.room-info');
|
|
|
|
expect(els[0].textContent).toBe("Name: A Dark Cave")
|
|
|
|
expect(els[1].textContent).toBe("Groupchat address (JID): coven@chat.shakespeare.lit")
|
|
|
|
expect(els[2].textContent).toBe("Description: This is the description")
|
|
|
|
expect(els[3].textContent).toBe("Topic: Hatching dark plots")
|
|
|
|
expect(els[4].textContent).toBe("Topic author: someone")
|
|
|
|
expect(els[5].textContent).toBe("Online users: 2")
|
|
|
|
done();
|
2018-06-04 19:53:33 +02:00
|
|
|
}));
|
2017-05-23 20:42:12 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("can be closed", mock.initConverse(
|
2019-07-11 12:30:51 +02:00
|
|
|
null, ['rosterGroupsFetched', 'emojisInitialized'],
|
2017-05-23 14:39:35 +02:00
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
2018-11-22 12:15:35 +01:00
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
|
2017-05-23 14:39:35 +02:00
|
|
|
},
|
2018-11-22 12:15:35 +01:00
|
|
|
async function (done, _converse) {
|
2017-05-23 20:42:12 +02:00
|
|
|
|
2018-07-30 18:16:32 +02:00
|
|
|
spyOn(window, 'confirm').and.callFake(() => true);
|
2017-05-23 20:42:12 +02:00
|
|
|
expect(_converse.chatboxes.length).toBe(1);
|
2018-11-22 12:15:35 +01:00
|
|
|
await test_utils.openChatRoom(_converse, 'lounge', 'conference.shakespeare.lit', 'JC');
|
|
|
|
expect(_converse.chatboxes.length).toBe(2);
|
2019-06-27 11:27:05 +02:00
|
|
|
const lview = _converse.rooms_list_view
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
|
2019-06-27 11:27:05 +02:00
|
|
|
let room_els = lview.el.querySelectorAll(".open-room");
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(room_els.length).toBe(1);
|
2019-06-27 11:27:05 +02:00
|
|
|
const close_el = _converse.rooms_list_view.el.querySelector(".close-room");
|
2018-11-22 12:15:35 +01:00
|
|
|
close_el.click();
|
|
|
|
expect(window.confirm).toHaveBeenCalledWith(
|
|
|
|
'Are you sure you want to leave the groupchat lounge@conference.shakespeare.lit?');
|
|
|
|
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
|
|
|
|
expect(room_els.length).toBe(0);
|
|
|
|
expect(_converse.chatboxes.length).toBe(1);
|
|
|
|
done();
|
2017-05-23 20:42:12 +02:00
|
|
|
}));
|
2017-05-24 08:40:09 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("shows unread messages directed at the user", mock.initConverse(
|
|
|
|
null, null,
|
|
|
|
{ whitelisted_plugins: ['converse-roomslist'],
|
2018-11-22 12:15:35 +01:00
|
|
|
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
|
2019-02-12 14:21:45 +01:00
|
|
|
}, async (done, _converse) => {
|
2017-07-10 21:14:48 +02:00
|
|
|
|
2018-12-16 12:29:43 +01:00
|
|
|
test_utils.openControlBox();
|
2018-08-18 11:28:51 +02:00
|
|
|
const room_jid = 'kitchen@conference.shakespeare.lit';
|
2019-07-29 10:19:05 +02:00
|
|
|
await u.waitUntil(() => _converse.rooms_list_view !== undefined, 500);
|
2019-07-03 14:18:46 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'romeo');
|
2018-11-22 12:15:35 +01:00
|
|
|
const view = _converse.chatboxviews.get(room_jid);
|
|
|
|
view.model.set({'minimized': true});
|
|
|
|
const nick = mock.chatroom_names[0];
|
2019-01-25 11:53:07 +01:00
|
|
|
await view.model.onMessage(
|
2018-11-22 12:15:35 +01:00
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
2019-06-03 07:58:51 +02:00
|
|
|
to: 'romeo@montague.lit',
|
2018-11-22 12:15:35 +01:00
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('foo').tree());
|
2018-08-18 11:28:51 +02:00
|
|
|
|
2019-06-27 16:50:44 +02:00
|
|
|
const lview = _converse.rooms_list_view
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => lview.el.querySelectorAll(".available-chatroom").length, 500);
|
2019-06-27 16:50:44 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
// If the user isn't mentioned, the counter doesn't get incremented, but the text of the groupchat is bold
|
2019-06-27 16:50:44 +02:00
|
|
|
let room_el = lview.el.querySelector(".available-chatroom");
|
2018-12-16 12:29:43 +01:00
|
|
|
expect(_.includes(room_el.classList, 'unread-msgs')).toBeTruthy();
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
// If the user is mentioned, the counter also gets updated
|
2019-01-25 11:53:07 +01:00
|
|
|
await view.model.onMessage(
|
2018-11-22 12:15:35 +01:00
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
2019-06-03 07:58:51 +02:00
|
|
|
to: 'romeo@montague.lit',
|
2018-11-22 12:15:35 +01:00
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('romeo: Your attention is required').tree()
|
|
|
|
);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".msgs-indicator").length);
|
2018-11-22 12:15:35 +01:00
|
|
|
spyOn(view.model, 'incrementUnreadMsgCounter').and.callThrough();
|
|
|
|
let indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
|
|
|
expect(indicator_el.textContent).toBe('1');
|
2019-01-25 11:53:07 +01:00
|
|
|
await view.model.onMessage(
|
2018-11-22 12:15:35 +01:00
|
|
|
$msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
2019-06-03 07:58:51 +02:00
|
|
|
to: 'romeo@montague.lit',
|
2018-11-22 12:15:35 +01:00
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('romeo: and another thing...').tree()
|
|
|
|
);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.incrementUnreadMsgCounter.calls.count());
|
2018-11-22 12:15:35 +01:00
|
|
|
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
|
|
|
|
expect(indicator_el.textContent).toBe('2');
|
2017-07-12 09:55:43 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
// 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");
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(indicator_el === null);
|
2018-11-22 12:15:35 +01:00
|
|
|
room_el = _converse.rooms_list_view.el.querySelector(".available-chatroom");
|
|
|
|
expect(_.includes(room_el.classList, 'unread-msgs')).toBeFalsy();
|
|
|
|
done();
|
2017-05-24 08:40:09 +02:00
|
|
|
}));
|
2017-05-23 14:39:35 +02:00
|
|
|
});
|
2017-05-16 11:56:40 +02:00
|
|
|
}));
|