Commit 53b3f2d0 authored by JC Brand's avatar JC Brand

Fix failing tests and rewrite to use async/await

parent 65190834
......@@ -9,10 +9,11 @@
], factory);
} (this, function (jasmine, $, mock, test_utils) {
"use strict";
var $iq = converse.env.$iq,
const $iq = converse.env.$iq,
$msg = converse.env.$msg,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe,
sizzle = converse.env.sizzle,
_ = converse.env._,
u = converse.env.utils;
......@@ -369,15 +370,16 @@
});
}));
it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
);
/* Client requests all items
* -------------------------
*
......@@ -387,26 +389,29 @@
* </pubsub>
* </iq>
*/
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0];
let IQ_id;
const call = await test_utils.waitUntil(() =>
_.filter(
_converse.connection.send.calls.all(),
call => {
const stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
// XXX: Wrapping in a div is a workaround for PhantomJS
var div = document.createElement('div');
div.appendChild(stanza);
if (div.innerHTML ===
'<iq from="dummy@localhost/resource" type="get" '+
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"></items>'+
'</pubsub>'+
'</iq>') {
if (sizzle('items[node="storage:bookmarks"]', stanza).length) {
IQ_id = stanza.getAttribute('id');
return true;
}
}).length).toBe(1);
}
).pop()
);
expect(Strophe.serialize(call.args[0])).toBe(
`<iq from="dummy@localhost/resource" id="${IQ_id}" type="get" xmlns="jabber:client">`+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"/>'+
'</pubsub>'+
'</iq>');
/*
* Server returns all items
......@@ -448,49 +453,51 @@
'jid': 'another@conference.shakespeare.lit'
}); // Purposefully exclude the <nick> element to test #1043
_converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.bookmarks.onBookmarksReceived.calls.count(), 300)
}).then(() => {
await test_utils.waitUntil(() => _converse.bookmarks.onBookmarksReceived.calls.count());
expect(_converse.bookmarks.models.length).toBe(2);
expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
done();
}).catch(_.partial(console.error, _));
}));
describe("The rooms panel", function () {
it("shows a list of bookmarks", mock.initConverseWithPromises(
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
);
test_utils.openControlBox();
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0];
let IQ_id;
const call = await test_utils.waitUntil(() =>
_.filter(
_converse.connection.send.calls.all(),
call => {
const stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
// XXX: Wrapping in a div is a workaround for PhantomJS
var div = document.createElement('div');
div.appendChild(stanza);
if (div.innerHTML ===
'<iq from="dummy@localhost/resource" type="get" '+
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"></items>'+
'</pubsub>'+
'</iq>') {
if (sizzle('items[node="storage:bookmarks"]', stanza).length) {
IQ_id = stanza.getAttribute('id');
return true;
}
}).length).toBe(1);
}
).pop()
);
expect(Strophe.serialize(call.args[0])).toBe(
`<iq from="dummy@localhost/resource" id="${IQ_id}" type="get" xmlns="jabber:client">`+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"/>'+
'</pubsub>'+
'</iq>'
);
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
const stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'})
.c('item', {'id': 'current'})
......@@ -521,10 +528,9 @@
}).c('nick').t('JC').up().up();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
test_utils.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length, 300)
.then(() => {
await test_utils.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length);
expect(document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length).toBe(5);
const els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
let els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
expect(els[0].textContent).toBe("1st Bookmark");
expect(els[1].textContent).toBe("Another room");
expect(els[2].textContent).toBe("Bookmark with a very very long name that will be shortened");
......@@ -534,50 +540,52 @@
spyOn(window, 'confirm').and.returnValue(true);
document.querySelector('#chatrooms .bookmarks.rooms-list .room-item:nth-child(2) a:nth-child(2)').click();
expect(window.confirm).toHaveBeenCalled();
return test_utils.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length === 4, 300)
}).then(() => {
const els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
await test_utils.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length === 4)
els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
expect(els[0].textContent).toBe("1st Bookmark");
expect(els[1].textContent).toBe("Bookmark with a very very long name that will be shortened");
expect(els[2].textContent).toBe("noname@conference.shakespeare.lit");
expect(els[3].textContent).toBe("The Play's the Thing");
done();
}).catch(_.partial(console.error, _));
});
}));
it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) {
test_utils.openControlBox();
test_utils.waitUntilDiscoConfirmed(
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0];
);
let IQ_id;
const call = await test_utils.waitUntil(() =>
_.filter(
_converse.connection.send.calls.all(),
call => {
const stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
// XXX: Wrapping in a div is a workaround for PhantomJS
var div = document.createElement('div');
div.appendChild(stanza);
if (div.innerHTML ===
'<iq from="dummy@localhost/resource" type="get" '+
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"></items>'+
'</pubsub>'+
'</iq>') {
if (sizzle('items[node="storage:bookmarks"]', stanza).length) {
IQ_id = stanza.getAttribute('id');
return true;
}
}).length).toBe(1);
}
).pop()
);
expect(Strophe.serialize(call.args[0])).toBe(
`<iq from="dummy@localhost/resource" id="${IQ_id}" type="get" xmlns="jabber:client">`+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"/>'+
'</pubsub>'+
'</iq>'
);
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
const stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'})
.c('item', {'id': 'current'})
......@@ -590,8 +598,7 @@
'name': 'The Play',
'nick': ''
});
test_utils.waitUntil(() => $('#chatrooms .bookmarks.rooms-list .room-item:visible').length
).then(function () {
await test_utils.waitUntil(() => $('#chatrooms .bookmarks.rooms-list .room-item:visible').length);
expect($('#chatrooms .bookmarks.rooms-list').hasClass('collapsed')).toBeFalsy();
expect($('#chatrooms .bookmarks.rooms-list .room-item:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
......@@ -603,8 +610,6 @@
expect($('#chatrooms .bookmarks.rooms-list .room-item:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
done();
});
});
}));
});
});
......
......@@ -150,7 +150,8 @@
}));
it("can be trimmed to conserve space",
mock.initConverseWithPromises(null, ['rosterGroupsFetched'], {}, function (done, _converse) {
mock.initConverseWithPromises(null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
spyOn(_converse.chatboxviews, 'trimChats');
......@@ -163,25 +164,23 @@
test_utils.openControlBox();
let online_contacts;
var i, jid, chatbox, chatboxview, trimmedview;
let jid, chatboxview;
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
expect(_converse.chatboxes.length).toEqual(1);
expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(1); // Controlbox is open
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attached.
test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length)
.then(() => {
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length);
// Test that they can be maximized again
online_contacts = _converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact a.open-chat');
const online_contacts = _converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact a.open-chat');
expect(online_contacts.length).toBe(15);
let i;
for (i=0; i<online_contacts.length; i++) {
const el = online_contacts[i];
el.click();
}
return test_utils.waitUntil(() => _converse.chatboxes.length == 16)
}).then(() => {
await test_utils.waitUntil(() => _converse.chatboxes.length == 16);
expect(_converse.chatboxviews.trimChats.calls.count()).toBe(16);
for (i=0; i<online_contacts.length; i++) {
......@@ -193,11 +192,10 @@
expect(trimmed_chatboxes.addChat).toHaveBeenCalled();
expect(chatboxview.minimize).toHaveBeenCalled();
}
return test_utils.waitUntil(() => _converse.chatboxviews.keys().length);
}).then(function () {
await test_utils.waitUntil(() => _converse.chatboxviews.keys().length);
var key = _converse.chatboxviews.keys()[1];
trimmedview = trimmed_chatboxes.get(key);
chatbox = trimmedview.model;
const trimmedview = trimmed_chatboxes.get(key);
const chatbox = trimmedview.model;
spyOn(chatbox, 'maximize').and.callThrough();
spyOn(trimmedview, 'restore').and.callThrough();
trimmedview.delegateEvents();
......@@ -207,7 +205,6 @@
expect(chatbox.maximize).toHaveBeenCalled();
expect(_converse.chatboxviews.trimChats.calls.count()).toBe(17);
done();
});
}));
it("can be opened in minimized mode initially",
......@@ -453,18 +450,16 @@
it("contains a button for inserting emojis",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
test_utils.openControlBox();
let timeout = false, view, toolbar;
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid)
.then(() => {
view = _converse.chatboxviews.get(contact_jid);
toolbar = view.el.querySelector('ul.chat-toolbar');
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
const toolbar = view.el.querySelector('ul.chat-toolbar');
expect(toolbar.querySelectorAll('li.toggle-smiley').length).toBe(1);
// Register spies
spyOn(view, 'toggleEmojiMenu').and.callThrough();
......@@ -473,52 +468,33 @@
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
toolbar.querySelector('li.toggle-smiley').click();
return test_utils.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker-container'), 500));
}).then(() => {
await test_utils.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker-container')));
var picker = view.el.querySelector('.toggle-smiley .emoji-picker-container');
var items = picker.querySelectorAll('.emoji-picker li');
items[0].click()
expect(view.insertEmoji).toHaveBeenCalled();
setTimeout(function () { timeout = true; }, 100);
return test_utils.waitUntil(() => timeout, 500);
}).then(() => {
timeout = false;
toolbar.querySelector('li.toggle-smiley').click(); // Close the panel again
return test_utils.waitUntil(() => !view.el.querySelector('.toggle-smiley .toolbar-menu').offsetHeight, 500);
}).then(() => {
setTimeout(function () { timeout = true; }, 100);
return test_utils.waitUntil(() => timeout, 500);
}).then(() => {
toolbar.querySelector('li.toggle-smiley').click();
expect(view.toggleEmojiMenu).toHaveBeenCalled();
return test_utils.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker-container')), 500);
}).then(() => {
var nodes = view.el.querySelectorAll('.toggle-smiley ul li');
nodes[nodes.length-1].click();
expect(view.el.querySelector('textarea.chat-textarea').value).toBe(':grinning: ');
expect(view.insertEmoji).toHaveBeenCalled();
toolbar.querySelector('li.toggle-smiley').click(); // Close the panel again
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}));
it("can contain a button for starting a call",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
test_utils.openControlBox();
let view, toolbar, call_button;
let toolbar, call_button;
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(_converse, 'emit');
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
_converse.visible_toolbar_buttons.call = false;
test_utils.openChatBoxFor(_converse, contact_jid)
.then(() => {
view = _converse.chatboxviews.get(contact_jid);
await test_utils.openChatBoxFor(_converse, contact_jid);
let view = _converse.chatboxviews.get(contact_jid);
toolbar = view.el.querySelector('ul.chat-toolbar');
call_button = toolbar.querySelector('.toggle-call');
expect(_.isNull(call_button)).toBeTruthy();
......@@ -526,15 +502,13 @@
// Now check that it's shown if enabled and that it emits
// callButtonClicked
_converse.visible_toolbar_buttons.call = true; // enable the button
return test_utils.openChatBoxFor(_converse, contact_jid);
}).then(() => {
await test_utils.openChatBoxFor(_converse, contact_jid);
view = _converse.chatboxviews.get(contact_jid);
toolbar = view.el.querySelector('ul.chat-toolbar');
call_button = toolbar.querySelector('.toggle-call');
call_button.click();
expect(_converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
done();
});
}));
});
......@@ -549,9 +523,9 @@
test_utils.openControlBox();
spyOn(_converse, 'emit');
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// <composing> state
var msg = $msg({
const msg = $msg({
'from': sender_jid,
'to': _converse.connection.jid,
'type': 'chat',
......
......@@ -2331,10 +2331,9 @@
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
.then(() => {
await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
const view = _converse.chatboxviews.get('lounge@localhost'),
trimmed_chatboxes = _converse.minimized_chats;
......@@ -2349,7 +2348,8 @@
expect(u.isVisible(view.el)).toBeFalsy();
expect(view.model.get('minimized')).toBeTruthy();
expect(view.minimize).toHaveBeenCalled();
var trimmedview = trimmed_chatboxes.get(view.model.get('id'));
await test_utils.waitUntil(() => trimmed_chatboxes.get(view.model.get('id')));
const trimmedview = trimmed_chatboxes.get(view.model.get('id'));
trimmedview.el.querySelector("a.restore-chat").click();
expect(view.maximize).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
......@@ -2357,7 +2357,6 @@
expect(_converse.emit.calls.count(), 3);
done();
});
}));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
......
......@@ -14,17 +14,16 @@
describe("Discovering support", function () {
it("is done automatically", mock.initConverseWithAsync(function (done, _converse) {
it("is done automatically", mock.initConverseWithAsync(async function (done, _converse) {
var IQ_stanzas = _converse.connection.IQ_stanzas;
var IQ_ids = _converse.connection.IQ_ids;
test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []).then(function () {
test_utils.waitUntil(function () {
return _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector(
'iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
}).length > 0;
}, 300).then(function () {
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []);
await test_utils.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]')).length
);
/* <iq type='result'
* from='plays.shakespeare.lit'
* to='romeo@montague.net/orchard'
......@@ -38,7 +37,7 @@
* </query>
* </iq>
*/
var stanza = _.find(IQ_stanzas, function (iq) {
let stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector(
'iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
});
......@@ -59,7 +58,7 @@
'var': 'http://jabber.org/protocol/disco#items'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.api.disco.entities.get().then(function(entities) {
const entities = await _converse.api.disco.entities.get();
expect(entities.length).toBe(2);
expect(_.includes(entities.pluck('jid'), 'localhost')).toBe(true);
expect(_.includes(entities.pluck('jid'), 'dummy@localhost')).toBe(true);
......@@ -67,15 +66,13 @@
expect(entities.get(_converse.domain).features.length).toBe(2);
expect(entities.get(_converse.domain).identities.length).toBe(1);
return test_utils.waitUntil(function () {
// Converse.js sees that the entity has a disco#items feature,
// so it will make a query for it.
return _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]');
}).length > 0;
}, 300);
});
}).then(function () {
await test_utils.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]')
).length
);
/* <iq from='montague.tld'
* id='step_01'
* to='romeo@montague.tld/garden'
......@@ -86,7 +83,7 @@
* </query>
* </iq>
*/
var stanza = _.find(IQ_stanzas, function (iq) {
stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]');
});
var items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
......@@ -99,6 +96,7 @@
.c('item', {
'jid': 'upload.localhost',
'name': 'HTTP File Upload'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.api.disco.entities.get().then(function (entities) {
......@@ -112,11 +110,15 @@
}).length > 0;
}, 300);
});
}).then(function () {
var stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
});
var IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
stanza = await test_utils.waitUntil(() =>
_.filter(
IQ_stanzas,
iq => iq.nodeTree.querySelector('iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]')
).pop()
);
const IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
expect(stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost/resource" id="`+IQ_id+`" to="upload.localhost" type="get" xmlns="jabber:client">`+
`<query xmlns="http://jabber.org/protocol/disco#info"/>`+
......@@ -165,8 +167,6 @@
}
);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})
})
}));
});
......@@ -474,16 +474,17 @@
done();
}));
it("shows an error message if the file is too large", mock.initConverseWithAsync(function (done, _converse) {
it("shows an error message if the file is too large", mock.initConverseWithAsync(async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas;
const IQ_ids = _converse.connection.IQ_ids;
const send_backup = XMLHttpRequest.prototype.send;
let view, contact_jid;
test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], [])
.then(() => test_utils.waitUntil(() => _.filter(
IQ_stanzas, (iq) => iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]')).length
)).then(() => {
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []);
await test_utils.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]')).length
);
var stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector(
'iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
......@@ -504,8 +505,8 @@
.c('feature', {
'var': 'http://jabber.org/protocol/disco#items'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.disco.entities.get();
}).then(function (entities) {
let entities = await _converse.api.disco.entities.get();
expect(entities.length).toBe(2);
expect(_.includes(entities.pluck('jid'), 'localhost')).toBe(true);
expect(_.includes(entities.pluck('jid'), 'dummy@localhost')).toBe(true);
......@@ -513,15 +514,15 @@
expect(entities.get(_converse.domain).features.length).toBe(2);
expect(entities.get(_converse.domain).identities.length).toBe(1);
return test_utils.waitUntil(function () {
await test_utils.waitUntil(function () {
// Converse.js sees that the entity has a disco#items feature,
// so it will make a query for it.
return _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]');
}).length > 0;
}, 300);
}).then(function () {
var stanza = _.find(IQ_stanzas, function (iq) {
stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]');
});
var items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
......@@ -537,19 +538,19 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.api.disco.entities.get().then(function (entities) {
entities = await _converse.api.disco.entities.get()
expect(entities.length).toBe(2);
expect(entities.get('localhost').items.length).toBe(1);
return test_utils.waitUntil(function () {
await test_utils.waitUntil(function () {
// Converse.js sees that the entity has a disco#info feature,
// so it will make a query for it.
return _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
}).length > 0;
}, 300);
});
}).then(function () {
var stanza = _.find(IQ_stanzas, function (iq) {
stanza = _.find(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
});
var IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
......@@ -569,18 +570,15 @@
.c('field', {'var':'max-file-size'})
.c('value').t('5242880');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.disco.entities.get();
}).then(function (entities) {
entities = await _converse.api.disco.entities.get();
expect(entities.get('localhost').items.get('upload.localhost').identities.where({'category': 'store'}).length).toBe(1);
return _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
}).then(function (result) {
const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
return test_utils.openChatBoxFor(_converse, contact_jid);
}).then(() => {
view = _converse.chatboxviews.get(contact_jid);
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
var file = {
'type': 'image/jpeg',
'size': '5242881',
......@@ -588,14 +586,12 @@
'name': "my-juliet.jpg"
};
view.model.sendFiles([file]);
return test_utils.waitUntil(() => view.el.querySelectorAll('.message').length)
}).then(function () {
await test_utils.waitUntil(() => view.el.querySelectorAll('.message').length)
const messages = view.el.querySelectorAll('.message.chat-error');
expect(messages.length).toBe(1);
expect(messages[0].textContent).toBe(
'The size of your file, my-juliet.jpg, exceeds the maximum allowed by your server, which is 5 MB.');
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
}));
});
});
......
......@@ -159,22 +159,26 @@
it("is played when the current user is mentioned in a chat room",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
_converse.play_sounds = true;
spyOn(_converse, 'playSoundNotification');
var view = _converse.chatboxviews.get('lounge@localhost');
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
var text = 'This message will play a sound because it mentions dummy';
var message = $msg({
const view = _converse.chatboxviews.get('lounge@localhost');
if (!view.el.querySelectorAll('.chat-area').length) {
view.renderChatArea();
}
let text = 'This message will play a sound because it mentions dummy';
let message = $msg({
from: 'lounge@localhost/otheruser',
id: '1',
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(text);
view.model.onMessage(message.nodeTree);
await test_utils.waitUntil(() => _converse.playSoundNotification.calls.count());
expect(_converse.playSoundNotification).toHaveBeenCalled();
text = "This message won't play a sound";
......@@ -199,7 +203,6 @@
expect(_converse.playSoundNotification, 1);
_converse.play_sounds = false;
done();
});
}));
});
});
......
......@@ -10,28 +10,21 @@
const u = converse.env.utils;
const checkHeaderToggling = function (group) {
var $group = $(group);
const checkHeaderToggling = async function (group) {
var toggle = group.querySelector('a.group-toggle');
expect(u.isVisible($group[0])).toBeTruthy();
expect($group.find('ul.collapsed').length).toBe(0);
expect(u.isVisible(group)).toBeTruthy();
expect(group.querySelectorAll('ul.collapsed').length).toBe(0);
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
toggle.click();
return test_utils.waitUntil(function () {
return $group.find('ul.collapsed').length === 1;
}, 500).then(function () {
await test_utils.waitUntil(() => group.querySelectorAll('ul.collapsed').length === 1);
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeTruthy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeFalsy();
toggle.click();
return test_utils.waitUntil(function () {
return $group.find('li').length === $group.find('li:visible').length
}, 500);
}).then(function () {
await test_utils.waitUntil(() => group.querySelectorAll('li').length === $(group).find('li:visible').length);
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
});
};
......@@ -501,7 +494,7 @@
it("remembers whether it is closed or opened",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
async function (done, _converse) {
_converse.roster_groups = true;
test_utils.openControlBox();
......@@ -524,20 +517,14 @@
});
}
});
var view = _converse.rosterview.get('colleagues');
var $toggle = $(view.el).find('a.group-toggle');
const view = _converse.rosterview.get('colleagues');
const toggle = view.el.querySelector('a.group-toggle');
expect(view.model.get('state')).toBe('opened');
$toggle[0].click();
return test_utils.waitUntil(function () {
return view.model.get('state') === 'closed';
}, 500).then(function () {
$toggle[0].click();
return test_utils.waitUntil(function () {
return view.model.get('state') === 'opened';
}, 500)
}).then(function () {
toggle.click();
await test_utils.waitUntil(() => view.model.get('state') === 'closed');
toggle.click();
await test_utils.waitUntil(() => view.model.get('state') === 'opened');
done();
});
}));
});
......
......@@ -105,6 +105,7 @@
spyOn(view, 'onMessageSubmitted').and.callThrough();
spyOn(_converse.connection, 'send');
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click();
......@@ -178,6 +179,8 @@
await test_utils.openChatBoxFor(_converse, contact_jid);
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
const view = _converse.chatboxviews.get(contact_jid);
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click();
......
......@@ -179,7 +179,6 @@ require.config(config);
var specs = [
"jasmine",
//"spec/transcripts",
//"spec/otr",
"spec/spoilers",
"spec/profiling",
"spec/utils",
......
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