Commit 9cb91512 authored by JC Brand's avatar JC Brand

Add test to check that #1577 is resolved

parent 1269d53e
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
it("can be bookmarked", mock.initConverse( it("can be bookmarked", mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
await test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid, _converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}], [{'category': 'pubsub', 'type': 'pep'}],
...@@ -188,6 +188,31 @@ ...@@ -188,6 +188,31 @@
describe("when bookmarked", function () { describe("when bookmarked", function () {
it("will use the nickname from the bookmark", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
);
const room_jid = 'coven@chat.shakespeare.lit';
await test_utils.waitUntil(() => _converse.bookmarks);
_converse.bookmarks.create({
'jid': room_jid,
'autojoin': false,
'name': 'The Play',
'nick': 'Othello'
});
const model = await _converse.api.rooms.open(room_jid);
spyOn(model, 'join').and.callThrough();
await test_utils.getRoomFeatures(_converse, 'coven', 'chat.shakespeare.lit');
await test_utils.waitUntil(() => model.join.calls.count());
expect(model.get('nick')).toBe('Othello');
done();
}));
it("displays that it's bookmarked through its bookmark icon", mock.initConverse( it("displays that it's bookmarked through its bookmark icon", mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -197,7 +222,7 @@ ...@@ -197,7 +222,7 @@
[{'category': 'pubsub', 'type': 'pep'}], [{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options'] ['http://jabber.org/protocol/pubsub#publish-options']
); );
await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); await _converse.api.rooms.open(`lounge@localhost`);
const view = _converse.chatboxviews.get('lounge@localhost'); const view = _converse.chatboxviews.get('lounge@localhost');
await test_utils.waitUntil(() => !_.isNull(view.el.querySelector('.toggle-bookmark'))); await test_utils.waitUntil(() => !_.isNull(view.el.querySelector('.toggle-bookmark')));
var bookmark_icon = view.el.querySelector('.toggle-bookmark'); var bookmark_icon = view.el.querySelector('.toggle-bookmark');
......
...@@ -453,7 +453,7 @@ ...@@ -453,7 +453,7 @@
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
await test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1'); await test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit');
const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
const chat_content = view.el.querySelector('.chat-content'); const chat_content = view.el.querySelector('.chat-content');
/* <presence to="dummy@localhost/_converse.js-29092160" /* <presence to="dummy@localhost/_converse.js-29092160"
......
...@@ -114,16 +114,14 @@ ...@@ -114,16 +114,14 @@
return _converse.chatboxviews.get(jid); return _converse.chatboxviews.get(jid);
}; };
utils.openChatRoom = function (_converse, room, server, nick) { utils.openChatRoom = function (_converse, room, server) {
return _converse.api.rooms.open(`${room}@${server}`); return _converse.api.rooms.open(`${room}@${server}`);
}; };
utils.openAndEnterChatRoom = async function (_converse, room, server, nick, features=[]) { utils.getRoomFeatures = async function (_converse, room, server, features=[]) {
const room_jid = `${room}@${server}`.toLowerCase(); const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas; const stanzas = _converse.connection.IQ_stanzas;
await _converse.api.rooms.open(room_jid); const stanza = await utils.waitUntil(() => _.filter(
const view = _converse.chatboxviews.get(room_jid);
let stanza = await utils.waitUntil(() => _.filter(
stanzas, stanzas,
iq => iq.querySelector( iq => iq.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]` `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
...@@ -161,6 +159,13 @@ ...@@ -161,6 +159,13 @@
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'}) .c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0); .c('value').t(0);
_converse.connection._dataRecv(utils.createRequest(features_stanza)); _converse.connection._dataRecv(utils.createRequest(features_stanza));
};
utils.openAndEnterChatRoom = async function (_converse, room, server, nick, features=[]) {
const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas;
await _converse.api.rooms.open(room_jid);
await utils.getRoomFeatures(_converse, room, server, features);
const iq = await utils.waitUntil(() => _.filter( const iq = await utils.waitUntil(() => _.filter(
stanzas, stanzas,
...@@ -171,8 +176,9 @@ ...@@ -171,8 +176,9 @@
stanzas.splice(stanzas.indexOf(iq), 1) stanzas.splice(stanzas.indexOf(iq), 1)
// The XMPP server returns the reserved nick for this user. // The XMPP server returns the reserved nick for this user.
const view = _converse.chatboxviews.get(room_jid);
const IQ_id = iq.getAttribute('id'); const IQ_id = iq.getAttribute('id');
stanza = $iq({ const stanza = $iq({
'type': 'result', 'type': 'result',
'id': IQ_id, 'id': IQ_id,
'from': view.model.get('jid'), 'from': view.model.get('jid'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment