Commit f2c14557 authored by JC Brand's avatar JC Brand

Bump waiting time for room opened via modal in test utils

Convert more promise-based tests to async/await
parent 0d3e94c6
...@@ -3197,38 +3197,36 @@ ...@@ -3197,38 +3197,36 @@
it("will use the nickname set in the global settings if the user doesn't have a VCard nickname", it("will use the nickname set in the global settings if the user doesn't have a VCard nickname",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'Benedict-Cucumberpatch'}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'Benedict-Cucumberpatch'},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost') await test_utils.openChatRoomViaModal(_converse, 'roomy@muc.localhost');
.then(function () { const view = _converse.chatboxviews.get('roomy@muc.localhost');
const view = _converse.chatboxviews.get('problematic@muc.localhost');
expect(view.model.get('nick')).toBe('Benedict-Cucumberpatch'); expect(view.model.get('nick')).toBe('Benedict-Cucumberpatch');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the groupchat requires a password", it("will show an error message if the groupchat requires a password",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'protected';
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var view = _converse.chatboxviews.get('problematic@muc.localhost'); const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'renderPasswordForm').and.callThrough(); spyOn(view, 'renderPasswordForm').and.callThrough();
var presence = $pres().attrs({ var presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', 'from': `${groupchat_jid}/dummy`,
id:'n13mt3l', 'id': u.getUniqueId(),
to:'dummy@localhost/pda', 'to': 'dummy@localhost/pda',
type:'error'}) 'type': 'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'auth'}) .c('error').attrs({by:'lounge@localhost', type:'auth'})
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}); .c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'});
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
var chat_body = view.el.querySelector('.chatroom-body'); const chat_body = view.el.querySelector('.chatroom-body');
expect(view.renderPasswordForm).toHaveBeenCalled(); expect(view.renderPasswordForm).toHaveBeenCalled();
expect(chat_body.querySelectorAll('form.chatroom-form').length).toBe(1); expect(chat_body.querySelectorAll('form.chatroom-form').length).toBe(1);
expect(chat_body.querySelector('legend').textContent) expect(chat_body.querySelector('legend').textContent)
...@@ -3236,78 +3234,78 @@ ...@@ -3236,78 +3234,78 @@
// Let's submit the form // Let's submit the form
spyOn(view, 'join'); spyOn(view, 'join');
var input_el = view.el.querySelector('[name="password"]'); const input_el = view.el.querySelector('[name="password"]');
input_el.value = 'secret'; input_el.value = 'secret';
view.el.querySelector('input[type=submit]').click(); view.el.querySelector('input[type=submit]').click();
expect(view.join).toHaveBeenCalledWith('dummy', 'secret'); expect(view.join).toHaveBeenCalledWith('dummy', 'secret');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the groupchat is members-only and the user not included", it("will show an error message if the groupchat is members-only and the user not included",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'members-only@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ const presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to: 'dummy@localhost/pda',
type:'error'}) type: 'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'auth'}) .c('error').attrs({by:'lounge@localhost', type:'auth'})
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe('You are not on the member list of this groupchat.'); .toBe('You are not on the member list of this groupchat.');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the user has been banned", it("will show an error message if the user has been banned",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'off-limits@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ const presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to: 'dummy@localhost/pda',
type:'error'}) type: 'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'auth'}) .c('error').attrs({by:'lounge@localhost', type:'auth'})
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe('You have been banned from this groupchat.'); .toBe('You have been banned from this groupchat.');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false", it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'conflicted@muc.localhost';
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ var presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to: 'dummy@localhost/pda',
type:'error'}) type: 'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(sizzle('.chatroom-body form.chatroom-form label:first', view.el).pop().textContent) expect(sizzle('.chatroom-body form.chatroom-form label:first', view.el).pop().textContent)
...@@ -3317,16 +3315,15 @@ ...@@ -3317,16 +3315,15 @@
input.value = 'nicky'; input.value = 'nicky';
view.el.querySelector('input[type=submit]').click(); view.el.querySelector('input[type=submit]').click();
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true", it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'conflicting@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
/* <presence /* <presence
* from='coven@chat.shakespeare.lit/thirdwitch' * from='coven@chat.shakespeare.lit/thirdwitch'
* id='n13mt3l' * id='n13mt3l'
...@@ -3340,18 +3337,18 @@ ...@@ -3340,18 +3337,18 @@
*/ */
_converse.muc_nickname_from_jid = true; _converse.muc_nickname_from_jid = true;
var attrs = { const attrs = {
from:'problematic@muc.localhost/dummy', 'from': `${groupchat_jid}/dummy`,
to:'dummy@localhost/pda', 'id': u.getUniqueId(),
type:'error' 'to': 'dummy@localhost/pda',
'type': 'error'
}; };
attrs.id = new Date().getTime(); let presence = $pres().attrs(attrs)
var presence = $pres().attrs(attrs) .c('x').attrs({'xmlns':'http://jabber.org/protocol/muc'}).up()
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() .c('error').attrs({'by': groupchat_jid, 'type':'cancel'})
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'}) .c('conflict').attrs({'xmlns':'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost'); const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
spyOn(view, 'join').and.callThrough(); spyOn(view, 'join').and.callThrough();
...@@ -3360,26 +3357,25 @@ ...@@ -3360,26 +3357,25 @@
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.join).toHaveBeenCalledWith('dummy-2'); expect(view.join).toHaveBeenCalledWith('dummy-2');
attrs.from = 'problematic@muc.localhost/dummy-2'; attrs.from = `${groupchat_jid}/dummy-2`;
attrs.id = new Date().getTime(); attrs.id = u.getUniqueId();
presence = $pres().attrs(attrs) presence = $pres().attrs(attrs)
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() .c('x').attrs({'xmlns':'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'}) .c('error').attrs({'by': groupchat_jid, type:'cancel'})
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.join).toHaveBeenCalledWith('dummy-3'); expect(view.join).toHaveBeenCalledWith('dummy-3');
attrs.from = 'problematic@muc.localhost/dummy-3'; attrs.from = `${groupchat_jid}/dummy-3`;
attrs.id = new Date().getTime(); attrs.id = new Date().getTime();
presence = $pres().attrs(attrs) presence = $pres().attrs(attrs)
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() .c('x').attrs({'xmlns': 'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'problematic@muc.localhost', type:'cancel'}) .c('error').attrs({'by': groupchat_jid, 'type': 'cancel'})
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('conflict').attrs({'xmlns':'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.join).toHaveBeenCalledWith('dummy-4'); expect(view.join).toHaveBeenCalledWith('dummy-4');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the user is not allowed to have created the groupchat", it("will show an error message if the user is not allowed to have created the groupchat",
...@@ -3391,7 +3387,7 @@ ...@@ -3391,7 +3387,7 @@
await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy') await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy')
var presence = $pres().attrs({ var presence = $pres().attrs({
from: `${groupchat_jid}/dummy`, from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to:'dummy@localhost/pda',
type:'error' type:'error'
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
...@@ -3412,7 +3408,7 @@ ...@@ -3412,7 +3408,7 @@
const groupchat_jid = 'conformist@muc.localhost' const groupchat_jid = 'conformist@muc.localhost'
await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy'); await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ const presence = $pres().attrs({
from: `${groupchat_jid}/dummy`, from: `${groupchat_jid}/dummy`,
id: u.getUniqueId(), id: u.getUniqueId(),
to:'dummy@localhost/pda', to:'dummy@localhost/pda',
...@@ -3421,7 +3417,7 @@ ...@@ -3421,7 +3417,7 @@
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get(groupchat_jid); const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
......
...@@ -101,22 +101,17 @@ ...@@ -101,22 +101,17 @@
return utils.waitUntil(() => _converse.chatboxviews.get(jid), 1000); return utils.waitUntil(() => _converse.chatboxviews.get(jid), 1000);
}; };
utils.openChatRoomViaModal = function (_converse, jid, nick='') { utils.openChatRoomViaModal = async function (_converse, jid, nick='') {
// Opens a new chatroom // Opens a new chatroom
return new Promise(function (resolve, reject) {
utils.openControlBox(_converse); utils.openControlBox(_converse);
const roomspanel = _converse.chatboxviews.get('controlbox').roomspanel; const roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
roomspanel.el.querySelector('.show-add-muc-modal').click(); roomspanel.el.querySelector('.show-add-muc-modal').click();
utils.closeControlBox(_converse); utils.closeControlBox(_converse);
const modal = roomspanel.add_room_modal; const modal = roomspanel.add_room_modal;
utils.waitUntil(() => u.isVisible(modal.el), 1000) await utils.waitUntil(() => u.isVisible(modal.el), 1500)
.then(() => {
modal.el.querySelector('input[name="chatroom"]').value = jid; modal.el.querySelector('input[name="chatroom"]').value = jid;
modal.el.querySelector('input[name="nickname"]').value = nick; modal.el.querySelector('input[name="nickname"]').value = nick;
modal.el.querySelector('form input[type="submit"]').click(); modal.el.querySelector('form input[type="submit"]').click();
resolve();
});
}).catch(_.partial(console.error, _));
}; };
utils.openChatRoom = function (_converse, room, server, nick) { utils.openChatRoom = function (_converse, room, server, nick) {
......
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