Commit 3a2bf766 authored by JC Brand's avatar JC Brand

Add new test utility `waitUntilBookmarksReturned`

parent 06717370
......@@ -322,11 +322,7 @@
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']
);
await test_utils.waitUntilBookmarksReturned(_converse);
spyOn(_converse.api.rooms, 'create').and.callThrough();
const jid = 'theplay@conference.shakespeare.lit';
const model = _converse.bookmarks.create({
......@@ -450,7 +446,7 @@
'<items node="storage:bookmarks"/>'+
'</pubsub>'+
'</iq>');
/*
* Server returns all items
* ------------------------
......
......@@ -262,8 +262,7 @@ converse.plugins.add('converse-bookmarks', {
if (!_converse.allow_bookmarks) {
return;
}
const supported = await _converse.checkBookmarksSupport();
if (supported) {
if (await _converse.checkBookmarksSupport()) {
_converse.bookmarks = new _converse.Bookmarks();
await _converse.bookmarks.fetchBookmarks();
/**
......
......@@ -78,6 +78,35 @@
return this;
};
utils.waitUntilBookmarksReturned = async function (_converse, bookmarks=[]) {
await utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
);
const IQ_stanzas = _converse.connection.IQ_stanzas;
const sent_stanza = await u.waitUntil(
() => IQ_stanzas.filter(s => sizzle('items[node="storage:bookmarks"]', s).length).pop()
);
const stanza = $iq({
'to': _converse.connection.jid,
'type':'result',
'id':sent_stanza.getAttribute('id')
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'})
.c('item', {'id': 'current'})
.c('storage', {'xmlns': 'storage:bookmarks'});
bookmarks.forEach(bookmark => {
stanza.c('conference', {
'name': bookmark.name,
'autojoin': bookmark.autojoin,
'jid': bookmark.jid
}).c('nick').t(bookmark.nick).up().up()
});
_converse.connection._dataRecv(utils.createRequest(stanza));
await _converse.api.waitUntil('bookmarksInitialized');
};
utils.openChatBoxes = function (converse, amount) {
var i = 0, jid, views = [];
for (i; i<amount; i++) {
......@@ -388,7 +417,7 @@
}
utils.sendMessage = function (view, message) {
const promise = new Promise((resolve, reject) => view.on('messageInserted', resolve));
const promise = new Promise(resolve => view.once('messageInserted', resolve));
view.el.querySelector('.chat-textarea').value = message;
view.onKeyDown({
target: view.el.querySelector('textarea.chat-textarea'),
......
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